# Name: AppendRoutes_Pro_Ex4.py
# Description: Append routes using a feature service in a stand-alone script. It is recommended to work in a version and post it into the default version.
# Requires: ArcGIS Location Referencing
# Import arcpy module.
import arcpy
# Check out any necessary licenses.
arcpy.CheckOutExtension("LocationReferencing")
# Set tool variables.
source_routes = r"C:\LocationReferencing\LR.gdb\LRS\routes"
route_id_field = "ROUTEID"
route_name_field = "ROUTENAME"
from_date_field = "FROMDATE"
to_date_field = "TODATE"
line_id_field = "LINEID"
line_name_field = "LINENAME"
line_order_field = "ORDERID"
field_mapping = r'CREATIONUSER "Creation User" true true false 50 Text 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,CREATIONUSER,0,50;DATECREATED "Date Created" true true false 8 Date 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,DATECREATED,-1,-1;DATEMODIFIED "Date Modified" true true false 8 Date 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,DATEMODIFIED,-1,-1;LASTUSER "Last User" true true false 50 Text 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,LASTUSER,0,50;EVENTSOURCE "Event Source" true true false 50 Text 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,EVENTSOURCE,0,50;LEGACYID "Legacy ID" true true false 38 Text 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,LEGACYID,0,38;ENGFROMM "ENGFROMM" true true false 0 Double 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,ENGFROMM,-1,-1;ENGTOM "ENGTOM" true true false 0 Double 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,ENGTOM,-1,-1;OBJECTSTATUS "Object Status" true true false 20 Text 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,OBJECTSTATUS,0,20;CONTINFROMM "Continuous from Measure" true true false 0 Double 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,CONTINFROMM,-1,-1;CONTINTOM "Continuous to Measure" true true false 0 Double 0 0,First,#,C:\LocationReferencing\LR.gdb\LRS\routes,CONTINTOM,-1,-1'
load_type = "REPLACE_BY_ROUTE_ID"
load_field = None
consider_existing_centerlines = "DO_NOT_CONSIDER"
## Target Route is in feature service. Signing in portal is required to access the feature service.
arcpy.SignInToPortal('https://yourdomain.com/portal', 'username', 'password')
## Map the target route network from the feature service.Here, 18 corresponds to the target route network.
in_lrs_network = r"https://yourdomain.com/server/rest/services/FeatureServiceName/FeatureServer/18"
# Run Append Routes
arcpy.locref.AppendRoutes(source_routes, in_lrs_network, route_id_field, route_name_field, from_date_field, to_date_field, line_id_field, line_name_field, line_order_field, field_mapping, load_type, load_field, consider_existing_centerlines)
# Check in licenses
arcpy.CheckInExtension('LocationReferencing')