Example #1
0
def RouteMaker():
    from arcpy import CreateRoutes_lr, Append_management
    CreateRoutes_lr(SSoutput + "Unsplit", "CountyKey1",
                    RouteOutput + "CountyRoute", "TWO_FIELDS", "MIN_F_CNTY_2",
                    "MAX_T_CNTY_2", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    CreateRoutes_lr(ClassOutput + "Unsplit", "CountyKey1",
                    "in_memory/RMCRoute", "TWO_FIELDS", "MIN_F_CNTY_2",
                    "MAX_T_CNTY_2", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    Append_management("RMCRoute", RouteOutput + "CountyRoute", "TEST", "", "")
Example #2
0
def calibrationCCL_Edit():

    print "deriving CCL LRS starting points and calibrations"
    CCLEnd = "!" + schema + "CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE! - !" + schema + "CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!"
    CCLBeg = "!" + schema + "CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE! - !" + schema + "CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!"
    MakeFeatureLayer_management(LineFeatureClass, "CITY_CONNECTING_LINK_RESET")
    resln = "CITY_CONNECTING_LINK_RESET"
    AddField_management(resln, "CCL_BEGIN", "DOUBLE", 12, 3)
    AddField_management(resln, "CCL_END", "DOUBLE", 12, 3)
    AddJoin_management("CITY_CONNECTING_LINK_RESET", "CCL_LRS",
                       connection1 + "CITY_CONNECTING_LINK_STATE_D", "CCL_LRS",
                       "KEEP_ALL")
    CalculateField_management(resln, "CCL_BEGIN", CCLBeg, "PYTHON")
    CalculateField_management(resln, "CCL_END", CCLEnd, "PYTHON")
    print "calibrating LRS - point calibration method"
    #statecalpoints = stateroutelyr+"_Point"
    #print statecalpoints
    #MakeFeatureLayer_management(statecalpoints, "smlrs_pt")
    #print connection1+"CITY_CONNECTING_LINK_STATE_D"
    #MakeFeatureLayer_management(connection1+"CITY_CONNECTING_LINK_STATE_D", "dissolved_res_sects")
    #intersects = ["dissolved_res_sects", "smlrs_pt"]
    #Intersect_analysis(intersects,connection0+"\CALIBRATION_POINTS_CCL","ALL","#","POINT")
    #print connection1+"CALIBRATION_POINTS_CCL"
    #MakeFeatureLayer_management(connection1+"CALIBRATION_POINTS_CCL", "Calibrators")
    #querystr = "Substring( CCL_LRS,4, 12)<> LRS_ROUTE"
    #SelectLayerByAttribute_management("Calibrators","NEW_SELECTION",querystr)
    #DeleteRows_management("Calibrators")
    MakeFeatureLayer_management(connection1 + "CITY_CONNECTING_LINK_STATE",
                                "CCL_sections")
    #DeleteIdentical_management("Calibrators","LRS_KEY;POINT_X;POINT_Y;POINT_M","#","0")
    AddField_management("CCL_sections", "CCL_BEGIN", "DOUBLE", "#", "#", "#",
                        "#", "NULLABLE", "NON_REQUIRED", "#")
    AddField_management("CCL_sections", "CCL_END", "DOUBLE", "#", "#", "#",
                        "#", "NULLABLE", "NON_REQUIRED", "#")
    AddJoin_management("CCL_sections", "CCL_LRS", "dissolved_res_sects",
                       "CCL_LRS", "KEEP_ALL")
    CalculateField_management(
        "CCL_sections", schema + "CITY_CONNECTING_LINK_STATE.CCL_BEGIN", "!" +
        schema + "CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE! - !" +
        schema + "CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!",
        "PYTHON", "#")
    CalculateField_management(
        "CCL_sections", schema + "CITY_CONNECTING_LINK_STATE.CCL_END", "!" +
        schema + "CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE! - !" +
        schema + "CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!",
        "PYTHON", "#")
    #AddField_management(connection1+"CALIBRATION_POINTS_CCL","CCL_MEASURE", "DOUBLE", 12, 3)
    #CalculateField_management("Calibrators","CCL_MEASURE","!POINT_M! - !MIN_BEG_STATE_LOGMILE!","PYTHON","#")
    CreateRoutes_lr(LineFeatureClass, NewRouteKey,
                    connection1 + NewRoute + "base", "TWO_FIELDS", NewBeg,
                    NewEnd, "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    CalibrateRoutes_lr(connection1 + "CCL_LRS_ROUTEbase", "CCL_LRS",
                       r"D:\workspaces\pythontests.gdb\CCL_Point_Calibrators",
                       "point_LRS", "point_Loc", connection1 + "CCL_LRS_ROUTE",
                       "MEASURES", "10 Feet", "BETWEEN", "NO_BEFORE",
                       "NO_AFTER", "NO_IGNORE", "KEEP", "INDEX")
    AddField_management(connection1 + NewRoute, "NETWORKDATE", "DATE")
    CalculateField_management(connection1 + NewRoute, "NETWORKDATE",
                              "datetime.datetime.now( )", "PYTHON_9.3", "#")
    MakeFeatureLayer_management(connection1 + "CCL_LRS_ROUTE", NewRoute)
Example #3
0
def CreateNonStateRoutes():
    FeatureClassToFeatureClass_conversion(in_features="Database Connections/SDEPROD_SHARED.sde/SHARED.NON_STATE_SYSTEM", out_path="C:/temp/Nusys_Check.gdb", out_name="Non_State_System", where_clause="", field_mapping="#", config_keyword="")
    NonState = r"C:/temp/Nusys_Check.gdb/Non_State_System"
    MakeFeatureLayer_management(NonState, "NonState", "MILEAGE_COUNTED = -1 AND SURFACE NOT LIKE 'Propose'")
    MakeFeatureLayer_management(NonState, "BackwardSegs", "LRS_BACKWARDS = -1")
    FlipLine_edit("BackwardSegs") 
    CreateRoutes_lr("NonState", "LRS_KEY", destdb+"\Route", "TWO_FIELDS", "LRS_BEG_CNTY_LOGMILE", "LRS_BEG_CNTY_LOGMILE", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    #Flip them back to the original direction
    FlipLine_edit(in_features="BackwardSegs") 
Example #4
0
def CheckRouteShapeLength():
    print "creating Non_State_Routes by the Shape Length"
    MakeFeatureLayer_management("C:/temp/Nusys_Check.gdb/Non_State_Classified", "BackwardSegs", "LRS_BACKWARDS = -1 AND MILEAGE_COUNTED = -1")
    FlipLine_edit("BackwardSegs") 
    Dissolve_management("Non_State_Classified", "C:/TEMP/Nusys_Check.gdb/TotalRouteShapeLength", "LRS_KEY", "", "MULTI_PART", "DISSOLVE_LINES")
    AddField_management("TotalRouteShapeLength", "Mileage", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("TotalRouteShapeLength", "Mileage", "Round([LINEARGEOMETRY_Length] /5280, 3)", "VB", "")
    AddField_management("TotalRouteShapeLength", "Zero", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("TotalRouteShapeLength", "Zero", "0", "VB", "")

    #MakeFeatureLayer_management(in_features="C:/temp/Nusys_Check.gdb/TotalRouteShapeLength", out_layer="ForwardRoutes", where_clause="LRS_BACKWARDS = 0")

    CreateRoutes_lr("TotalRouteShapeLength", "LRS_KEY", destdb+"\ShapeLengthRoute", "TWO_FIELDS", "Zero", "Mileage", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    #Flip them back to the original direction
    FlipLine_edit(in_features="BackwardSegs") 
    LocateFeaturesAlongRoutes_lr("Non_State_Classified", "ShapeLengthRoute", "LRS_KEY", "0 Feet", "C:/temp/Nusys_Check.gdb/NON_STATE_EVENTS", "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
    AddField_management("NON_STATE_EVENTS", "CheckBegin", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("NON_STATE_EVENTS", "CheckEnd", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    
    CalculateField_management("NON_STATE_EVENTS", "CheckBegin", "abs(!LRS_BEG_CNTY_LOGMILE!- !FMEAS!)", "PYTHON_9.3", "")
    CalculateField_management("NON_STATE_EVENTS", "CheckEnd", "abs(!LRS_END_CNTY_LOGMILE!- !TMEAS!)", "PYTHON_9.3", "")
   
    MakeRouteEventLayer_lr("ShapeLengthRoute", "LRS_KEY", "NON_STATE_EVENTS", "rid LINE fmeas tmeas", "LRS_Review_Events", "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
Example #5
0
def CheckCRouteShapeLength():
    print "CreateNUSYSLocal() is a prerequisite function to this one "
    print "creating Non_State_Routes by the Shape Length"
    MakeFeatureLayer_management("C:/temp/Nusys_Check.gdb/Non_State_Classified", "BackwardSegs", "LRS_BACKWARDS = -1 AND (MILEAGE_COUNTED = -1 OR SURFACE = 'Propose')")
    FlipLine_edit("BackwardSegs") 
    Dissolve_management("Non_State_Classified", "C:/TEMP/Nusys_Check.gdb/TotalRouteShapeLength", "LRS_KEY", "", "MULTI_PART", "DISSOLVE_LINES")
    AddField_management("TotalRouteShapeLength", "Mileage", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("TotalRouteShapeLength", "Mileage", "Round([Lineargeometry_Length] /5280, 3)", "VB", "")
    AddField_management("TotalRouteShapeLength", "Zero", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("TotalRouteShapeLength", "Zero", "0", "VB", "")

    #MakeFeatureLayer_management(in_features="C:/temp/Nusys_Check.gdb/TotalRouteShapeLength", out_layer="ForwardRoutes", where_clause="LRS_BACKWARDS = 0")

    CreateRoutes_lr("TotalRouteShapeLength", "LRS_KEY", destdb+"\C_ShapeLengthRoute", "TWO_FIELDS", "Zero", "Mileage", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    #Flip them back to the original direction
    FlipLine_edit(in_features="BackwardSegs") 
    LocateFeaturesAlongRoutes_lr("Non_State_Classified", "ShapeLengthRoute", "LRS_KEY", "0 Feet", "C:/temp/Nusys_Check.gdb/C_NON_STATE_EVENTS", "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
    AddField_management("C_NON_STATE_EVENTS", "AdjBegin", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("C_NON_STATE_EVENTS", "AdjEnd", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("C_NON_STATE_EVENTS", "CHG_BEGLOG","DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("C_NON_STATE_EVENTS", "CHG_ENDLOG","DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("C_NON_STATE_EVENTS", "NEW_BEGLOG","DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("C_NON_STATE_EVENTS", "NEW_ENDLOG","DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("C_NON_STATE_EVENTS", "AdjLength","DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("C_NON_STATE_EVENTS", "CHANGE","DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    
    CalculateField_management(in_table="C_NON_STATE_EVENTS", field="AdjBegin", expression="round( !FMEAS! , 3 )", expression_type="PYTHON_9.3", code_block="")
    CalculateField_management(in_table="C_NON_STATE_EVENTS", field="AdjEnd", expression="round( !TMEAS! , 3 )", expression_type="PYTHON_9.3", code_block="")
    CalculateField_management(in_table="C_NON_STATE_EVENTS", field="CHG_BEGLOG", expression="[AdjBegin] - [LRS_BEG_CNTY_LOGMILE]", expression_type="VB", code_block="")
    CalculateField_management(in_table="C_NON_STATE_EVENTS", field="CHG_ENDLOG", expression="[AdjEnd] - [LRS_END_CNTY_LOGMILE]", expression_type="VB", code_block="")
    CalculateField_management(in_table="C_NON_STATE_EVENTS", field="NEW_BEGLOG", expression="[AdjBegin]", expression_type="VB", code_block="")
    CalculateField_management(in_table="C_NON_STATE_EVENTS", field="NEW_ENDLOG", expression="[AdjEnd]", expression_type="VB", code_block="")
    CalculateField_management(in_table="C_NON_STATE_EVENTS", field="AdjLength", expression="[AdjEnd] - [AdjBegin]", expression_type="VB", code_block="")
    CalculateField_management(in_table="C_NON_STATE_EVENTS", field="CHANGE", expression="abs([LENGTH] - [AdjLength])", expression_type="VB", code_block="")
       
    MakeRouteEventLayer_lr("C_ShapeLengthRoute", "LRS_KEY", "C_NON_STATE_EVENTS", "rid LINE fmeas tmeas", "C_LRS_Review_Events", "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
Example #6
0
MakeTableView_management(connection1 + "CP_MEAS", "CalibrationEvents",
                         querystr, "#")
delfields = NewRouteKey + ";MEASURE"
DeleteIdentical_management("CalibrationEvents", delfields)
inprops = str(ReferenceRouteKey + " POINT MEASURE")
MakeRouteEventLayer_lr(ReferenceRoute, ReferenceRouteKey, "CalibrationEvents",
                       inprops, "Calibration_Event_lyr", "#", "ERROR_FIELD",
                       "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
FeatureClassToFeatureClass_conversion("Calibration_Event_lyr", connection0,
                                      "Calibration_Points" + NewRoute, "#",
                                      "#")
MakeFeatureLayer_management(connection1 + "Calibration_Points" + NewRoute,
                            NewRoute + "CalibrationPointsLyr")

CreateRoutes_lr(LineFeatureClass, NewRouteKey, connection1 + NewRoute + "base",
                "TWO_FIELDS", NewBeg, NewEnd, "UPPER_LEFT", "1", "0", "IGNORE",
                "INDEX")
AddField_management(connection1 + "Calibration_Points" + NewRoute,
                    "CCL_MEASURE", "DOUBLE", 12, 3)
calxpr = '[CCL.DBO.Calibration_PointsCCL_LRS_ROUTE.MEASURE]-[CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE]'
AddJoin_management(NewRoute + "CalibrationPointsLyr", "CCL_LRS",
                   connection1 + "CITY_CONNECTING_LINK_STATE_D", "CCL_LRS",
                   "KEEP_ALL")
CalculateField_management(NewRoute + "CalibrationPointsLyr", "CCL_MEASURE",
                          calxpr, "VB", "#")

CalibrateRoutes_lr(connection1 + NewRoute + "base", NewRouteKey,
                   connection1 + "Calibration_Points" + NewRoute, NewRouteKey,
                   "CCL_MEASURE", connection1 + NewRoute, "MEASURES", "5 feet",
                   "BETWEEN", "BEFORE", "AFTER", "IGNORE", "KEEP", "INDEX")
AddField_management(connection1 + NewRoute, "NETWORKDATE", "DATE")
def routeCreation():
    env.workspace = returnGDBOrSDEPath(createRoutesOutputFC)
    env.overwriteOutput = 1
    '''
    # Need to match what Transcend used. -- Done.
    routeId = 'SourceRouteId'
    measureSource = 'TWO_FIELDS'
    fMeasureField = 'SourceFromMeasure'
    tMeasureField = 'SourceToMeasure'
    coordinatePriority = 'UPPER_LEFT'
    measureFactor = 1
    measureOffset = 0
    ignoreGaps = True
    buildIndex = True
    '''
    # Modifications for County Target Network.
    routeId = 'TargetCountyLRSKey'
    measureSource = 'Shapelength'
    #fMeasureField = 'SourceFromMeasure'
    #tMeasureField = 'SourceToMeasure'
    coordinatePriority = 'LOWER_LEFT'
    measureFactor = 1
    measureOffset = 0
    ignoreGaps = True
    buildIndex = True

    routesOutputGDB = returnGDBOrSDEPath(createRoutesOutputFC)
    routesOutputGDBName = returnGDBOrSDEName(routesOutputGDB)
    # Need to implement a new path function to get the GDB's folder.
    routesOutputGDBFolder = mainFolder
    if Exists(routesOutputGDB):
        Delete_management(routesOutputGDB)
    else:
        pass
    CreateFileGDB_management(routesOutputGDBFolder, routesOutputGDBName)

    # Checking to see if the copy for routes output exists.
    # If so, remove it.
    #if Exists(createRoutesOutputFC):
    #    Delete_management(createRoutesOutputFC)
    #else:
    #    pass

    print("Creating the lrs routes.")
    # CreateRoutes_lr GP Tool
    CreateRoutes_lr(createRoutesInputFC, routeId, createRoutesOutputFC,
                    measureSource, fMeasureField, tMeasureField,
                    coordinatePriority, measureFactor, measureOffset,
                    ignoreGaps, buildIndex)

    print("Adding date fields to " + returnFeatureClass(createRoutesOutputFC) +
          ".")
    #Addfields:
    AddField_management(createRoutesOutputFC, "F_Date", "DATE", "", "", "",
                        "F_Date", nullable)
    pyDateExpression = '''def pyFindTheDate():
        import time
        return time.strftime("%Y/%m/%d")'''

    CalculateField_management(createRoutesOutputFC, "F_Date",
                              "pyFindTheDate()", "PYTHON_9.3",
                              pyDateExpression)
    # T_Date (Date)
    AddField_management(createRoutesOutputFC, "T_Date", "DATE", "", "", "",
                        "T_Date", nullable)

    # ---- Add route calibration point creation steps for Start & End points. ----
    MakeFeatureLayer_management(createRoutesInputFC, 'tempFeatureLayer')

    # Checking to see if the output already exists.
    # If so, remove it so that it can be recreated.
    if Exists(startCalibrationPoints):
        Delete_management(startCalibrationPoints)
    else:
        pass
    if Exists(endCalibrationPoints):
        Delete_management(endCalibrationPoints)
    else:
        pass

    # Create 2 fieldInfo objects. Turn off all the fields in each one.
    featureDesc = Describe('tempFeatureLayer')
    if featureDesc.dataType == "FeatureLayer":
        fieldInfo_For_Start_CP_Fields = featureDesc.fieldInfo
        fieldInfo_For_End_CP_Fields = featureDesc.fieldInfo
        # Use the count property to iterate through all the fields
        for index in range(0, fieldInfo_For_Start_CP_Fields.count):
            fieldInfo_For_Start_CP_Fields.setVisible(index, 'HIDDEN')
            fieldInfo_For_End_CP_Fields.setVisible(index, 'HIDDEN')

    # Turn on the needed fields.
    visibile_Fields_For_Start_CP_Layer = [routeId, 'SourceFromMeasure']
    for visibile_Field in visibile_Fields_For_Start_CP_Layer:
        tempIndex = fieldInfo_For_Start_CP_Fields.findFieldByName(
            visibile_Field)
        fieldInfo_For_Start_CP_Fields.setVisible(tempIndex, 'VISIBLE')
    # Create a feature layer that only shows the needed fields.
    MakeFeatureLayer_management(createRoutesInputFC,
                                featureLayerCL_For_Start_CP, "", "",
                                fieldInfo_For_Start_CP_Fields)
    # Use that feature layer to create the 1st calibration point set.
    FeatureVerticesToPoints_management(featureLayerCL_For_Start_CP,
                                       startCalibrationPoints, "START")

    # Turn on the needed fields.
    visibile_Fields_For_End_CP_Layer = [routeId, 'SourceToMeasure']
    for visibile_Field in visibile_Fields_For_End_CP_Layer:
        tempIndex = fieldInfo_For_End_CP_Fields.findFieldByName(visibile_Field)
        fieldInfo_For_End_CP_Fields.setVisible(tempIndex, 'VISIBLE')
    # Create a feature layer that only shows the needed fields.
    MakeFeatureLayer_management(createRoutesInputFC, featureLayerCL_For_End_CP,
                                "", "", fieldInfo_For_End_CP_Fields)
    # Use that feature layer to create the 2nd calibration point set.
    FeatureVerticesToPoints_management(featureLayerCL_For_End_CP,
                                       endCalibrationPoints, "END")

    # ---- Merge the Start & End calibration points. ----
    # Checking to see if the output already exists.
    # If so, remove it so that it can be recreated.
    if Exists(mergedCalibrationPoints):
        Delete_management(mergedCalibrationPoints)
    else:
        pass
    # RoutesSource_Start_CP.SourceRouteId to CalPts_Merge.RouteId
    # RoutesSource_End_CP.SourceRouteId to CalPts_Merge.RouteId
    mcp_Field1 = FieldMap()
    mcp_Field1.addInputField(startCalibrationPoints, routeId)
    mcp_Field1.addInputField(endCalibrationPoints, routeId)
    mcp_Field1_OutField = mcp_Field1.outputField
    mcp_Field1_OutField.name = 'RouteId'
    mcp_Field1_OutField.aliasName = 'RouteId'
    mcp_Field1_OutField.type = 'String'
    mcp_Field1_OutField.length = 50
    mcp_Field1.outputField = mcp_Field1_OutField

    # RoutesSource_Start_CP.SourceFromMeasure to CalPts_Merge.Measure
    mcp_Field2 = FieldMap()
    mcp_Field2.addInputField(startCalibrationPoints, 'SourceFromMeasure')
    mcp_Field2.addInputField(endCalibrationPoints, 'SourceToMeasure')
    mcp_Field2_OutField = mcp_Field2.outputField
    mcp_Field2_OutField.name = 'Measure'
    mcp_Field2_OutField.aliasName = 'Measure'
    mcp_Field2_OutField.type = 'Double'
    mcp_Field2.outputField = mcp_Field2_OutField

    # Create a fieldMappings object for the layer merge.
    calibrationPointsMappings = FieldMappings()
    calibrationPointsMappings.addFieldMap(mcp_Field1)
    calibrationPointsMappings.addFieldMap(mcp_Field2)

    #Merge the points together into a single feature class.
    inputMergeLayers = [startCalibrationPoints, endCalibrationPoints]
    Merge_management(inputMergeLayers, mergedCalibrationPoints,
                     calibrationPointsMappings)

    MakeFeatureLayer_management(mergedCalibrationPoints, 'tempMergedPoints')

    dissolveFields = ["RouteId", "Measure"]
    print('Dissolving points.')
    Dissolve_management('tempMergedPoints', dissolvedCalibrationPoints,
                        dissolveFields, "#", "SINGLE_PART")
routelyr = ws+"\\"+tempgdb+"\\"+route
inlyr2 = ws+"\\"+tempgdb+"/STATE_SYSTEM"

inlyr1 = ws+"\\"+tempgdb+"/Calibration_Points"
'''





LocateFeaturesAlongRoutes_lr(ws+"\\"+tempgdb+"/Calibration_Points",ws+"\\"+tempgdb+"/SRND","NE_UNIQUE","0.001 Feet",ws+"\\"+tempgdb+"/CP_SRND","STATE_MILE POINT SR_MEAS","ALL","DISTANCE","ZERO","FIELDS","M_DIRECTON")
MakeTableView_management(ws+"\\"+tempgdb+"/CP_SRND","Calibration_SR",'"STATE_MILE" = "SRND"', ws+"\\"+tempgdb,"#")
MakeRouteEventLayer_lr(routelyr,"NE_UNIQUE","Calibration_SR","STATE_MILE POINT SR_MEAS","SR_Calibration_Events","#","ERROR_FIELD","NO_ANGLE_FIELD","NORMAL","ANGLE","LEFT","POINT")
FeatureClassToFeatureClass_conversion("SR_Calibration_Events",ws+"\\"+tempgdb,"Calibration_Points_SRND","#","#")
DeleteIdentical_management(ws+"\\"+tempgdb+"/Calibration_Points_SRND","STATE_MILE;SR_MEAS","0.002 Miles","0")
CreateRoutes_lr(ws+"\\"+tempgdb+"/State_System","LRS_ROUTE",ws+"\\"+tempgdb+"/StateSystem_State_Route_SRND","TWO_FIELDS","BEG_STATE_LOGMILE","END_STATE_LOGMILE","UPPER_LEFT","1","0","IGNORE","INDEX")
CalibrateRoutes_lr(ws+"\\"+tempgdb+"/StateSystem_State_Route_"+route,"LRS_ROUTE",ws+"\\"+tempgdb+"/Calibration_Points_SRND","LRS_ROUTE","SR_MEAS",ws+"\\"+tempgdb+"/SMLRS","MEASURES","5 feet","BETWEEN","BEFORE","AFTER","IGNORE","KEEP","INDEX")
AddField_management(ws+"\\"+tempgdb+"/SMLRS", "NETWORKDATE", "DATE")
CalculateField_management(ws+"\\"+tempgdb+"/SMLRS","NETWORKDATE","datetime.datetime.now( )","PYTHON_9.3","#")

route = "CRND"
routelyr = ws+"\\"+tempgdb+"\\"+route
LocateFeaturesAlongRoutes_lr(ws+"\\"+tempgdb+"/Calibration_Points",ws+"\\"+tempgdb+"/CRND","NE_UNIQUE","0.001 Feet",ws+"\\"+tempgdb+"/CP_CRND","STATE_MILE POINT CR_MEAS","ALL","DISTANCE","ZERO","FIELDS","M_DIRECTON")
MakeTableView_management(ws+"\\"+tempgdb+"/CP_CRND","Calibration_CR",'"STATE_MILE" = "CRND"', ws+"\\"+tempgdb,"#")
MakeRouteEventLayer_lr(routelyr,"NE_UNIQUE","Calibration_CR","STATE_MILE POINT CR_MEAS","CR_Calibration_Events","#","ERROR_FIELD","NO_ANGLE_FIELD","NORMAL","ANGLE","LEFT","POINT")
FeatureClassToFeatureClass_conversion("CR_Calibration_Events",ws+"\\"+tempgdb,"Calibration_Points_CRND","#","#")
DeleteIdentical_management(ws+"\\"+tempgdb+"/Calibration_Points_CRND","STATE_MILE;CR_MEAS","0.002 Miles","0")
CreateRoutes_lr(ws+"\\"+tempgdb+"/State_System","LRS_KEY",ws+"\\"+tempgdb+"/StateSystem_County_Route_CRND","TWO_FIELDS","BEG_CNTY_LOGMILE","END_CNTY_LOGMILE","UPPER_LEFT","1","0","IGNORE","INDEX")
CalibrateRoutes_lr(ws+"\\"+tempgdb+"/StateSystem_County_Route_"+route,"LRS_KEY",ws+"\\"+tempgdb+"/Calibration_Points_CRND","LRS_KEY","CR_MEAS",ws+"\\"+tempgdb+"/CMLRS","MEASURES","5 feet","BETWEEN","BEFORE","AFTER","IGNORE","KEEP","INDEX")
AddField_management(ws+"\\"+tempgdb+"/CMLRS", "NETWORKDATE", "DATE")
CalculateField_management(ws+"\\"+tempgdb+"/CMLRS","NETWORKDATE","datetime.datetime.now( )","PYTHON_9.3","#")
Example #9
0
                                      "STATE_SYSTEM", "LOC_ERROR = 'NO ERROR'")

#copy state systen to GISTEST
FeatureClassToFeatureClass_conversion("MapExtractSRNDEvents",
                                      "Database Connections/GISTEST.sde",
                                      "STATE_SYSTEM", "#", "#", "SDO_GEOMETRY")

#Save the Primary Route Skeleton Layer

#Create the vertices for calibration points
FeatureVerticesToPoints_management(STAGEDB + "/GIS_STATE_SYSTEM",
                                   STAGEDB + "/Calibration_Points", "ALL")
DeleteIdentical_management("GIS_CANSYS.DBO.Calibration_Points",
                           "LRS_KEY;POINT_X;POINT_Y;POINT_M", "#", "0")
CreateRoutes_lr(STAGEDB + "/GIS_STATE_SYSTEM", "LRS_ROUTE",
                STAGEDB + "/GIS_STATE_ROUTES", "TWO_FIELDS",
                "BEG_STATE_LOGMILE", "END_STATE_LOGMILE", "UPPER_LEFT", "1",
                "0", "IGNORE", "INDEX")
CalibrateRoutes_lr(STAGEDB + "/GIS_STATE_ROUTES", "LRS_ROUTE",
                   STAGEDB + "/Calibration_Points", "LRS_ROUTE", "POINT_M",
                   STAGEDB + "/SMLRS", "MEASURES", "5 feet", "BETWEEN",
                   "BEFORE", "AFTER", "IGNORE", "KEEP", "INDEX")

#Rider Routes
CreateRoutes_lr(STAGEDB + "/GIS_STATE_SYSTEM", "SRND_KEY",
                STAGEDB + "/SRND_PRIMARY_ROUTE", "TWO_FIELDS",
                "BEG_STATE_LOGMILE", "END_STATE_LOGMILE", "UPPER_LEFT", "1",
                "0", "IGNORE", "INDEX")
LocateFeaturesAlongRoutes(
    "SRND_PRIMARY", "GIS_CANSYS.DBO.SRND_PRIMARY_ROUTE", "SRND_KEY",
    "0 DecimalDegrees",
    r"Database Connections\SQL61_GIS_CANSYS.sde\GIS_CANSYS.DBO.SRND_RIDER_ROUTES",
Example #10
0
def CRB():
    print "querying the shared.NON_STATE_SYSTEM to obtain only urban classified primary C routes with mileage that should be counted and for resolution segments."
    MakeFeatureLayer_management(
        NonState, "NonStateCP",
        "((LRS_KEY LIKE '%C%' OR LRS_ROUTE_PREFIX = 'C') AND (MILEAGE_COUNTED = -1)) OR (LRS_DIR_OF_TRAVEL = 'P' and SURFACE = 'Propose')"
    )

    print "querying the shared.NON_STATE_SYSTEM to obtain only urban classified NonPrimary C routes with mileage that should be counted and for resolution segments."
    MakeFeatureLayer_management(
        NonState, "NonStateCNP",
        "(LRS_KEY LIKE '%C%' OR LRS_ROUTE_PREFIX = 'C') AND (MILEAGE_COUNTED = 0) AND (LRS_DIR_OF_TRAVEL = 'S') and (COUNTY_NUMBER <> 0)"
    )

    print "shared.Non_State_System has unique IDS that we desire to keep as persistent IDs for comparison with GeoMedia, so we are spatially intersecting the state boundary to keep them as is."
    Buffer_analysis(StateBnd, "State_Boundary_1Mile", "5280 Feet", "FULL",
                    "ROUND", "NONE", "", "PLANAR")
    MakeFeatureLayer_management("State_Boundary_1Mile", "StateBnd")
    Intersect_analysis("NonStateCP #;StateBnd #",
                       "Non_State_Classified_Primary", "ALL", "-1 Unknown",
                       "LINE")
    Intersect_analysis("NonStateCNP #;StateBnd #",
                       "Non_State_Classified_NonPrimary", "ALL", "-1 Unknown",
                       "LINE")

    NonStateCP_fx = r'Non_State_Classified_Primary'
    NonStateCNP_fx = r'Non_State_Classified_NonPrimary'

    MakeFeatureLayer_management(NonStateCP_fx, "Non_State_Classified_Primary")
    MakeFeatureLayer_management(NonStateCNP_fx,
                                "Non_State_Classified_NonPrimary")

    CP_ET = 'CP_NON_STATE_EVENTS'
    CNP_ET = 'CNP_NON_STATE_EVENTS'

    MakeFeatureLayer_management(NUSYS, "Nusys_Extract",
                                "NSEC_SUB_CLASS <> 'R'")

    print "creating primary C Non_State_Routes by the Shape Length"
    MakeFeatureLayer_management(
        "Non_State_Classified_Primary", "BackwardSegsCP",
        "LRS_BACKWARDS = -1 AND (MILEAGE_COUNTED = -1 OR (LRS_DIR_OF_TRAVEL = 'P' and SURFACE = 'Propose'))"
    )
    FlipLine_edit("BackwardSegsCP")
    Dissolve_management("Non_State_Classified_Primary", "CPRouteShapeLength",
                        "NQR_DESCRIPTION", "", "MULTI_PART", "DISSOLVE_LINES")
    AddField_management("CPRouteShapeLength", "BCM", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("CPRouteShapeLength", "BCM", "0", "VB", "")
    AddField_management("CPRouteShapeLength", "ECM", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("CPRouteShapeLength", "ECM",
                              "!Shape.length@miles!", "Python")

    CreateRoutes_lr("CPRouteShapeLength", "NQR_DESCRIPTION",
                    destdb + "\CP_ShapeLengthRoute", "TWO_FIELDS", "BCM",
                    "ECM", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    #Flip them back to the original direction
    FlipLine_edit(in_features="BackwardSegsCP")
    LocateFeaturesAlongRoutes_lr("Non_State_Classified_Primary",
                                 "CP_ShapeLengthRoute", "NQR_DESCRIPTION",
                                 "0 Feet", "CP_NON_STATE_EVENTS",
                                 "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")
    AddField_management("CP_NON_STATE_EVENTS", "AdjBegin", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "AdjEnd", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "CHG_BEGLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "CHG_ENDLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "NEW_BEGLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "NEW_ENDLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "AdjLength", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "CHANGE", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")

    CalculateField_management("CP_NON_STATE_EVENTS",
                              "AdjBegin",
                              "round( [FMEAS] , 3 )",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "AdjEnd",
                              "round( [TMEAS] , 3 )",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "CHG_BEGLOG",
                              "[AdjBegin] - [LRS_BEG_CNTY_LOGMILE]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "CHG_ENDLOG",
                              "[AdjEnd] - [LRS_END_CNTY_LOGMILE]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "NEW_BEGLOG",
                              "[AdjBegin]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "NEW_ENDLOG",
                              "[AdjEnd]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "AdjLength",
                              "[AdjEnd] - [AdjBegin]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "CHANGE",
                              "abs([LENGTH] - [AdjLength])",
                              "VB",
                              code_block="")

    MakeRouteEventLayer_lr("CP_ShapeLengthRoute", "NQR_DESCRIPTION",
                           "CP_NON_STATE_EVENTS", "RID LINE FMEAS TMEAS",
                           "CP_LRS_Review_Events", "", "ERROR_FIELD",
                           "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                           "POINT")
    print "CP-Rte Builder script completed successfully"

    print "creating NonPrimary C Non_State_Routes by the Shape Length"
    MakeFeatureLayer_management(
        "Non_State_Classified_NonPrimary", "BackwardSegsCNP",
        "LRS_BACKWARDS = -1 AND LRS_DIR_OF_TRAVEL = 'S' and COUNTY_NUMBER <> 0"
    )
    FlipLine_edit("BackwardSegsCNP")
    Dissolve_management("Non_State_Classified_NonPrimary",
                        "CNPRouteShapeLength", "LRS_KEY", "", "MULTI_PART",
                        "DISSOLVE_LINES")
    AddField_management("CNPRouteShapeLength", "BCM", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("CNPRouteShapeLength", "BCM", "0", "VB", "")
    AddField_management("CNPRouteShapeLength", "ECM", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("CNPRouteShapeLength", "ECM",
                              "!Shape.length@miles!", "Python")

    CreateRoutes_lr("CNPRouteShapeLength", "LRS_KEY",
                    destdb + "\CNP_ShapeLengthRoute", "TWO_FIELDS", "BCM",
                    "ECM", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    #Flip them back to the original direction
    FlipLine_edit(in_features="BackwardSegsCNP")
    LocateFeaturesAlongRoutes_lr("Non_State_Classified_NonPrimary",
                                 "CNP_ShapeLengthRoute", "LRS_KEY", "0 Feet",
                                 "CNP_NON_STATE_EVENTS",
                                 "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")
    AddField_management("CNP_NON_STATE_EVENTS", "AdjBegin", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "AdjEnd", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "CHG_BEGLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "CHG_ENDLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "NEW_BEGLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "NEW_ENDLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "AdjLength", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "CHANGE", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")

    CalculateField_management("CNP_NON_STATE_EVENTS", "AdjBegin",
                              "round( [FMEAS] , 3 )", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "AdjEnd",
                              "round( [TMEAS] , 3 )", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "CHG_BEGLOG",
                              "[AdjBegin] - [LRS_BEG_CNTY_LOGMILE]", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "CHG_ENDLOG",
                              "[AdjEnd] - [LRS_END_CNTY_LOGMILE]", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "NEW_BEGLOG",
                              "[AdjBegin]", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "NEW_ENDLOG", "[AdjEnd]",
                              "VB", "")

    CalculateField_management("CNP_NON_STATE_EVENTS",
                              "AdjLength",
                              "[AdjEnd] - [AdjBegin]",
                              "VB",
                              code_block="")
    CalculateField_management("CNP_NON_STATE_EVENTS",
                              "CHANGE",
                              "abs([LENGTH] - [AdjLength])",
                              "VB",
                              code_block="")

    MakeRouteEventLayer_lr("CNP_ShapeLengthRoute", "LRS_KEY",
                           "CNP_NON_STATE_EVENTS", "RID LINE FMEAS TMEAS",
                           "CNP_LRS_Review_Events", "", "ERROR_FIELD",
                           "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                           "POINT")
    AddField_management("CNPRouteShapeLength", "PersistentID", "LONG", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNPRouteShapeLength", "Pbeg", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNPRouteShapeLength", "Pend", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")

    CalculateField_management("CNPRouteShapeLength", "PersistentID", "!ID2!",
                              "PYTHON_9.3", "")
    TableToTable_conversion("CNPRouteShapeLength", "in_memory", "CNP_Events",
                            "")

    endpoints = ["beg", "end"]
    for pos in endpoints:
        out_event = "CNP_Events_" + pos
        print out_event
        out_lyr = "CNP_Events_Features_" + pos
        print out_lyr

        outfield = "P" + pos
        print outfield
        if pos == "beg":
            print "Will locate begin point"
            routesettings = "LRS_KEY POINT BCM"
        else:
            print "locating end point"
            routesettings = "LRS_KEY POINT ECM"
        MakeRouteEventLayer_lr("CNP_ShapeLengthRoute", "LRS_KEY", "CNP_Events",
                               routesettings, out_event, "", "ERROR_FIELD",
                               "ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                               "POINT")
        LocateFeaturesAlongRoutes_lr(out_event, "CP_ShapeLengthRoute",
                                     "NQR_DESCRIPTION", "500 Feet", out_lyr,
                                     "RID POINT MEAS", "ALL", "DISTANCE",
                                     "ZERO", "FIELDS", "M_DIRECTON")
        AddJoin_management(out_lyr, "PersistentID", "CNPRouteShapeLength",
                           "PersistentID", "KEEP_ALL")
        selexp = out_lyr + ".RID <> CNPRouteShapeLength.LRS_KEY"
        print selexp
        SelectLayerByAttribute_management(out_lyr, "NEW_SELECTION", selexp)
        DeleteRows_management(out_lyr)
        RemoveJoin_management(out_lyr)
        AddJoin_management("CNPRouteShapeLength", "PersistentID", out_lyr,
                           "PersistentID", "KEEP_ALL")
        #expression = "[CNP_Events_Features_Begin.MEAS]"
        expression = "[" + out_lyr + ".MEAS]"
        print expression
        calcfield = "CNPRouteShapeLength." + outfield
        #CNPRouteShapeLength.Pbeg
        CalculateField_management("CNPRouteShapeLength", calcfield, expression,
                                  "VB", "")
        RemoveJoin_management("CNPRouteShapeLength", "")

    #test flipped routes and calculate mileage and flip flag
    AddField_management("CNPRouteShapeLength", "FlipTest", "LONG", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNPRouteShapeLength", "Adj_Beg", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNPRouteShapeLength", "Adj_End", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    SelectLayerByAttribute_management("CNPRouteShapeLength", "NEW_SELECTION",
                                      '"Pbeg" > "Pend"')
    CalculateField_management("CNPRouteShapeLength", "FlipTest", "1", "VB", "")
    CalculateField_management("CNPRouteShapeLength", "Adj_Beg", "!Pend!",
                              "Python", "")
    CalculateField_management("CNPRouteShapeLength", "Adj_End", "!Pbeg!",
                              "Python", "")
    SelectLayerByAttribute_management("CNPRouteShapeLength", "NEW_SELECTION",
                                      '"Pbeg" < "Pend"')
    CalculateField_management("CNPRouteShapeLength", "FlipTest", "0", "VB", "")
    CalculateField_management("CNPRouteShapeLength", "Adj_Beg", "!Pbeg!",
                              "Python", "")
    CalculateField_management("CNPRouteShapeLength", "Adj_End", "!Pend!",
                              "Python", "")
    SelectLayerByAttribute_management("CNPRouteShapeLength", "NEW_SELECTION",
                                      '"Adj_Beg" <= 0.003')
    CalculateField_management("CNPRouteShapeLength", "Adj_Beg", "0", "Python",
                              "")

    print "CNP-Rte Builder script completed successfully"
Example #11
0
def StateHighwayCalibrate(theStateHighwaySegments):
    #theStateHighwaySegments is defined as the roadway segments intended for calibration to the EXOR measures
    #this function is being called by

    #here are the GIS routes with measures extracted regularly from EXOR using the FME extraction and python route reference tools from DT00ar60
    #these routes contain the current exor measures
    #Smlrs = r'Database Connections\RO@sqlgisprod_GIS_cansys.sde\GIS_CANSYS.SHARED.SMLRS'

    #need to define a route source represntative of the correct network year, about 2015
    #should have K-10 on 23rd street still

    Cmlrs = r'Database Connections\RO@sqlgisprod_GIS_cansys.sde\GIS_CANSYS.SHARED.CMLRS_2015'

    from arcpy import FeatureClassToFeatureClass_conversion, FeatureVerticesToPoints_management, LocateFeaturesAlongRoutes_lr, CalculateField_management
    from arcpy import env, MakeFeatureLayer_management, SelectLayerByAttribute_management, DeleteRows_management, AddJoin_management, AddField_management, RemoveJoin_management
    env.overwriteOutput = 1
    # Start by loading NG911 aggregated, conflated road centerlines to an in-memory feature class

    #FeatureClassToFeatureClass_conversion(Roads, "in_memory", "RoadCenterlines", "StateKey1 IS NOT NULL ")
    #FeatureClassToFeatureClass_conversion(Roads, "in_memory", "RoadCenterlines", "StateKey1 IS NOT NULL ")

    MakeFeatureLayer_management(theStateHighwaySegments,
                                "CalibrateRoadCenterlines")
    RoadCenterlines = "CalibrateRoadCenterlines"
    #these are the two linear referencing networks we're going to use to calibrate the state highway system
    #for iteration 2, no source data should refer to the state LRM, so we're only doing the County LRM
    Lrm_Dict = {'COUNTY': Cmlrs}

    #and this is the beginning and end of a line, for which we are going to create a vertex point
    End_List = ['START', 'END']

    # First,  create points at the begin and end of each road centerline segment using Vertices to Points.
    for end in End_List:
        i_end_output = "in_memory/CalibrationPoint" + str(end)
        FeatureVerticesToPoints_management(RoadCenterlines, i_end_output,
                                           str(end))

    #Iterate through the LRMs to bring them into memory and do the processing for each segment begin and end point!
    for key, value in Lrm_Dict.items():
        FeatureClassToFeatureClass_conversion(value, "in_memory",
                                              "LRM" + str(key))
        for end in End_List:
            outtable = "in_memory/" + str(end) + "_" + str(key)
            outstore = spampathfd + r"/" + str(end) + "_" + str(key)
            outproperties = str(key) + "_LRS POINT MEAS_" + str(key)
            if key == "STATE":
                lrskey = str(key) + "_NQR_DESCRIPTION"
            else:
                lrskey = "NQR_DESCRIPTION"
            LocateFeaturesAlongRoutes_lr(
                "in_memory/CalibrationPoint" + str(end),
                "in_memory/LRM" + str(key), lrskey, "500 Feet", outtable,
                outproperties, "ALL", "DISTANCE", "ZERO", "FIELDS",
                "M_DIRECTON")

            #that LFAR function located begin/end segment points to ALL ROUTES within 500 feet of the segment endpoint

            #for calibrating, we are only interested in the points and LFAR Results that where this query is NOT true:
            qNotThisRoad = '"COUNTY_LRS" <> "KDOT_LRS_KEY"'
            #so we will delete the records where this query is trye
            SelectLayerByAttribute_management(
                str(end) + "_" + str(key), "NEW_SELECTION", qNotThisRoad)
            DeleteRows_management(str(end) + "_" + str(key))
            #DeleteField_management(outtable, "Mileage_Length;Mileage_Logmile;ROUTE_PREFIX_TARGET;LRS_ROUTE_NUM_TARGET;LRS_UNIQUE_TARGET;Non_State_System_OBJECTID;LRS_BACKWARD;F_CNTY_2;T_CNTY_2;F_STAT_2;T_STAT_2;CountyKey2;MileFlipCheck;InLine_FID;SimLnFLag")

            #TableToTable_conversion(outtable, ConflationDatabase, outstore)
            #One Method, if using SQL Server, is to use table to table conversion to export to SQL server, then run these query in #CalcUsingSQLserver()
            #If not using SQL server this will suffice, although if there are multiple orig FID's to the original data source FID, there's no logic or handling to discern between the many to one relationship.
            #In the case of hte many to one, or duplicate Orig_FID in the measure table, it might be desirable to choose the closest result
            #A few of the duplicates I reviewed had identical measure values, if that's always the case, then handling the duplicates is unnecessary
            measfield = str(end) + "_" + str(key) + "_meas"
            try:
                AddField_management(theStateHighwaySegments, measfield,
                                    "DOUBLE", "", "", "", "", "NULLABLE",
                                    "NON_REQUIRED")
            except:
                print "could not add the field for calibrated measures"
            jointable = str(end) + "_" + str(key)
            AddJoin_management(theStateHighwaySegments, "OBJECTID", jointable,
                               "ORIG_FID", "KEEP_ALL")
            exp = "!" + jointable + ".MEAS_" + str(key) + "!"
            measfieldcalc = theStateHighwaySegments + "." + measfield
            CalculateField_management(theStateHighwaySegments, measfieldcalc,
                                      exp, "PYTHON")
            RemoveJoin_management(theStateHighwaySegments)

        # NEed to now test for direction again based on begin < end, handle flipping and assemble the routes
    from arcpy import CreateRoutes_lr
    CreateRoutes_lr("CalibrateRoadCenterlines", "KDOT_LRS_KEY",
                    "in_memory/Simplified_CreateRoutes_test1", "TWO_FIELDS",
                    "START_COUNTY_meas", "END_COUNTY_meas", "UPPER_LEFT", "1",
                    "0", "IGNORE", "INDEX")
Example #12
0
Non_State_Roads = r"\\gisdata\arcgis\GISdata\Connection_files\[email protected]\SHARED.NON_STATE_SYSTEM"
Non_State_Sections = r"\\gisdata\arcgis\GISdata\Connection_files\[email protected]\SHARED.NON_STATE_SECTIONS"

#import cx_Oracle
#con = cx_Oracle.connect('shared/gis@sdeprod')
# here, explore using cx_Oracle to run/commit the following SQL Query

#update  NON_STATE_SECTIONS S
#set S.END_MP = S.milepost+ S.length
#where (ABS(S.END_MP - (S.MILEPOST+ S.LENGTH))) >= 0.001 or S.END_MP is null

#print con.version
#con.close()

FeatureClassToFeatureClass_conversion(Non_State_Roads, "in_memory",
                                      "Rural_Major_Collectors",
                                      "LRS_KEY like '%R%'")
MakeFeatureLayer_management("Rural_Major_Collectors",
                            "Rural_Major_Collectors_Flips",
                            """"LRS_BACKWARDS" <0""")
FlipLine_edit("Rural_Major_Collectors_Flips")
CreateRoutes_lr("Rural_Major_Collectors", "LRS_KEY", "in_memory/RMC_Routes",
                "TWO_FIELDS", "LRS_BEG_CNTY_LOGMILE", "LRS_END_CNTY_LOGMILE",
                "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
MakeRouteEventLayer_lr("RMC_Routes", "LRS_KEY", Non_State_Sections,
                       "LRS_KEY LINE MILEPOST END_MP", "NON_STATE_SECTIONS",
                       "", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE",
                       "LEFT", "POINT")
MakeFeatureLayer_management("NON_STATE_SECTIONS", "HP_Colls",
                            "HPMS is not null AND SUPERCEDEDASOF IS NULL")
Example #13
0
#simpleroutecreation.py
# -*- coding: utf-8 -*-
# Created by: Dirk Talley
# 2017-01-24

from arcpy import (env, CopyFeatures_management, CreateRoutes_lr,
                   FlipLine_edit, MakeFeatureLayer_management,
                   SelectLayerByAttribute_management)

env.overwriteOutput = True
env.MResolution = 0.0001
env.MTolerance = 0.001

modifiedData = r'C:\GIS\Geodatabases\KHUB\Testing\R6_For_Vertex_Simplification_10Ft.gdb\RoadCenterlines_10Ft'
modifiedRouteOutput = r'C:\GIS\Geodatabases\KHUB\Testing\R6_For_Vertex_Simplification_10Ft.gdb\RoadCenterlines_10Ft_Routes'

routeId = 'SourceRouteId'
measureSource = 'TWO_FIELDS'
fMeasureField = 'SourceFromMeasure'
tMeasureField = 'SourceToMeasure'
coordinatePriority = 'LOWER_LEFT'
measureFactor = 1
measureOffset = 0
ignoreGaps = True
buildIndex = True

print("Creating routes from the modified data.")
CreateRoutes_lr(modifiedData, routeId, modifiedRouteOutput, measureSource,
                fMeasureField, tMeasureField, coordinatePriority,
                measureFactor, measureOffset, ignoreGaps, buildIndex)
print("Finished creating routes from the modified data.")
Example #14
0
def calibrationCCL():

    print "deriving CCL LRS starting points and calibrations"
    CCLEnd = "!CCL.DBO.CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE!- !CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!"
    CCLBeg = "!CCL.DBO.CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE! - !CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!"
    MakeFeatureLayer_management(LineFeatureClass, "CITY_CONNECTING_LINK_RESET")
    resln = "CITY_CONNECTING_LINK_RESET"
    AddField_management(resln, "CCL_BEGIN", "DOUBLE", 12, 3)
    AddField_management(resln, "CCL_END", "DOUBLE", 12, 3)
    AddJoin_management("CITY_CONNECTING_LINK_RESET", "CCL_LRS",
                       connection1 + "CITY_CONNECTING_LINK_STATE_D", "CCL_LRS",
                       "KEEP_ALL")
    CalculateField_management(resln, "CCL_BEGIN", CCLBeg, "PYTHON")
    CalculateField_management(resln, "CCL_END", CCLEnd, "PYTHON")
    print "calibrating LRS - point calibration method"
    statecalpoints = stateroutelyr + "_Point"
    Intersect_analysis(
        "CCL.DBO.CITY_CONNECTING_LINK_STATE_D #;'Database Connections/SQL61_GIS_CANSYS_RO.sde/GIS_CANSYS.DBO.SMLRS_Point' #",
        "Database Connections/SQL61_GEOADMIN_CCL.sde/CALIBRATION_POINTS_CCL",
        "ALL", "#", "POINT")
    querystr = "Substring( CCL_LRS,4, 12)<> LRS_ROUTE"
    SelectLayerByAttribute_management("CCL.DBO.CALIBRATION_POINTS_CCL",
                                      "NEW_SELECTION", querystr)
    DeleteRows_management("CCL.DBO.CALIBRATION_POINTS_CCL")

    DeleteIdentical_management("CCL.DBO.CALIBRATION_POINTS_CCL",
                               "LRS_KEY;POINT_X;POINT_Y;POINT_M", "#", "0")
    AddField_management("CCL.DBO.CITY_CONNECTING_LINK_STATE", "CCL_BEGIN",
                        "DOUBLE", "#", "#", "#", "#", "NULLABLE",
                        "NON_REQUIRED", "#")
    AddField_management("CCL.DBO.CITY_CONNECTING_LINK_STATE", "CCL_BEGIN",
                        "DOUBLE", "#", "#", "#", "#", "NULLABLE",
                        "NON_REQUIRED", "#")
    AddJoin_management("CCL.DBO.CITY_CONNECTING_LINK_STATE", "CCL_LRS",
                       "CCL.DBO.CITY_CONNECTING_LINK_STATE_D", "CCL_LRS",
                       "KEEP_ALL")
    CalculateField_management(
        "CCL.DBO.CITY_CONNECTING_LINK_STATE",
        "CCL.DBO.CITY_CONNECTING_LINK_STATE.CCL_BEGIN",
        "!CCL.DBO.CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE!- !CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!",
        "PYTHON", "#")
    CalculateField_management(
        "CCL.DBO.CITY_CONNECTING_LINK_STATE",
        "CCL.DBO.CITY_CONNECTING_LINK_STATE.CCL_END",
        "!CCL.DBO.CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE!- !CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!",
        "PYTHON", "#")
    inprops = str(ReferenceRouteKey + " POINT MEASURE")
    AddField_management(connection1 + "CALIBRATION_POINTS_CCL", "CCL_MEASURE",
                        "DOUBLE", 12, 3)
    CalculateField_management("CCL.DBO.CALIBRATION_POINTS_CCL", "CCL_MEASURE",
                              "!POINT_M!- !MIN_BEG_STATE_LOGMILE!", "PYTHON",
                              "#")
    CreateRoutes_lr(LineFeatureClass, NewRouteKey,
                    connection1 + NewRoute + "base", "TWO_FIELDS", NewBeg,
                    NewEnd, "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    CalibrateRoutes_lr(
        "Database Connections/SQL61_GEOADMIN_CCL.sde/CCL.DBO.CCL_LRS_ROUTEbase",
        "CCL_LRS",
        "Database Connections/SQL61_GEOADMIN_CCL.sde/CCL.DBO.CALIBRATION_POINTS_CCL",
        "CCL_LRS", "CCL_MEASURE",
        "Database Connections/SQL61_GEOADMIN_CCL.sde/CCL.DBO.CCL_LRS_ROUTE",
        "DISTANCE", "1 Feet", "BETWEEN", "NO_BEFORE", "NO_AFTER", "IGNORE",
        "KEEP", "INDEX")
    AddField_management(connection1 + NewRoute, "NETWORKDATE", "DATE")
    CalculateField_management(connection1 + NewRoute, "NETWORKDATE",
                              "datetime.datetime.now( )", "PYTHON_9.3", "#")
    MakeFeatureLayer_management(connection1 + "CCL_LRS_ROUTE", NewRoute)
Example #15
0
 FeatureClassToGeodatabase_conversion(rfc, outws)
 FeatureVerticesToPoints_management(rfc, outws + "/" + idc + "_VP", "ALL")
 LocateFeaturesAlongRoutes_lr(outws + "/" + idc + "_VP", rfc, IDfield,
                              "0 DecimalDegrees",
                              outws + "/" + idc + "_CPT",
                              "NE_UNIQUE POINT AASHTO_MEAS", "FIRST",
                              "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
 DeleteIdentical_management(outws + "/" + idc + "_CPT",
                            "NE_UNIQUE;AASHTO_MEAS", "#", "0")
 Statistics_analysis(outws + "/" + idc + "_CPT",
                     outws + "/" + idc + "_ENDS",
                     "AASHTO_MEAS MIN;AASHTO_MEAS MAX", "NE_UNIQUE")
 AddJoin_management(idc + "_SRND", IDfield, outws + "/" + idc + "_ENDS",
                    IDfield, "KEEP_ALL")
 CreateRoutes_lr(idc + "_SRND", IDfield, outws + "/" + idc, "TWO_FIELDS",
                 idc + "_ENDS.MAX_AASHTO_MEAS",
                 idc + "_ENDS.MIN_AASHTO_MEAS", "UPPER_LEFT", "1", "0",
                 "IGNORE", "INDEX")
 MakeRouteEventLayer_lr(outws + "/" + idc + "_SRND", IDfield,
                        outws + "/" + idc + "_CPT",
                        "NE_UNIQUE POINT AASHTO_MEAS", idc + "_CP", "#",
                        "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE",
                        "LEFT", "POINT")
 FeatureClassToGeodatabase_conversion(idc + "_CP", outws)
 MakeFeatureLayer_management(
     outws + "/" + idc + "_CP", idc + "_CP",
     IDfield + " LIKE '" + row.getValue(IDfield) + "'")
 AddJoin_management(idc + "_CP", IDfield, outws + "/" + idc + "_ENDS",
                    IDfield, "KEEP_ALL")
 CalculateField_management(
     idc + "_CP", idc + "_CP.AASHTO_MEAS",
     '[' + idc + '_ENDS.MAX_AASHTO_MEAS] - [' + idc + '_CP.AASHTO_MEAS]',