示例#1
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") 
示例#2
0
def createSourceRoutes123():
    from arcpy import CreateRoutes_lr, FlipLine_edit, AddField_management, FeatureClassToFeatureClass_conversion, SelectLayerByAttribute_management, CalculateField_management
    from KhubCode25.KhubCode25Config import localProFileGDBWorkspace

    fileformatDateStr = startDateTime.strftime("%Y%m%d")
    localfilegdb = localProFileGDBWorkspace + '\\' + 'KhubRoadCenterlines' + fileformatDateStr + '.gdb'
    FeatureClassToFeatureClass_conversion(
        localfilegdb + "\\All_Road_Centerlines", "in_memory",
        "SourceRoadCenterlines123",
        "LRS_ROUTE_SUFFIX in ( '0' , 'A' , 'B' , 'C' , 'Y' , 'S' ) AND LRS_ROUTE_PREFIX in ( 'I' , 'K' , 'U' )"
    )

    #flip backward routes
    #selecting by End less than begin mileage: 3/7/2018, 14948 routes need flipped
    #Selection by State Flip Flag = "Y" 3/7/2018, 14752 routes need flipped
    #for county_log_end < county_log_begin AND STATE_FLIP_FLAG NOT LIKE 'Y' there are 5 records, all 5 are K-14 on the mitchell/jewell county line
    #flip flag has become unreliable, do not use, just use mileage relationship

    AddField_management("SourceRoadCenterlines123", "TmpDblVal", "DOUBLE", "",
                        "", "", "", "NULLABLE", "NON_REQUIRED", "")
    SelectLayerByAttribute_management("SourceRoadCenterlines123",
                                      "NEW_SELECTION",
                                      "county_log_end < county_log_begin")

    CalculateField_management("SourceRoadCenterlines123", "TmpDblVal",
                              "!county_log_begin!", "PYTHON")
    CalculateField_management("SourceRoadCenterlines123", "county_log_begin",
                              "!county_log_end!", "PYTHON", "")
    CalculateField_management("SourceRoadCenterlines123", "county_log_end",
                              "!TmpDblVal!", "PYTHON", "")
    FlipLine_edit("SourceRoadCenterlines123")
    #once these lines have been flipped, we will flag them with an F in the state flip flag field
    CalculateField_management("SourceRoadCenterlines123", "STATE_FLIP_FLAG",
                              "'F'", "PYTHON")
示例#3
0
 def StateHighwaySystemDissolve():
     # Create an in-memory copy of state highay system routes based on LRS Route Prefix
     FeatureClassToFeatureClass_conversion(routesSourceCenterlines, "in_memory", inMemFeatureClassName, "LRS_ROUTE_PREFIX in ('I', 'U', 'K')")
     MakeFeatureLayer_management(inMemFeatureClass, stateSystemFeatureLayer)
     #about 941 records in Southwest Kansas had reverse mileages and need to be flipped
     #this should be corrected in the final conflation delivery
     #if it is not corrected, these route segments should be explored in more detail
     
     SelectLayerByAttribute_management(stateSystemFeatureLayer, "NEW_SELECTION", """("COUNTY_BEGIN_MP" > "COUNTY_END_MP" OR "STATE_BEGIN_MP" > "STATE_END_MP") AND "STATE_FLIP_FLAG" IS NULL""")
     CalculateField_management(stateSystemFeatureLayer, "STATE_FLIP_FLAG", """'Y'""", "PYTHON_9.3", "")
     
     SelectLayerByAttribute_management(stateSystemFeatureLayer, "NEW_SELECTION", """"STATE_FLIP_FLAG" = 'Y' """)
     FlipLine_edit(stateSystemFeatureLayer)
     #need to flip mileages where geometry was flipped so add fields
     AddField_management(stateSystemFeatureLayer, "F_CNTY_2", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
     AddField_management(stateSystemFeatureLayer, "T_CNTY_2", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
     AddField_management(stateSystemFeatureLayer, "F_STAT_2", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
     AddField_management(stateSystemFeatureLayer, "T_STAT_2", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
     
     #check if there are any state system segments where the to is greater than the from and flag them for review
     AddField_management(stateSystemFeatureLayer, "MileFlipCheck", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
     
     CalculateField_management(stateSystemFeatureLayer, "F_CNTY_2", "!COUNTY_END_MP!", "PYTHON_9.3", "")
     CalculateField_management(stateSystemFeatureLayer, "T_CNTY_2", "!COUNTY_BEGIN_MP!", "PYTHON_9.3", "")
     CalculateField_management(stateSystemFeatureLayer, "F_STAT_2", "!STATE_END_MP!", "PYTHON_9.3", "")
     CalculateField_management(stateSystemFeatureLayer, "T_STAT_2", "!STATE_BEGIN_MP!", "PYTHON_9.3", "")
     
     # Switch selection and calculate mileages
     
     SelectLayerByAttribute_management(in_layer_or_view=stateSystemFeatureLayer, selection_type="SWITCH_SELECTION", where_clause="")
     
     CalculateField_management(stateSystemFeatureLayer, "F_CNTY_2", "!COUNTY_BEGIN_MP!", "PYTHON_9.3", "")
     CalculateField_management(stateSystemFeatureLayer, "T_CNTY_2", "!COUNTY_END_MP!", "PYTHON_9.3", "")
     CalculateField_management(stateSystemFeatureLayer, "F_STAT_2", "!STATE_BEGIN_MP!", "PYTHON_9.3", "")
     CalculateField_management(stateSystemFeatureLayer, "T_STAT_2", "!STATE_END_MP!", "PYTHON_9.3", "")
     #KDOT Direction should already be calculated, by running "DualCarriagweayIdentity.py" and updating the KDOT_DIRECTION_CALC to 1 where dual carriagway is found
     #Validation_CheckOverlaps can also help do identify sausage link/parallel geometries that may indicate dual carriagway, but that script does not yet 
     #identify and calculate the KDOT_DIRECTION_CALC flag.  It probably could with more development
     # Select the EB routes and change the LRS_Direction to WB
     
     SelectLayerByAttribute_management(stateSystemFeatureLayer, "NEW_SELECTION", """"KDOT_DIRECTION_CALC" = '1' AND "LRS_DIRECTION" = 'EB'""")
     CalculateField_management(stateSystemFeatureLayer, "LRS_DIRECTION", "'WB'", "PYTHON_9.3", "")
     #Select the SB routes to chante hte LRS direction to SB
     SelectLayerByAttribute_management(stateSystemFeatureLayer, "NEW_SELECTION", """"KDOT_DIRECTION_CALC" = '1' AND "LRS_DIRECTION" = 'NB'""")
     CalculateField_management(stateSystemFeatureLayer, "LRS_DIRECTION", "'SB'", "PYTHON_9.3", "")
     # Clear the selections
     SelectLayerByAttribute_management(stateSystemFeatureLayer, "CLEAR_SELECTION", "")
     
     #Calculate County LRS Key in CountyKey1 field for State Highway system
     #Need to add CountyKey2 for iteration 2, also go ahead and add new LRS Key format
     CalculateField_management(stateSystemFeatureLayer, "CountyKey1", """[LRS_COUNTY_PRE] + [LRS_ROUTE_PREFIX] + [LRS_ROUTE_NUM] + [LRS_ROUTE_SUFFIX] + [LRS_UNIQUE_IDENT] +"-" + [LRS_DIRECTION]""", "VB")
     CalculateField_management(stateSystemFeatureLayer, "StateKey1", """[LRS_ROUTE_PREFIX] + [LRS_ROUTE_NUM] + [LRS_ROUTE_SUFFIX] + [LRS_UNIQUE_IDENT] +"-" + [LRS_DIRECTION]""", "VB")
     
     #this is the dissolve - the output of this is a feature class which is clean for route creation of the state highway system
     Dissolve_management(stateSystemFeatureLayer, routesSourceDissolveOutput+"_Dissolve_EO", "CountyKey1;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_NUM;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT;LRS_DIRECTION", "F_CNTY_2 MIN;T_CNTY_2 MAX", "SINGLE_PART", "DISSOLVE_LINES")
     Dissolve_management(stateSystemFeatureLayer, routesSourceDissolveOutput+"_Unsplit_EO", "CountyKey1;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_NUM;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT;LRS_DIRECTION", "F_CNTY_2 MIN;T_CNTY_2 MAX", "SINGLE_PART", "UNSPLIT_LINES")
示例#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")
示例#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")
示例#6
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"
def CollectorDissolve():
    from arcpy import FeatureClassToFeatureClass_conversion, FlipLine_edit, SelectLayerByAttribute_management, CalculateField_management

    from arcpy import AddField_management, Dissolve_management, Delete_management
    FeatureClassToFeatureClass_conversion(
        roadcenterlines, "in_memory", "Classified_System",
        "LRS_ROUTE_PREFIX in ('R', 'M', 'C')")
    CalculateField_management(
        "Classified_System", "CountyKey1",
        "!Non_State_System_LRSKey![:-1]+ !KDOT_DIRECTION_CALC!", "PYTHON_9.3",
        "")
    #select lines that need to be flipped - this query should include them all, and not result in any double flips
    SelectLayerByAttribute_management(
        "Classified_System", "NEW_SELECTION",
        """("NON_STATE_FLIP_FLAG" = 'Y'  AND( "LRS_BACKWARD" IS NULL OR "LRS_BACKWARD" = 0)) OR ("LRS_BACKWARD" IN( -1 , 1 ) AND "NON_STATE_FLIP_FLAG" IS NULL)"""
    )
    #editorial note:  as of 2/13/2017, draft statewide conflation deliverable, there are 41782 of 93600 segments in the above queries for flips on the classified networks
    #there are 38525 segments where the non_state begin logmile is greater than the non state end logmile
    #flip geometry and calculate begin/end miles
    FlipLine_edit("Classified_System")
    AddField_management("Classified_System", "F_CNTY_2", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("Classified_System", "T_CNTY_2", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("Classified_System", "F_STAT_2", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("Classified_System", "T_STAT_2", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")

    CalculateField_management("Classified_System", "F_CNTY_2",
                              "!NON_STATE_END_MP!", "PYTHON_9.3", "")
    CalculateField_management("Classified_System", "T_CNTY_2",
                              "!NON_STATE_BEGIN_MP!", "PYTHON_9.3", "")

    #calculate mileages for non flip segments
    SelectLayerByAttribute_management("Classified_System", "SWITCH_SELECTION",
                                      "")
    CalculateField_management("Classified_System", "F_CNTY_2",
                              "!NON_STATE_BEGIN_MP!", "PYTHON_9.3", "")
    CalculateField_management("Classified_System", "T_CNTY_2",
                              "!NON_STATE_END_MP!", "PYTHON_9.3", "")

    #check for increasing logmiles

    SelectLayerByAttribute_management("Classified_System", "NEW_SELECTION",
                                      '"F_CNTY_2" > "T_CNTY_2"')
    #as of 2/13/2017, draft statewide conflation deliverable at this point there are 5206 segments meeting this criteria
    #upon initial review, lots of variables... need to review what's going on here more

    #There is 1 segment flagged with KDOT_DIRECTION_CALC = 1
    #Also, the Non-State_System was conflated with the GIS_LRS_KEY, not the NSND NE_Unique which MAY be preferable for data migration.
    #based on discussion with Kevin K, there shouldnt be any unique information keyed to the non-primary direction
    #The NSND NE_Unique key should be calculate-able from the LRS Key parts we have once we calculate the appropriate direction code
    #The NSND does not follow Even/East Odd/North rule 100%
    SelectLayerByAttribute_management("Classified_System", "NEW_SELECTION",
                                      """"KDOT_DIRECTION_CALC" = '1'""")
    #We are also going to need to refer to the NSND or NUSYS layer from CANSYS to determine whether a route is EB or NB, logically

    SelectLayerByAttribute_management("Classified_System", "CLEAR_SELECTION",
                                      "")

    Dissolve_management(
        "Classified_System", ClassOutput + "dissolve",
        "CountyKey1;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_NUM;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT;KDOT_DIRECTION_CALC",
        "F_CNTY_2 MIN;T_CNTY_2 MAX", "SINGLE_PART", "DISSOLVE_LINES")
    Dissolve_management(
        "Classified_System", ClassOutput + "Unsplit",
        "CountyKey1;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_NUM;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT;KDOT_DIRECTION_CALC",
        "F_CNTY_2 MIN;T_CNTY_2 MAX", "SINGLE_PART", "UNSPLIT_LINES")
    #Once dissolved, delete the in memory dataset to free up resources
    #review the dissolve output, go back and flag the input data
    Delete_management("Classified_System")
示例#8
0
def StateHighwaySystemDissolve():
    from arcpy import FeatureClassToFeatureClass_conversion, FlipLine_edit, SelectLayerByAttribute_management, CalculateField_management
    print "processing the state highway system"
    from arcpy import AddField_management, Dissolve_management, Delete_management

    # Create an in-memory copy of state highway system routes based on LRS Route Prefix
    FeatureClassToFeatureClass_conversion(
        roadcenterlines, "in_memory", "State_System",
        "LRS_ROUTE_PREFIX in ('I', 'U', 'K')")

    #this happens in memory, only do this in memory, and don't do it twice or the flipping logic will break
    #Many records have state system flip flags that are falsely identified as yes.
    #The flip flag by definition tells you about the nature of the geometry direction accumulation of vertices compared to the direction accummulation of measures.
    #If the measures are backwards, ie the end measure is less than the begin measure, that is the defining indicator
    #that the centerline vertex accumulation is opposite the measure accumulation.
    #to be consistent, this processing will orient all vertices in the direction of measure accumulation,
    #and at the attribute level,  ensure all begin measures are less than the end measures for all segments to be processed

    #two lines here correct false positive flip flags
    SelectLayerByAttribute_management(
        "State_System", "NEW_SELECTION",
        """("COUNTY_BEGIN_MP" > "COUNTY_END_MP") AND "STATE_FLIP_FLAG" = """
        "'Y'"
        "")
    CalculateField_management("State_System", "STATE_FLIP_FLAG", """''""",
                              "PYTHON_9.3", "")

    #about 941 records in Southwest Kansas had reverse mileages and need to be flipped
    #two lines here correct null flip flags
    SelectLayerByAttribute_management(
        "State_System", "NEW_SELECTION",
        """("COUNTY_BEGIN_MP" > "COUNTY_END_MP") AND "STATE_FLIP_FLAG" IS NULL"""
    )
    CalculateField_management("State_System", "STATE_FLIP_FLAG", """'Y'""",
                              "PYTHON_9.3", "")

    #flip the lines using the flip flag
    SelectLayerByAttribute_management("State_System", "NEW_SELECTION",
                                      """"STATE_FLIP_FLAG" = 'Y' """)
    FlipLine_edit("State_System")

    #need to flip mileages where geometry was flipped so add fields
    AddField_management("State_System", "F_CNTY_2", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    AddField_management("State_System", "T_CNTY_2", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    AddField_management("State_System", "F_STAT_2", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    AddField_management("State_System", "T_STAT_2", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    AddField_management("State_System", "CountyKey2", "TEXT", "15", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")

    #check if there are any state system segments where the to measure is less than the from measure and flag them for review
    AddField_management("State_System", "MileFlipCheck", "LONG", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("State_System", "F_CNTY_2", "!COUNTY_END_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "T_CNTY_2", "!COUNTY_BEGIN_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "F_STAT_2", "!STATE_END_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "T_STAT_2", "!STATE_BEGIN_MP!",
                              "PYTHON_9.3", "")

    #Switch selection and calculate mileages
    SelectLayerByAttribute_management("State_System", "SWITCH_SELECTION", "")

    CalculateField_management("State_System", "F_CNTY_2", "!COUNTY_BEGIN_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "T_CNTY_2", "!COUNTY_END_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "F_STAT_2", "!STATE_BEGIN_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "T_STAT_2", "!STATE_END_MP!",
                              "PYTHON_9.3", "")

    #KDOT Direction should already be calculated, by running "DualCarriagweayIdentity.py" and updating the KDOT_DIRECTION_CALC to 1 where dual carriageway is found
    #Validation_CheckOverlaps can also help identify sausage link/parallel geometries that may indicate dual carriageway
    #identify and calculate the KDOT_DIRECTION_CALC flag by whatever means necessary - script, manual editing
    #Select the EB routes and change the LRS_Direction to WB

    SelectLayerByAttribute_management(
        "State_System", "NEW_SELECTION",
        """"KDOT_DIRECTION_CALC" = '1' AND "LRS_DIRECTION" = 'EB'""")
    CalculateField_management("State_System", "LRS_DIRECTION", "'WB'",
                              "PYTHON_9.3", "")
    #Select the SB routes to change the LRS direction to SB

    SelectLayerByAttribute_management(
        "State_System", "NEW_SELECTION",
        """"KDOT_DIRECTION_CALC" = '1' AND "LRS_DIRECTION" = 'NB'""")
    CalculateField_management("State_System", "LRS_DIRECTION", "'SB'",
                              "PYTHON_9.3", "")

    #Clear the selections
    SelectLayerByAttribute_management("State_System", "CLEAR_SELECTION", "")

    #Calculate County LRS Key in CountyKey1 field for State Highway system
    #Need to add CountyKey2 for iteration 2, also go ahead and add new LRS Key format
    CalculateField_management(
        "State_System", "CountyKey2",
        """[LRS_COUNTY_PRE] + [LRS_ROUTE_PREFIX] + [LRS_ROUTE_NUM] + [LRS_ROUTE_SUFFIX] + [LRS_UNIQUE_IDENT] +"-" + [LRS_DIRECTION]""",
        "VB")
    #CalculateField_management("State_System", "StateKey2", """[LRS_ROUTE_PREFIX] + [LRS_ROUTE_NUM] + [LRS_ROUTE_SUFFIX] + [LRS_UNIQUE_IDENT] +"-" + [LRS_DIRECTION]""", "VB")

    SuperSimpleSimplify("State_System")

    StateHighwayCalibrate("Simplified")

    #this is the dissolve - the output of this is a feature class which is "clean" for route creation of the state highway system
    #looking at the dissolve output, you can easily identify multipart issues due to KDOT_DIRECTION_CALC settings and/or ghost routes
    #Dissolve_management("State_System", SSoutput+"dissolve", "CountyKey2;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_NUM;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT;LRS_DIRECTION", "F_CNTY_2 MIN;T_CNTY_2 MAX", "SINGLE_PART", "DISSOLVE_LINES")
    #Dissolve_management("State_System", SSoutput+"Unsplit" , "CountyKey2;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_NUM;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT;LRS_DIRECTION", "F_CNTY_2 MIN;T_CNTY_2 MAX", "SINGLE_PART", "UNSPLIT_LINES")
    #Once dissolved, delete the in memory dataset to free up resources
    #review the dissolve output, go back and flag the input data

    print "...and hardly a splash!"
示例#9
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")
def StateHighwaySystemDissolve():
    from arcpy import FeatureClassToFeatureClass_conversion, FlipLine_edit, SelectLayerByAttribute_management, CalculateField_management
    print "Up now, the state highway system"
    from arcpy import AddField_management, Dissolve_management, Delete_management
    print "The state highways are a little over 10,000 miles these days"
    print "That's right arnie, they've been dominating transportation in Kansas since about 1936."
    print "stepping up to the ladder now"
    # Create an in-memory copy of state highay system routes based on LRS Route Prefix
    FeatureClassToFeatureClass_conversion(
        roadcenterlines, "in_memory", "State_System",
        "LRS_ROUTE_PREFIX in ('I', 'U', 'K')")
    #about 941 records in Southwest Kansas had reverse mileages and need to be flipped
    #this should be corrected in the final conflation delivery
    #if it is not corrected, these route segments should be explored in more detail
    print "and we're off"
    #print "ready, set, go!"
    SelectLayerByAttribute_management(
        "State_System", "NEW_SELECTION",
        """("COUNTY_BEGIN_MP" > "COUNTY_END_MP" OR "STATE_BEGIN_MP" > "STATE_END_MP") AND "STATE_FLIP_FLAG" IS NULL"""
    )
    CalculateField_management("State_System", "STATE_FLIP_FLAG", """'Y'""",
                              "PYTHON_9.3", "")

    SelectLayerByAttribute_management("State_System", "NEW_SELECTION",
                                      """"STATE_FLIP_FLAG" = 'Y' """)

    print "here comes a 180 whirly-doo"
    FlipLine_edit("State_System")

    #need to flip mileages where geometry was flipped so add fields
    AddField_management("State_System", "F_CNTY_2", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    AddField_management("State_System", "T_CNTY_2", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    AddField_management("State_System", "F_STAT_2", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    AddField_management("State_System", "T_STAT_2", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")

    #check if there are any state system segments where the to is greater than the from and flag them for review
    AddField_management("State_System", "MileFlipCheck", "LONG", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    print "with a twist"
    CalculateField_management("State_System", "F_CNTY_2", "!COUNTY_END_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "T_CNTY_2", "!COUNTY_BEGIN_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "F_STAT_2", "!STATE_END_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "T_STAT_2", "!STATE_BEGIN_MP!",
                              "PYTHON_9.3", "")

    # Switch selection and calculate mileages
    print "then a spin"
    SelectLayerByAttribute_management("State_System", "SWITCH_SELECTION", "")

    CalculateField_management("State_System", "F_CNTY_2", "!COUNTY_BEGIN_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "T_CNTY_2", "!COUNTY_END_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "F_STAT_2", "!STATE_BEGIN_MP!",
                              "PYTHON_9.3", "")
    CalculateField_management("State_System", "T_STAT_2", "!STATE_END_MP!",
                              "PYTHON_9.3", "")
    #KDOT Direction should already be calculated, by running "DualCarriagweayIdentity.py" and updating the KDOT_DIRECTION_CALC to 1 where dual carriagway is found
    #Validation_CheckOverlaps can also help do identify sausage link/parallel geometries that may indicate dual carriagway, but that script does not yet
    #identify and calculate the KDOT_DIRECTION_CALC flag.  It probably could with more development
    # Select the EB routes and change the LRS_Direction to WB

    print "...changing directions here, now going the other way.."
    SelectLayerByAttribute_management(
        "State_System", "NEW_SELECTION",
        """"KDOT_DIRECTION_CALC" = '1' AND "LRS_DIRECTION" = 'EB'""")
    CalculateField_management("State_System", "LRS_DIRECTION", "'WB'",
                              "PYTHON_9.3", "")
    #Select the SB routes to chante hte LRS direction to SB
    SelectLayerByAttribute_management(
        "State_System", "NEW_SELECTION",
        """"KDOT_DIRECTION_CALC" = '1' AND "LRS_DIRECTION" = 'NB'""")
    CalculateField_management("State_System", "LRS_DIRECTION", "'SB'",
                              "PYTHON_9.3", "")
    # Clear the selections
    SelectLayerByAttribute_management("State_System", "CLEAR_SELECTION", "")

    #Calculate County LRS Key in CountyKey1 field for State Highway system
    #Need to add CountyKey2 for iteration 2, also go ahead and add new LRS Key format
    CalculateField_management(
        "State_System", "CountyKey1",
        """[LRS_COUNTY_PRE] + [LRS_ROUTE_PREFIX] + [LRS_ROUTE_NUM] + [LRS_ROUTE_SUFFIX] + [LRS_UNIQUE_IDENT] +"-" + [LRS_DIRECTION]""",
        "VB")
    CalculateField_management(
        "State_System", "StateKey1",
        """[LRS_ROUTE_PREFIX] + [LRS_ROUTE_NUM] + [LRS_ROUTE_SUFFIX] + [LRS_UNIQUE_IDENT] +"-" + [LRS_DIRECTION]""",
        "VB")

    print "here comes the big finish, a triple lindy"
    #this is the dissolve - the output of this is a feature class which is clean for route creation of the state highway system
    Dissolve_management(
        "State_System", SSoutput + "dissolve",
        "CountyKey1;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_NUM;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT;LRS_DIRECTION",
        "F_CNTY_2 MIN;T_CNTY_2 MAX", "SINGLE_PART", "DISSOLVE_LINES")
    Dissolve_management(
        "State_System", SSoutput + "Unsplit",
        "CountyKey1;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_NUM;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT;LRS_DIRECTION",
        "F_CNTY_2 MIN;T_CNTY_2 MAX", "SINGLE_PART", "UNSPLIT_LINES")
    #Once dissolved, delete the in memory dataset to free up resources
    #review the dissolve output, go back and flag the input data
    print "...and hardly a splash!"
    Delete_management("State_System")