def setupEnv(): print "run at "+ str(datetime.datetime.now()) rsel = "ENDDATE IS NULL" MakeTableView_management(resolve, "CCL_Resolution_tbl", rsel) CalculateField_management("CCL_Resolution_tbl", "CCL_LRS", 'str(!CITYNUMBER!)+str(!LRS_KEY![3:14])', "PYTHON" ) MakeTableView_management(connection1+"CCL_Resolution", "CCL_Resolution_tbl10", 'CITYNUMBER<100') CalculateField_management("CCL_Resolution_tbl10", "CCL_LRS", '"0"+str(!CITYNUMBER!)+str(!LRS_KEY![3:14])', "PYTHON") MakeFeatureLayer_management(cntyroutelyr, "cmlrs") MakeFeatureLayer_management(stateroutelyr, "smlrs") MakeFeatureLayer_management(citylimits, "CityLimits", "TYPE IN ( 'CS', 'ON')") LocateFeaturesAlongRoutes_lr(citylimits,"cmlrs","LRS_KEY","0 Feet",connection1+"GIS_CITY","LRS_KEY LINE Beg_CMP End_CMP","FIRST","DISTANCE","NO_ZERO","FIELDS","M_DIRECTON") MakeRouteEventLayer_lr("cmlrs","LRS_KEY","CCL_Resolution_tbl","LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE","City_Connecting_Links","#","ERROR_FIELD","NO_ANGLE_FIELD","NORMAL","ANGLE","LEFT","POINT") MakeTableView_management(connection1+"GIS_CITY", "GIS_CITY") MakeTableView_management(laneclass, "LaneClass") MakeRouteEventLayer_lr("cmlrs","LRS_KEY","GIS_CITY","LRS_KEY LINE BEG_CMP END_CMP","GIS_BASED_CCL","#","ERROR_FIELD","NO_ANGLE_FIELD","NORMAL","ANGLE","LEFT","POINT") OverlayRouteEvents_lr(connection1+"CCL_Resolution","LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE",laneclass,"LRS_KEY LINE BCMP ECMP","INTERSECT",connection1+"CCL_LANE_CLASS_OVERLAY","LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE","NO_ZERO","FIELDS","INDEX") print "create Route Layer specific to City Connecting Link locations" FeatureClassToFeatureClass_conversion("City_Connecting_Links", connection0, "CITY_CONNECTING_LINK_CENTERLINE") LocateFeaturesAlongRoutes_lr(connection1+"CITY_CONNECTING_LINK_CENTERLINE",stateroutelyr,"LRS_ROUTE","0 Meters",connection1+"CCL_STATE_LRS_tbl","LRS_ROUTE LINE BEG_STATE_LOGMILE END_STATE_LOGMILE","FIRST","DISTANCE","ZERO","FIELDS","M_DIRECTON") MakeRouteEventLayer_lr("smlrs", "LRS_ROUTE",connection1+"CCL_STATE_LRS_tbl","LRS_ROUTE LINE BEG_STATE_LOGMILE END_STATE_LOGMILE","CCL_STATE_LRS","#","ERROR_FIELD","NO_ANGLE_FIELD","NORMAL","ANGLE","LEFT","POINT") FeatureClassToFeatureClass_conversion("CCL_STATE_LRS", connection0, "CITY_CONNECTING_LINK_STATEREF") if Exists(connection1+"CITY_CONNECTING_LINK_STATE"): Delete_management(connection1+"CITY_CONNECTING_LINK_STATE") Dissolve_management(connection1+"CITY_CONNECTING_LINK_STATEREF",connection1+"CITY_CONNECTING_LINK_STATE","LRS_ROUTE;CITY;CITYNUMBER;DESCRIPTION;CCL_LRS","BEG_STATE_LOGMILE MIN;END_STATE_LOGMILE MAX","MULTI_PART","UNSPLIT_LINES") Dissolve_management(connection1+"CITY_CONNECTING_LINK_STATEREF",connection1+"CITY_CONNECTING_LINK_STATE_D","CCL_LRS","BEG_STATE_LOGMILE MIN;END_STATE_LOGMILE MAX","MULTI_PART","DISSOLVE_LINES") print "processes to Create the layer that will be used to create a new LRS for city connecting links"
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")
def UniqueIDgen(): for i in range(87, 88): c = str(i).zfill(3) #print "filling in unique Route IDs for county %s" %c expression = "LRS_ROUTE_PREFIX = 'L' AND LRS_COUNTY_PRE = '%s'" % c layer = "County" + c MakeFeatureLayer_management(target, layer, expression) #this part of the script performs a couple types of dissolves to create a unique set of numbers in 4 characters for every route in a county #first, do an unsplit dissolve for each local road in the county based on the RD, STS, and POD fields #this creates nice segments from which to build the destination routes Dissolve_management(layer, "in_memory/" + layer + "d1", "RD;STS;POD;LRS_COUNTY_PRE", "GCID COUNT", "SINGLE_PART", "UNSPLIT_LINES") #add, calculate, and index a field for a join operation #cant add index to in memory database so skip that part AddField_management(layer + "d1", "ConCatRtName", "TEXT", "", "", "50", "", "NULLABLE", "NON_REQUIRED", "") AddField_management(layer + "d1", "RouteNum1", "TEXT", "", "", "6", "", "NULLABLE", "NON_REQUIRED", "") AddField_management(layer + "d1", "UniqueNum1", "TEXT", "", "", "3", "", "NULLABLE", "NON_REQUIRED", "") CalculateField_management( layer + "d1", "ConCatRtName", """[LRS_COUNTY_PRE]&[RD] & [STS] & [POD] """, "VB", "") #dissolve the unsplit dissolve layer to a multipart, full dissolve to get unique road names Dissolve_management(layer + "d1", "in_memory/" + layer + "d2", "ConCatRtName;RouteNum1", "", "MULTI_PART", "DISSOLVE_LINES") #A spatial sort here might be nice #Calculate a unique 4 digit number for each road name #I'm just using the Object ID to calculate the unique number string, with a spatial sort another incrementation method would be needed #the road names should mostly be unique, so a spatial sort at this level would only be beneficial of there is POD field is the only road name distinction #otherwise an attribute sort would be sufficient, if necessary CalculateField_management("in_memory/" + layer + "d2", "RouteNum1", "str(!OBJECTID!).zfill(4)", "PYTHON_9.3", "") # add the unique id field and increment each duplicate road name part # calculate that unique number back to the split dissolve AddJoin_management(layer + "d1", "ConCatRtName", "County087d2", "ConCatRtName", "KEEP_ALL") CalculateField_management(layer + "d1", layer + "d1.RouteNum1", "[" + layer + "d2.RouteNum1]", "VB", "") #AddField_management("in_memory/"+layer+"d2", "UniqueNum1", "TEXT", "", "", "3", "", "NULLABLE", "NON_REQUIRED", "") RemoveJoin_management(layer + "d1") #try this spatial sort thing here Sort_management("in_memory/" + layer + "d1", "in_memory/" + layer + "d1_Sort", "Shape ASCENDING;RouteNum1 ASCENDING", "LL") #now we run the incrementer to calcualte the unique ID's #the incrementer isnt working here, but it is calculating a unique ID on for the segments, and it is going it better and much faster than the join method #it might be better to use the incrementer to do this calculation on the sorted table, then figure out the unique ID Incrementer("in_memory/" + layer + "d1") Delete_management("in_memory/" + layer + "d1") Delete_management("in_memory/" + layer + "d2") Delete_management("in_memory/" + layer + "d2_Sort")
def route_endings_generation(): # Overwrite tables env.overwriteOutput = True # May need to check locks # Local variables: SHARED_NON_STATE_SYSTEM = r"\\gisdata\ArcGIS\GISdata\Connection_files\[email protected]\SHARED.NON_STATE_SYSTEM" RS_Routes = r"\\gisdata\Planning\Cart\Maps\MXD\County\County_Maps.gdb\RS_Routes" RS_Endings_Dissolve = r"\\gisdata\Planning\Cart\Maps\MXD\County\County_Maps.gdb\RS_Endings_Dissolve" C_Routes_Temp = r"in_memory\C_Routes_Temp" C_Endings_Dissolve = r"\\gisdata\Planning\Cart\Maps\MXD\County\County_Maps.gdb\C_Endings_Dissolve" MCS_Routes_Temp = r"in_memory\MCS_Routes_Temp" MCS_Endings_Dissolve = r"\\gisdata\Planning\Cart\Maps\MXD\County\County_Maps.gdb\MCS_Endings_Dissolve" SHARED_STATE_SYSTEM = r"\\gisdata\ArcGIS\GISdata\Connection_files\[email protected]\SHARED.STATE_SYSTEM" State_Routes_Dissolve = r"\\gisdata\Planning\Cart\Maps\MXD\County\County_Maps.gdb\STATE_SYSTEM_Dissolve" # Process: Select Select_analysis(SHARED_NON_STATE_SYSTEM, RS_Routes, "LRS_ROUTE_PREFIX = 'R'") # Process: Dissolve Dissolve_management(RS_Routes, RS_Endings_Dissolve, "LRS_KEY", "", "SINGLE_PART", "DISSOLVE_LINES") # Process: Select Select_analysis(SHARED_NON_STATE_SYSTEM, C_Routes_Temp, "LRS_ROUTE_PREFIX = 'C'") # Process: Dissolve Dissolve_management(C_Routes_Temp, C_Endings_Dissolve, "LRS_KEY", "", "MULTI_PART", "DISSOLVE_LINES") # Process: Select Select_analysis(SHARED_NON_STATE_SYSTEM, MCS_Routes_Temp, "LRS_ROUTE_PREFIX = 'M'") # Process: Dissolve Dissolve_management(MCS_Routes_Temp, MCS_Endings_Dissolve, "LRS_KEY", "", "SINGLE_PART", "DISSOLVE_LINES") # Process: Dissolve Dissolve_management(SHARED_STATE_SYSTEM, State_Routes_Dissolve, "LRS_ROUTE;LRS_PREFIX", "", "MULTI_PART", "DISSOLVE_LINES")
def Report(): OverlayRouteEvents_lr( connection1 + "MAINTENANCE_CCL", "CCL_LRS LINE CCL_BEGIN CCL_END", connection1 + "LANECLASS_CCL", "CCL_LRS LINE CCL_BEGIN CCL_END", "UNION", connection1 + "CCL_Report_M", "CCL_LRS LINE CCL_MA_BEGIN CCL_MA_END", "NO_ZERO", "FIELDS", "INDEX") DissolveRouteEvents_lr(connection1 + "CCL_Report_M", "CCL_LRS LINE CCL_MA_BEGIN CCL_MA_END", "CITYNO;MAINT_DESC;CITY_NAME;Lanes", connection1 + "CCL_Report_D", "CCL_LRS LINE CCL_MA_BEGIN CCL_MA_END", "CONCATENATE", "INDEX") #cleanup border errors - make feature layers based on City, city number, and CCLLRS and delete where they are not consistent between Maintenance and Resolution sections if Exists(connection1 + "CCL_Report"): MakeTableView_management(connection1 + "CCL_Report", "Report_Clean1", "CCL_LRS2 <> CCL_LRS") DeleteRows_management("Report_Clean1") LocateFeaturesAlongRoutes_lr(LineFeatureClass, connection1 + "CCL_LRS_ROUTE", NewRouteKey, "#", connection1 + "RES_SECTION_CCL", "CCL_LRS LINE CCL_BEGIN CCL_END", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") OverlayRouteEvents_lr( connection1 + "RES_SECTION_CCL", "CCL_LRS LINE CCL_BEGIN CCL_END", connection1 + "CCL_Report_D", "CCL_LRS LINE CCL_MA_BEGIN CCL_MA_END", "INTERSECT", connection1 + "CCL_Report", "CCL_LRS LINE CCL_BEGIN CCL_END", "NO_ZERO", "FIELDS", "INDEX") MakeRouteEventLayer_lr(connection1 + "CCL_LRS_ROUTE", "CCL_LRS", connection1 + "CCL_Report", "CCL_LRS LINE CCL_BEGIN CCL_END", "City Connecting Links Mapping", "#", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT") print "add mapping fields for lane miles" AddField_management("City Connecting Links Mapping", "CenterlineMiles", "DOUBLE") CalculateField_management("City Connecting Links Mapping", "CenterlineMiles", '[CCL_END]-[CCL_BEGIN]', "VB") AddField_management("City Connecting Links Mapping", "LaneMiles", "DOUBLE") CalculateField_management("City Connecting Links Mapping", "LaneMiles", '([CCL_END]-[CCL_BEGIN])*[Lanes]', "VB") AddField_management(connection1 + "CITY_CONNECTING_LINK_CENTERLINE", "CenterlineMiles", "DOUBLE") MakeFeatureLayer_management( connection1 + "CITY_CONNECTING_LINK_CENTERLINE", 'Res_centerline') CalculateField_management("Res_centerline", "CenterlineMiles", '[END_CNTY_LOGMILE]-[BEG_CNTY_LOGMILE]', "VB") Dissolve_management("Res_centerline", connection1 + "CCL_LEGEND", "CITY;LRS_KEY;CITYNUMBER;CCL_LRS", "CenterlineMiles SUM", "MULTI_PART", "DISSOLVE_LINES") AddField_management(connection1 + "CCL_LEGEND", "CCL_LEGEND", "TEXT", "#", "#", "50") legendexp = 'str(!CCL_LRS![3]) +"-" + str(!CCL_LRS![6:9]).lstrip("0")+"........"+ str(!SUM_CenterlineMiles!)' MakeFeatureLayer_management(connection1 + "CCL_LEGEND", 'LegendCalc') CalculateField_management("LegendCalc", "CCL_LEGEND", legendexp, "PYTHON_9.3", "#")
def PostProcAnnum(admin_workspace): Unlock(admin_workspace) #AADT is historical and left open so it takes a really long time to run all the junk that exists in this layer #It might help to put a def query in the MXD that ilmits AADT to 5 years #sine AADT is only updated once a year, this can be run manually annually or as needed AADT = admin_workspace + "/GIS_CANSYS.DBO.ACCS" Unlock(admin_workspace) Dissolve_management( admin_workspace + "/GIS_CANSYS.DBO.V_ACCS_SDO_V", AADT, "CRND_RTE;LRS_KEY;STATE_LRS;ROUTE_NO;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;ACS_CTRL_ID;ACS_CTRL_ID_DESC", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(AADT, "readonly", "GRANT", "AS_IS")
def PostProcAnnum(): Unlock(admin_workspace) AADT = "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.ACCS" Unlock(admin_workspace) Dissolve_management( "Database Connections/SQL61_GIS_CANSYS.sde/GIS_CANSYS.DBO.V_ACCS_SDO_V", AADT, "CRND_RTE;LRS_KEY;STATE_LRS;ROUTE_NO;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;ACS_CTRL_ID;ACS_CTRL_ID_DESC", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(AADT, "readonly", "GRANT", "AS_IS") AcceptConnections(admin_workspace, True)
def PostProcAnnum(owner_workspace, admin_workspace): Unlock(admin_workspace) owner = "GIS_CANSYS.SHARED." outpre = owner_workspace + "/" + owner #AADT is historical and left open so it takes a really long time to run all the junk that exists in this layer #It might help to put a def query in the MXD that ilmits AADT to 5 years #sine AADT is only updated once a year, this can be run manually annually or as needed AADT = outpre + "AADT" Unlock(admin_workspace) Dissolve_management( outpre + "V_AADT_SDO_V", AADT, "CRND_RTE;LRS_KEY;STATE_LRS;ROUTE_NO;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;AADT_CNT;CNT_DT;XPNSN_FCTR;XPNSN_FCTR_DT;FTR_AADT;ALTD_FTR_AADT;ALTD_FTR_DT;K_FCTR;HVY_CMRCL;RAW_HVY_CMRCL;HVY_CMRCL_DT;PCT_HVY_CMRCL;MED_TRK;RAW_MED_TRK;HVY_TRK;RAW_HVY_TRK;RAW_NON_HVY_COMM;TRF_SEQ;DIR_SPLT;AADT_COUNT_YEAR;RAW_AADT_CNT", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(AADT, "readonly", "GRANT", "AS_IS")
def Non_State_Centerpoint_Check(): MakeFeatureLayer_management(in_features="Database Connections/SDEPROD_SHARED.sde/SHARED.NON_STATE_SYSTEM", out_layer="C_Routes", where_clause="LRS_KEY like '%C%' OR LRS_ROUTE_PREFIX = 'C'") FeatureToPoint_management(NonState_fx, "C_Routes_Point", "INSIDE") #LocateFeaturesAlongRoutes_lr(NonState_fx, NUSYS, "ROUTE", "50 Feet", "Nonstate_Point_LFAR", "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") Intersect_analysis("Nusys_Extract #;C_Routes #", out_feature_class="C:/temp/Nusys_Check.gdb/C_Routes_Point_Int5", join_attributes="ALL", cluster_tolerance="5 Feet", output_type="POINT") Dissolve_management("C_Routes_Point_Int5", out_feature_class="C:/temp/Nusys_Check.gdb/C_Routes_Point_Int_Route_Mileage_5D", dissolve_field="ROUTE;DIVIDED_UNDIVIDED;LRS_KEY", statistics_fields="COUNTY_BEGIN_MP MIN;COUNTY_END_MP MAX;LRS_BEG_CNTY_LOGMILE MIN;LRS_END_CNTY_LOGMILE MAX", multi_part="MULTI_PART", unsplit_lines="DISSOLVE_LINES") AddField_management(in_table="C_Routes_Point_Int_Route_Mileage_5D", field_name="Check_LRS", field_type="TEXT", field_precision="", field_scale="", field_length="15", field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="") CalculateField_management(in_table="C_Routes_Point_Int_Route_Mileage_5D", field="Check_LRS", expression="!LRS_KEY![:11]", expression_type="PYTHON_9.3", code_block="") AddField_management(in_table="C_Routes_Point_Int_Route_Mileage_5D", field_name="Check_Route", field_type="TEXT", field_precision="", field_scale="", field_length="15", field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="") CalculateField_management(in_table="C_Routes_Point_Int_Route_Mileage_5D", field="Check_Route", expression="!Route![:11]", expression_type="PYTHON_9.3", code_block="") MakeFeatureLayer_management("C_Routes_Point_Int_Route_Mileage_5D", out_layer="C_Routes_Check_Del", where_clause="Check_Route <> Check_LRS OR Check_Route is null OR Check_LRS is null") DeleteFeatures_management("C_Routes_Check_Del")
def FIMS_GIS(FMIS_ADD): #arcpy.MakeFeatureLayer_management(CPMSlyr, 'CPMS', ProjectSelect) #only process the new rows in FMIS_ADD MakeFeatureLayer_management(CPMSlyr, 'CPMS') MakeFeatureLayer_management(CountyLyr, 'County') MakeFeatureLayer_management(HPMSlyr, 'HPMS') MakeFeatureLayer_management(MPOLyr, 'MPO') MakeFeatureLayer_management(CONGDistlyr, 'CONG') MakeFeatureLayer_management(ws + "/Polygons", 'Polygons') #make the polygon analysis layer for Districts, Counties, and MPOs #arcpy.Union_analysis("CONG #;MPO #;County #",ws+"/Polygons","ALL","1 feet","GAPS") MakeTableView_management(FMIS_ADD, 'CPMS_STAGING_TMP') AddJoin_management("CPMS", "PROJECT_ID", "CPMS_STAGING_TMP", "PROJECT_NUMBER", "KEEP_COMMON") Output_Event_Table_Properties = 'RID LINE CNTY_BEG CNTY_END' outtblP = ws + "/FIMS_EventTableAreas" outtblH = ws + "/FIMS_EventTableLines" if Exists(outtblP): Delete_management(outtblP) #consider/testing running "in memory" LocateFeaturesAlongRoutes_lr('CPMS', 'HPMS', "Route_ID", "30 Feet", outtblH, Output_Event_Table_Properties, "FIRST", "DISTANCE", "NO_ZERO", "FIELDS", "M_DIRECTON") MakeRouteEventLayer_lr("HPMS", "Route_ID", "FIMS_EventTableLines", "rid LINE CNTY_BEG CNTY_END", "FIMS_EventTableLineLyr", "#", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT") Intersect_analysis("FIMS_EventTableLineLyr #;HPMS #;Polygons #", ws + "/FMIS_Data", "ALL", "#", "LINE") Dissolve_management( "FMIS_Data", ws + r"/HPMS_Data", "PROJECT_ID;F_SYSTEM_V;NHS_VN;DISTRICT_1;COUNTY_NUMBER;ID_1", "#", "MULTI_PART", "UNSPLIT_LINES") # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script LocateFeaturesAlongRoutes_lr("HPMS_Data", "HPMS", "Route_ID", "0 Feet", ws + "/FIMS_EventTable", "RID LINE CNTY_BEG CNTY_END", "FIRST", "DISTANCE", "NO_ZERO", "FIELDS", "M_DIRECTON")
def CityLimitsMod_OLD(): env.overwriteOutput = True env.workspace = mainFeaturesLocation modfile = r'Database Connections\SDEPROD_GIS.sde\GIS.CITY_LIMITS_MODS_KDOT_1' taxfile = r'Database Connections\SDEPROD_GIS.sde\GIS.CITY_LIMITS_KDOR_1' cityLimitsAdd = "CITY_LIMITS_MODS_ADD" cityLimitsSub = "CITY_LIMITS_MODS_SUBTRACT" CalculateField_management( modfile, "LOAD_DATE", "str(datetime.datetime.now( ))[0:4]+str(datetime.datetime.now( ))[5:7]+str(datetime.datetime.now( ))[8:10]", "PYTHON_9.3", "#") MakeFeatureLayer_management(modfile, cityLimitsAdd, "MODTYPE = 'ADD'", "#", "#") MakeFeatureLayer_management(modfile, cityLimitsSub, "MODTYPE = 'SUBTRACT'", "#", "#") KDOTcity = r'Database Connections\SDEPROD_GIS.sde\GIS.CITY_LIMITS_1' CityTemp = r'Database Connections\SDEPROD_GIS.sde\GIS.CITY_TEMP' CityOutlines = r'Database Connections\SDEPROD_GIS.sde\GIS.CITY_LIMITS_LN_1' DisconnectHarshly_SDEPROD() AllowConnections_SDEPROD() if Exists(CityTemp): print "CityTemp exists" Delete_management(CityTemp) else: print "I don't think CityTemp exists." pass # Instead of erase, might try a union, then selection for only the features # that do not have their centers within the 2nd feature class, # then output the selected features. # MakeFeatureLayer, Union, SelectByLocation, CopyFeatures. Erase_analysis(taxfile, cityLimitsSub, CityTemp, "0 Feet") Append_management(cityLimitsAdd, CityTemp, "NO_TEST", "#", "#") Dissolve_management( CityTemp, KDOTcity, "CITYNUMBER;CITY;COUNTY;DIST;TYPE;POPCENSUS;POPCURRENT;ID1", "LOAD_DATE MAX", "MULTI_PART", "DISSOLVE_LINES") FeatureToLine_management(KDOTcity, CityOutlines, "0.01 Feet", "ATTRIBUTES")
def main(): print("Starting to dissolve the routes source.") stateSystemSelectedFeatures = 'StateSystem_Features' selectQuery1 = '''LRS_ROUTE_PREFIX in ('I', 'U', 'K')''' MakeFeatureLayer_management (routesSourceCenterlines, stateSystemSelectedFeatures, selectQuery1) CopyFeatures_management(stateSystemSelectedFeatures, routesSourcePreDissolveOutput) #GetCount on the features in the layer here. countResult = GetCount_management(stateSystemSelectedFeatures) intCount = int(countResult.getOutput(0)) print('Found ' + str(intCount) + ' state system features to be dissolved.') # Removed STATE_FLIP_FLAG because we've already flipped the data prior to this process. dissolveFields = "KDOT_DIRECTION_CALC;KDOT_LRS_KEY;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT" statisticsFields = "BEG_NODE MIN;BEG_NODE MAX;END_NODE MAX;END_NODE MIN;COUNTY_BEGIN_MP MIN;COUNTY_END_MP MAX" multipart = "SINGLE_PART" unsplitLines = "DISSOLVE_LINES" ## Use a selection for the state system so that it will work the first time. ## Then, later expand the selection and the amount of routes that are attempted for ## the dissolve. Dissolve_management(stateSystemSelectedFeatures, routesSourceDissolveOutput, dissolveFields, statisticsFields, multipart, unsplitLines) print("Completed dissolving the routes source.")
def PostProcDissolveOne(): owner = "GIS_CANSYS.SHARED." outpre = admin_workspace + "/" + owner DissolveLayer = "MED" PostProcDissolveLocation = "MED" # @UnusedVariable #each layer for GIS should be dissolved as multi-part lines so they can more efficiently be mapped online #each layer has different fields so each of these dissolves can be tested in ArcMap and copied to this script as needed try: Outputlyr = outpre + DissolveLayer MakeFeatureLayer_management( owner + "V_MED_SDO_V", "MED_PRIMARY", "CRND_RTE LIKE '%EB' OR CRND_RTE LIKE '%NB'", "#", "#") Dissolve_management( "MED_PRIMARY", Outputlyr, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;MED_ID;MED_ID_DESC;MED_WDTH;MED_WDTH_FT", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(Outputlyr, "readonly", "GRANT", "AS_IS") #print "MED dissolved for viewing" except: print "oops" pass
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")
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")
def CityLimitsMod(): from arcpy import MakeFeatureLayer_management, Erase_analysis, Append_management, env, CalculateField_management, Dissolve_management, FeatureToLine_management env.overwriteOutput = 1 modfile = r'Database Connections\SDEPROD_GIS.sde\GIS.Administrative_Boundary\GIS.CITY_LIMITS_MODS_KDOT' taxfile = r'Database Connections\SDEPROD_GIS.sde\GIS.Administrative_Boundary\GIS.CITY_LIMITS_KDOR' CalculateField_management( modfile, "LOAD_DATE", "str(datetime.datetime.now( ))[0:4]+str(datetime.datetime.now( ))[5:7]+str(datetime.datetime.now( ))[8:10]", "PYTHON_9.3", "#") MakeFeatureLayer_management(modfile, "CITY_LIMITS_MODS_ADD", "MODTYPE = 'ADD'", "#", "#") MakeFeatureLayer_management(modfile, "CITY_LIMITS_MODS_SUBTRACT", "MODTYPE = 'SUBTRACT'", "#", "#") KDOTcity = r'Database Connections\SDEPROD_GIS.sde\GIS.Administrative_Boundary\GIS.CITY_LIMITS' CityTemp = r'Database Connections\SDEPROD_GIS.sde\GIS.Administrative_Boundary\GIS.TempCity' Erase_analysis(taxfile, "CITY_LIMITS_MODS_SUBTRACT", CityTemp, "#") Append_management("CITY_LIMITS_MODS_ADD", CityTemp, "NO_TEST", "#", "#") Dissolve_management( CityTemp, KDOTcity, "CITYNUMBER;CITY;COUNTY;DIST;TYPE;POPCENSUS;POPCURRENT;ID1", "LOAD_DATE MAX", "MULTI_PART", "DISSOLVE_LINES") CityOutlines = r"Database Connections/SDEPROD_GIS.sde/GIS.Administrative_Boundary/GIS.CITY_LIMITS_LN" FeatureToLine_management("GIS.CITY_LIMITS", CityOutlines, "0.01 Feet", "ATTRIBUTES")
LocateFeaturesAlongRoutes_lr( connection1 + "CITY_CONNECTING_LINK_CENTERLINE", stateroutelyr, "LRS_ROUTE", "0 Meters", connection1 + "CCL_STATE_LRS_tbl", "LRS_ROUTE LINE BEG_STATE_LOGMILE END_STATE_LOGMILE", "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") MakeRouteEventLayer_lr("smlrs", "LRS_ROUTE", connection1 + "CCL_STATE_LRS_tbl", "LRS_ROUTE LINE BEG_STATE_LOGMILE END_STATE_LOGMILE", "CCL_STATE_LRS", "#", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT") FeatureClassToFeatureClass_conversion("CCL_STATE_LRS", connection0, "CITY_CONNECTING_LINK_STATEREF") if Exists(connection1 + "CITY_CONNECTING_LINK_STATE"): Delete_management(connection1 + "CITY_CONNECTING_LINK_STATE") Dissolve_management(connection1 + "CITY_CONNECTING_LINK_STATEREF", connection1 + "CITY_CONNECTING_LINK_STATE", "LRS_ROUTE;CITY;CITYNUMBER;DESCRIPTION;CCL_LRS", "BEG_STATE_LOGMILE MIN;END_STATE_LOGMILE MAX", "MULTI_PART", "UNSPLIT_LINES") Dissolve_management(connection1 + "CITY_CONNECTING_LINK_STATEREF", connection1 + "CITY_CONNECTING_LINK_STATE_D", "CCL_LRS", "BEG_STATE_LOGMILE MIN;END_STATE_LOGMILE MAX", "MULTI_PART", "DISSOLVE_LINES") print "processes to Create the layer that will be used to create a new LRS for city connecting links" 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"
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")
"in_memory", "DAS1", "", "#", config_keyword="") AddField_management("DAS1", "DAS", "Text", "#", "#", "4") CalculateField_management("DAS1", "DAS", "[MAINT_DISTRICT] & [MAINT_AREA] & [MAINT_SUB_AREA]", "VB", code_block="") gp.EucAllocation_sa("DAS1", "in_memory/EucAllo_Subarea", "", "", "1E-03", "DAS", "", "") RasterToPolygon_conversion("EucAllo_Subarea", "in_Memory/DAS_Poly", "SIMPLIFY", "Value") Dissolve_management("DAS1", "in_memory/DAS_Dissolve", "DAS", "", "SINGLE_PART", "DISSOLVE_LINES") FeatureToPoint_management("DAS_Dissolve", "in_memory/DAS_Dissolve_FeatureToPoint", "INSIDE") SpatialJoin_analysis("DAS_Poly", "DAS_Dissolve_FeatureToPoint", "in_memory/MAINTENANCE_AREA", "JOIN_ONE_TO_ONE", "KEEP_ALL", "", "CONTAINS", "", "") #this is the time to look at the in memory process and edit any null DAS values, and review the changes Clip_analysis("in_memory/MAINTENANCE_AREA", "Database Connections/GISPROD_Shared.sde/SHARED.STATE_BOUNDARY", "in_memory/MAINTENANCE_AREA_CLIP", "") AddField_management("MAINTENANCE_AREA_CLIP", "D", "Text", "#", "#", "1") AddField_management("MAINTENANCE_AREA_CLIP", "A", "Text", "#", "#", "1") AddField_management("MAINTENANCE_AREA_CLIP", "S", "Text", "#", "#", "1")
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")
def RM_Calibrate(): import datetime startDateTime = datetime.datetime.now() print( "starting SHS calibration at " + str(startDateTime) + ", it should take about 20 minutes to calibrate non-state system urban and rural classified routes" ) from KhubCode25.KhubCode25Config import devorprod, dbname, dbownername, localProFileGDBWorkspace, KDOTConnections, prodDataSourceSDE, devDataSourceSDE, RuralClassifiedRoutes, UrbanClassifiedRoutes if devorprod == 'prod': database = prodDataSourceSDE print("running on " + devorprod) else: database = devDataSourceSDE print("running on " + devorprod) fileformatDateStr = startDateTime.strftime("%Y%m%d") from arcpy import (MakeFeatureLayer_management, FeatureVerticesToPoints_management, LocateFeaturesAlongRoutes_lr, MakeRouteEventLayer_lr, Dissolve_management, Exists) localfilegdb = localProFileGDBWorkspace + '\\' + 'KhubRoadCenterlinesTemp' + fileformatDateStr + '.gdb' print(localfilegdb) sdegdb = KDOTConnections + r'\\' + database + r'\\' + dbname + "." + dbownername CalibrateD1 = sdegdb + ".All_Road_Centerlines_D1" RMRoute = sdegdb + "." + RuralClassifiedRoutes Croutes = sdegdb + "." + UrbanClassifiedRoutes FeatureClassToFeatureClass(RMRoute, localfilegdb, "RM_Routes") nusysprimary = "DIRECTION IN ('EB', 'NB') Or (DIVIDED_UNDIVIDED = 'U' And DIRECTION IN ('SB', 'WB'))" FeatureClassToFeatureClass(Croutes, localfilegdb, "C_Routes", nusysprimary) RMRoute = localfilegdb + "." + r"/RM_Routes" Croutes = localfilegdb + "." + r"/C_Routes" MakeFeatureLayer_management(CalibrateD1, "D1_NUSYS", "LRS_ROUTE_PREFIX = 'C'", None, "#") MakeFeatureLayer_management(CalibrateD1, "D1_RM", "LRS_ROUTE_PREFIX IN ('M', 'R')", None, "") print("making endpoints for nusys") FeatureVerticesToPoints_management("D1_NUSYS", localfilegdb + r"\Nusys_END", "END") FeatureVerticesToPoints_management("D1_NUSYS", localfilegdb + r"\Nusys_START", "START") print("making endpoints for rural") FeatureVerticesToPoints_management("D1_RM", localfilegdb + r"\RM_END", "END") FeatureVerticesToPoints_management("D1_RM", localfilegdb + r"\RM_START", "START") print("Exporting rural event tables") LocateFeaturesAlongRoutes_lr(localfilegdb + r"\RM_START", RMRoute, "LRS_KEY", "250 Feet", localfilegdb + r"\START_D1_RM", "LRS_KEY Point RM_MEAS", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") LocateFeaturesAlongRoutes_lr(localfilegdb + r"\RM_END", RMRoute, "LRS_KEY", "250 Feet", localfilegdb + r"\END_D1_RM", "LRS_KEY Point RM_MEAS", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") print("Exporting urban event tables") print("starting start c") LocateFeaturesAlongRoutes_lr(localfilegdb + r"\Nusys_START", Croutes, "Route", "250 Feet", localfilegdb + r"\START_D1_C", "LRS_KEY Point C_MEAS", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") print("starting end c") LocateFeaturesAlongRoutes_lr(localfilegdb + r"\Nusys_END", Croutes, "Route", "250 Feet", localfilegdb + r"\END_D1_C", "LRS_KEY Point C_MEAS", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") MakeRouteEventLayer_lr(RMRoute, "LRS_KEY", localfilegdb + r"\START_D1_RM", "LRS_KEY Point RM_MEAS", "START_D1_RM Events", None, "ERROR_FIELD", "ANGLE_FIELD", "NORMAL", "COMPLEMENT", "LEFT", "POINT") MakeRouteEventLayer_lr(RMRoute, "LRS_KEY", localfilegdb + r"\END_D1_RM", "LRS_KEY Point RM_MEAS", "END_D1_RM Events", None, "ERROR_FIELD", "ANGLE_FIELD", "NORMAL", "COMPLEMENT", "LEFT", "POINT") MakeRouteEventLayer_lr(Croutes, "Route", localfilegdb + r"\START_D1_C", "LRS_KEY Point C_MEAS", "START_D1_C Events", None, "ERROR_FIELD", "ANGLE_FIELD", "NORMAL", "COMPLEMENT", "LEFT", "POINT") MakeRouteEventLayer_lr(Croutes, "Route", localfilegdb + r"\END_D1_C", "LRS_KEY Point C_MEAS", "END_D1_C Events", None, "ERROR_FIELD", "ANGLE_FIELD", "NORMAL", "COMPLEMENT", "LEFT", "POINT") Dissolve_management( "START_D1_RM Events", localfilegdb + r"\START_D1_RM_DX", "LRS_KEY;RM_MEAS;KDOT_LRS_KEY", "Distance MIN;Distance MAX;KDOT_STATIC_ID2 FIRST;OBJECTID COUNT;RM_MEAS MIN;RM_MEAS MAX", "MULTI_PART", "DISSOLVE_LINES") FeatureClassToFeatureClass(localfilegdb + r"\START_D1_RM_DX", localfilegdb, "START_D1_RM_D", "KDOT_LRS_KEY = LRS_KEY", "#") print("START_D1_RM_D") Dissolve_management( "END_D1_RM Events", localfilegdb + r"\END_D1_RM_DX", "LRS_KEY;RM_MEAS;KDOT_LRS_KEY", "Distance MIN;Distance MAX;KDOT_STATIC_ID2 FIRST;OBJECTID COUNT;RM_MEAS MIN;RM_MEAS MAX", "MULTI_PART", "DISSOLVE_LINES") FeatureClassToFeatureClass(localfilegdb + r"\END_D1_RM_DX", localfilegdb, "END_D1_RM_D", "KDOT_LRS_KEY = LRS_KEY", "#") print("END_D1_RM_D") Dissolve_management( "START_D1_C Events", localfilegdb + r"\START_D1_C_DX", "LRS_KEY;C_MEAS;KDOT_LRS_KEY", "Distance MIN;Distance MAX;KDOT_STATIC_ID2 FIRST;OBJECTID COUNT;C_MEAS MIN;C_MEAS MAX", "MULTI_PART", "DISSOLVE_LINES") FeatureClassToFeatureClass( localfilegdb + r"\START_D1_C_DX", localfilegdb, "START_D1_C_D", "SUBSTRING(KDOT_LRS_KEY,0, 9) = SUBSTRING(LRS_KEY,0,9)", "#") print("START_D1_C_D") Dissolve_management( "END_D1_C Events", localfilegdb + r"\END_D1_C_DX", "LRS_KEY;C_MEAS;KDOT_LRS_KEY", "Distance MIN;Distance MAX;KDOT_STATIC_ID2 FIRST;OBJECTID COUNT;C_MEAS MIN;C_MEAS MAX", "MULTI_PART", "DISSOLVE_LINES") FeatureClassToFeatureClass( localfilegdb + r"\END_D1_C_DX", localfilegdb, "END_D1_C_D", "SUBSTRING(KDOT_LRS_KEY,0, 9) = SUBSTRING(LRS_KEY,0,9)", "#") print("END_D1_C_D") print( 'Calibration process completed in {} hours, minutes, seconds.'.format( datetime.datetime.now() - startDateTime))
def derive_data_from_catchments(catchment_areas, flow_direction_raster, slope_raster, curve_number_raster, area_conv_factor=0.00000009290304, length_conv_factor=1, out_catchment_polygons=None): """ For tools that handle multiple inputs quickly, we execute here (e.g., zonal stats). For those we need to run on individual catchments, this parses the catchments raster and passes individual catchments, along with other required data, to the calc_catchment_flowlength_max function. area_conversion_factor: for converting the area of the catchments to Sq. Km, which is expected by the core business logic. By default, the factor converts from square feet out_catchment_polygons: will optionally return a catchment polygon feature class. Output: an array of records containing info about each inlet's catchment, e.g.: [ { "id": <ID value from pour_point_field (spec'd in catchment_delineation func)> "area_sqkm": <area of inlet's catchment in square km> "avg_slope": <average slope of DEM in catchment> "avg_cn": <average curve number in the catchment> "max_fl": <maximum flow length in the catchment> }, {...}, ... ] """ raster_field = "Value" # store the results, keyed by a catchment ID (int) that comes from the # catchments layer gridcode results = {} # make a raster object with the catchment raster if not isinstance(catchment_areas, Raster): c = Raster(catchment_areas) else: c = catchment_areas # if the catchment raster does not have an attribute table, build one if not c.hasRAT: BuildRasterAttributeTable_management(c, "Overwrite") # make a table view of the catchment raster catchment_table = 'catchment_table' MakeTableView_management( c, catchment_table) #, {where_clause}, {workspace}, {field_info}) # calculate flow length for each zone. Zones must be isolated as individual # rasters for this to work. We handle that with calc_catchment_flowlength_max() # using the table to get the zone values... catchment_count = int(GetCount_management(catchment_table).getOutput(0)) with SearchCursor(catchment_table, [raster_field]) as catchments: # TODO: implement multi-processing for this loop. ResetProgressor() SetProgressor('step', "Mapping flow length for catchments", 0, catchment_count, 1) # msg("Mapping flow length for catchments") for idx, each in enumerate(catchments): this_id = each[0] # msg("{0}".format(this_id)) # calculate flow length for each "zone" in the raster fl_max = calc_catchment_flowlength_max(catchment_areas, this_id, flow_direction_raster, length_conv_factor) if this_id in results.keys(): results[this_id]["max_fl"] = clean(fl_max) else: results[this_id] = {"max_fl": clean(fl_max)} SetProgressorPosition() ResetProgressor() # calculate average curve number within each catchment for all catchments table_cns = so("cn_zs_table", "timestamp", "fgdb") msg("CN Table: {0}".format(table_cns)) ZonalStatisticsAsTable(catchment_areas, raster_field, curve_number_raster, table_cns, "DATA", "MEAN") # push table into results object with SearchCursor(table_cns, [raster_field, "MEAN"]) as c: for r in c: this_id = r[0] this_area = r[1] if this_id in results.keys(): results[this_id]["avg_cn"] = clean(this_area) else: results[this_id] = {"avg_cn": clean(this_area)} # calculate average slope within each catchment for all catchments table_slopes = so("slopes_zs_table", "timestamp", "fgdb") msg("Slopes Table: {0}".format(table_slopes)) ZonalStatisticsAsTable(catchment_areas, raster_field, slope_raster, table_slopes, "DATA", "MEAN") # push table into results object with SearchCursor(table_slopes, [raster_field, "MEAN"]) as c: for r in c: this_id = r[0] this_area = r[1] if this_id in results.keys(): results[this_id]["avg_slope"] = clean(this_area) else: results[this_id] = {"avg_slope": clean(this_area)} # calculate area of each catchment #ZonalGeometryAsTable(catchment_areas,"Value","output_table") # crashes like an mfer cp = so("catchmentpolygons", "timestamp", "in_memory") #RasterToPolygon copies our ids from raster_field into "gridcode" RasterToPolygon_conversion(catchment_areas, cp, "NO_SIMPLIFY", raster_field) # Dissolve the converted polygons, since some of the raster zones may have corner-corner links if not out_catchment_polygons: cpd = so("catchmentpolygonsdissolved", "timestamp", "in_memory") else: cpd = out_catchment_polygons Dissolve_management(in_features=cp, out_feature_class=cpd, dissolve_field="gridcode", multi_part="MULTI_PART") # get the area for each record, and push into results object with SearchCursor(cpd, ["gridcode", "SHAPE@AREA"]) as c: for r in c: this_id = r[0] this_area = r[1] * area_conv_factor if this_id in results.keys(): results[this_id]["area_up"] = clean(this_area) else: results[this_id] = {"area_up": clean(this_area)} # flip results object into a records-style array of dictionaries # (this makes conversion to table later on simpler) # msg(results,"warning") records = [] for k in results.keys(): record = { "area_up": 0, "avg_slope": 0, "max_fl": 0, "avg_cn": 0, "tc_hr": 0 } for each_result in record.keys(): if each_result in results[k].keys(): record[each_result] = results[k][each_result] record["id"] = k records.append(record) if out_catchment_polygons: return records, cpd else: return records, None
def createCountyLinesForEachCounty(): env.workspace = sqlGdbLocation inputCountyLines = sharedCountyLines inputCountyPolygons = sharedCounties dissolvedCountyLines = countyLinesDissolved loadedCounties = 'loadedCounties' tempCountyLines = r'in_memory\tempCountyLines' outputCountyLines = countyLinesIntersectedNoPath bufferCursorFields = ["OBJECTID"] # Dissolve all of those county lines into one set of lines # then, need to create 105 features that are are intersected # with the polygons from said line dissolve. Dissolve_management(inputCountyLines, dissolvedCountyLines) Buffer_analysis(inputCountyPolygons, countiesBuffered, "15500 Feet") bufferedCountyPolygonList = list() outputFeatureList = list() # 1st SearchCursor newCursor = daSearchCursor(countiesBuffered, bufferCursorFields) for newRow in newCursor: bufferedCountyPolygonList.append(list(newRow)) if 'newCursor' in locals(): del newCursor else: pass MakeFeatureLayer_management(countiesBuffered, loadedCounties) loadedCountiesFields = ListFields(loadedCounties) for loadedCountiesField in loadedCountiesFields: print "A loadedCountiesField was found: " + str( loadedCountiesField.name) for listedRow in bufferedCountyPolygonList: selectNumber = listedRow[0] whereClause = """ "OBJECTID" = """ + str(selectNumber) print "The whereClause = " + str(whereClause) SelectLayerByAttribute_management(loadedCounties, "NEW_SELECTION", whereClause) Intersect_analysis([dissolvedCountyLines, loadedCounties], tempCountyLines, "ALL") # 2nd SearchCursor newCursor = daSearchCursor(tempCountyLines, ["SHAPE@", "County_Number", "County_Name"]) for newRow in newCursor: outputFeatureList.append(newRow) if 'newCursor' in locals(): del newCursor else: pass try: Delete_management(countyLinesIntersectedWithUser) except: pass CreateFeatureclass_management(sqlGdbLocation, outputCountyLines, "POLYLINE", "", "", "", spatialReferenceProjection) AddField_management(outputCountyLines, "County_Number", "DOUBLE", "", "", "") AddField_management(outputCountyLines, "County_Name", "TEXT", "", "", "55") print "First Intersected County Row: " + str(outputFeatureList[0]) countyLinesIntersectFields = ["SHAPE@", "County_Number", "County_Name"] newCursor = daInsertCursor(countyLinesIntersectedPath, countyLinesIntersectFields) counter = 1 for outputFeature in outputFeatureList: rowToInsert = ([outputFeature]) insertedOID = newCursor.insertRow(outputFeature) counter += 1 print "Inserted Row with Object ID of " + str(insertedOID) if 'newCursor' in locals(): del newCursor else: pass
def countyAndRoadPreprocessing(): print "Removing non-County roads and other roads not displayed on the map..." featureClass1 = nSSNoZ featureClass1Out = nSSNoZCounty inMemoryRoadsLayer1 = "roadsToCounty" # Need to delete out the non-county roads. CopyFeatures_management(featureClass1, featureClass1Out) # Load the feature class with all non_state roads. MakeFeatureLayer_management(featureClass1Out, inMemoryRoadsLayer1) # Now select & delete all the roads that do not have 999 as their city number, which would mean # that they are in the county. # Also select any roads that will not be shown in the map per Elaine's query: # (SURFACE <> 'Propose' AND SURFACE IS NOT NULL) AND VISIBILITY = 'Y' selectionString = """ "CITYNUMBER" <> 999 OR SURFACE = 'Propose' OR SURFACE IS NULL OR VISIBILITY <> 'Y' """ SelectLayerByAttribute_management(inMemoryRoadsLayer1, "NEW_SELECTION", selectionString) countNumber = GetCount_management(inMemoryRoadsLayer1) if countNumber >= 1: try: DeleteFeatures_management(inMemoryRoadsLayer1) except Exception as e: # If an error occurred, print line number and error message tb = sys.exc_info()[2] print("Line {0}".format(tb.tb_lineno)) print(e.message) else: pass # Cleanup if 'inMemoryRoadsLayer1' in locals(): del inMemoryRoadsLayer1 else: pass featureClass2 = nSSNoZCounty fieldListForRoads = ["RD_NAMES", "COUNTY_NUMBER"] featureClass2Out = nSSNoZCountyDS featureClass3 = featureClass2Out featureClass3Out = nSSNoZCountyClean inMemoryRoadsLayer2 = "roadsToDissolve" inMemoryRoadsLayer3 = "roadsToClean" print "Dissolving road segments by Name & County..." # Load the undissolved feature class. MakeFeatureLayer_management(featureClass2, inMemoryRoadsLayer2) # Dissolve based on RD_NAMES and COUNTY_NUMBER. Dissolve_management(inMemoryRoadsLayer2, featureClass2Out, fieldListForRoads, "", "SINGLE_PART", "DISSOLVE_LINES") # Cleanup if 'inMemoryRoadsLayer2' in locals(): del inMemoryRoadsLayer2 else: pass print "Deleting unnamed road segments..." # Copy the feature class to prepare for deleting unnamed roads. CopyFeatures_management(featureClass3, featureClass3Out) # Load the copied feature class. MakeFeatureLayer_management(featureClass3Out, inMemoryRoadsLayer3) # Now select & delete all the roads that have <null> or "" as their roadname. selectionString = """ "RD_NAMES" IS NULL OR "RD_NAMES" = '' OR "COUNTY_NUMBER" = 0 OR "COUNTY_NUMBER" >= 106""" SelectLayerByAttribute_management(inMemoryRoadsLayer3, "NEW_SELECTION", selectionString) countNumber = GetCount_management(inMemoryRoadsLayer3) print "For " + selectionString + ", selected = " + str(countNumber) if countNumber >= 1: try: DeleteFeatures_management(inMemoryRoadsLayer3) except Exception as e: # If an error occurred, print line number and error message tb = sys.exc_info()[2] print("Line {0}".format(tb.tb_lineno)) print(e.message) try: del tb except: pass else: pass # Cleanup if 'inMemoryRoadsLayer3' in locals(): del inMemoryRoadsLayer3 else: pass print "Preprocessing for county road label points is complete!"
def DissolveNonDirectionalItems(OpEnvironmentMode): OpRunIn = OpEnvironment.OpRunInSum # @UndefinedVariable OpRunOut = OpEnvironment.OpRunOut # @UndefinedVariable adm = OpEnvironment.adm # @UndefinedVariable Owner = OpEnvironment.Owner # @UndefinedVariable DB = OpEnvironment.DB # @UndefinedVariable env.workspace = OpRunIn env.overwriteOutput = True print OpRunIn #combine the connection, db, and owner to the destination path for enterprise geodatabase output OpRunFullOut = OpRunOut + "/" + DB + "." + Owner + "." print OpRunFullOut FCList = ListFeatureClasses() print "dissolving items in the primary direction" FCGlobalFieldsDissolve = [ "LRS_KEY", "COUNTY_CD", "COUNTY_NAME", "DISTRICT" ] FCGlobalFieldsSummarize = "BSMP MIN;ESMP MAX;BCMP MIN;ECMP MAX" FCFieldsIgnore = [ "OBJECTID", "CRND_RTE", "LANE_DIRECTION", "DIV_UNDIV", "SHAPE", "SHAPE.STLength()", "BSMP", "ESMP", "BCMP", "ECMP", "OLD_FUN_CLASS", "FUN_DT" ] for Item in FCList: ItemOut = Item[2:] ItemDissolveFields = [] print ItemOut fields = ListFields(Item) for field in fields: if field.name not in FCFieldsIgnore: #print " "+field.name ItemDissolveFields.append(field.name) dissolvelist = ItemDissolveFields + FCGlobalFieldsDissolve DissolveFields = ';'.join(dissolvelist) if Exists(OpRunFullOut + ItemOut): try: print "feature class " + str( ItemOut) + " exists and will be updated" Dissolve_management(Item, "in_memory/" + ItemOut, DissolveFields, FCGlobalFieldsSummarize, "MULTI_PART", "DISSOLVE_LINES") TruncateTable_management(OpRunFullOut + ItemOut) Append_management("in_memory/" + ItemOut, OpRunFullOut + ItemOut, "NO_TEST", "#") Delete_management("in_memory/" + ItemOut) print "feature class " + str( ItemOut) + " was successfully updated" except ExecuteError: print "update failed because the schema has changed from what existed" #need to add locking DisconnectUser(adm, "readonly") AcceptConnections(adm, True) Delete_management(OpRunFullOut + ItemOut) print "recreating the dissolved feature class for " + str( ItemOut) Dissolve_management(Item, OpRunFullOut + ItemOut, DissolveFields, FCGlobalFieldsSummarize, "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(OpRunFullOut + ItemOut, "readonly", "GRANT", "AS_IS") except: print "another error happened on updating the feature class" else: print "feature class " + str( ItemOut) + " will be created or overwritten" DisconnectUser(adm, "readonly") AcceptConnections(adm, True) Dissolve_management(Item, OpRunFullOut + ItemOut, DissolveFields, FCGlobalFieldsSummarize, "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(OpRunFullOut + ItemOut, "readonly", "GRANT", "AS_IS") try: Delete_management("in_memory/" + Item) except: pass
def PostProcDissolve(): owner = "GIS_CANSYS.SHARED." outpre = owner_workspace + "/" + owner PostProcDissolveLocation = "" #each layer for GIS should be dissolved as multi-part lines so they can more efficiently be mapped online #each layer has different fields so each of these dissolves can be tested in ArcMap and copied to this script as needed try: ##PostProcDissolveLocation = "ACCS" ACCS = outpre + "ACCS" Unlock(admin_workspace) Dissolve_management( owner + "V_ACCS_SDO_V", ACCS, "CRND_RTE;LRS_KEY;STATE_LRS;ROUTE_NO;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;ACS_CTRL_ID;ACS_CTRL_ID_DESC", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(ACCS, "readonly", "GRANT", "AS_IS") #PostProcDissolveLocation = "SMAP" SMAP = outpre + "SMAP" Unlock(admin_workspace) Dissolve_management( owner + "V_SMAP_SDO_V", SMAP, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;STATIONING_TYPE;STATIONING_TYPE_DESC;BEGIN_STATIONING;BEGIN_STATIONING_DECIMAL;END_STATIONING;END_STATIONING_DECIMAL;PROJECT_YEAR;PROJECT_NUMBER;PROJECT_TYPE;PROJECT_TYPE_DESC;HOST_PROJECT_NUMBER;PW_URL", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(SMAP, "readonly", "GRANT", "AS_IS") print "SMAP dissolved for viewing" #PostProcDissolveLocation = "LYRS" LYRS = outpre + "LYRS" Dissolve_management( owner + "V_LYRS_SDO_V", LYRS, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;LAYER_TYPE;LAYER_TYPE_DESC;MATERIAL_TYPE;MATERIAL_TYPE_DESC;DEPTHS_MILLIMETERS;LAYER_DATE;MATERIAL_WIDTH_METERS;MATERIAL_WIDTH_FEET;SOURCE_TYPE;SOURCE_TYPE_DESC;PROJECT_ID;PW_URL", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(LYRS, "readonly", "GRANT", "AS_IS") print "LYRS dissolved for viewing" #PostProcDissolveLocation = "LNCL" LNCL = outpre + "LNCL" MakeFeatureLayer_management( outpre + "V_LNCL_SDO_V", "LNCL_PRIMARY", "CRND_RTE LIKE '%EB' OR CRND_RTE LIKE '%NB'", "#", "OBJECTID OBJECTID VISIBLE NONE;CRND_RTE CRND_RTE VISIBLE NONE;LRS_KEY LRS_KEY VISIBLE NONE;BCMP BCMP VISIBLE NONE;ECMP ECMP VISIBLE NONE;BSMP BSMP VISIBLE NONE;ESMP ESMP VISIBLE NONE;COUNTY_CD COUNTY_CD VISIBLE NONE;COUNTY_NAME COUNTY_NAME VISIBLE NONE;LANE_DIRECTION LANE_DIRECTION VISIBLE NONE;DISTRICT DISTRICT VISIBLE NONE;DIV_UNDIV DIV_UNDIV VISIBLE NONE;LNCL_CLS_ID LNCL_CLS_ID VISIBLE NONE;LNCL_CLS_ID_DESC LNCL_CLS_ID_DESC VISIBLE NONE;LNCL_DT LNCL_DT VISIBLE NONE;Shape Shape VISIBLE NONE;Shape.STLength() Shape.STLength() VISIBLE NONE" ) Dissolve_management( "LNCL_PRIMARY", LNCL, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;LNCL_CLS_ID;LNCL_CLS_ID_DESC", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(LNCL, "readonly", "GRANT", "AS_IS") print "LNCL dissolved for viewing" #PostProcDissolveLocation = "CPMS" CPMS = outpre + "CPMS" Dissolve_management( owner + "V_CPMS_SDO_V", CPMS, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;SCHEME_ID;PROJECT_ID;TECH_NAME;WORK_TYPE_DESC;DESIGN_CRITERIA;LEG_MAP_ID;CATEGORY_CODE;SUBCAT_CODE;PROJECT_DESC_FRND;PROJ_DISTRICT;PROJ_AREA;PROJ_SUB_AREA;PROJ_LENGTH;HOST_PROJ_NUM;FISCAL_YEAR_PRGM;LETTING_DATE;PW_URL", "BCMP MIN;BSMP MIN;ECMP MAX;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(CPMS, "readonly", "GRANT", "AS_IS") print "CPMS dissolved for viewing" #PostProcDissolveLocation = "POEQ" POEQ = outpre + "POEQ" Dissolve_management( owner + "V_POEQ_SDO_V", POEQ, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;IRIR;RLIFE;RLIFE_DEFAULT;RLIFE_DEFAULT_DESC;EQFAULT;EQJD;EQTCR;RUTVAL;PVMTGRP;PVMTGRP_DESC;DEF_FLAG;DEF_FLAG_DESC;POEQ_DT;MEAN_IRIR;YEAR_LAST_IMP;YEAR_LAST_CONST;LAST_OVERLAY_THIC;IRIR_DATE;IRIR_DATE_DEFAULT;IRIR_DATE_DEFAULT_DESC", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(POEQ, "readonly", "GRANT", "AS_IS") print "POEQ dissolved for viewing" #PostProcDissolveLocation = "HPPA" HPPA = outpre + "HPPA" Dissolve_management( owner + "V_HPPA_SDO_V", HPPA, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;HPMS_SURFACE_TYPE;HPMS_SURFACE_TYPE_DESC;HPMS_YEAR_LAST_IMPROV;HPMS_YEAR_LAST_CONST;HPMS_LAST_OVERLAY_THICK;HPMS_THICKNESS_RIGID;HPMS_THICKNESS_FLEXIBLE;HPMS_BASE_TYPE;HPMS_BASE_TYPE_DESC;HPMS_BASE_THICKNESS", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(HPPA, "readonly", "GRANT", "AS_IS") #print "HPPA dissolved for viewing" #PostProcDissolveLocation = "SPED" SPED = outpre + "SPED" Dissolve_management( owner + "V_SPED_SDO_V", SPED, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;SPD_LMT;SPD_LMT_DESC;SPED_RESOL", "#", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(SPED, "readonly", "GRANT", "AS_IS") #print "SPED dissolved for viewing" #PostProcDissolveLocation = "FUN" FUN = outpre + "FUN" Dissolve_management( owner + "V_FUN_SDO_V", FUN, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;FUN_CLASS;FUN_CLASS_DESC;OLD_FUN_CLASS", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(FUN, "readonly", "GRANT", "AS_IS") #print "FUN dissolved for viewing" #PostProcDissolveLocation = "LANE" LANE = outpre + "LANE" Dissolve_management( owner + "V_LANE_SDO_V", LANE, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;LN_ID;LN_ID_DESC;LN_WDTH;LN_WDTH_FT;XSP;XSP_DESCR;HOV;HOV_DESC", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(LANE, "readonly", "GRANT", "AS_IS") #print "LANE dissolved for viewing" #PostProcDissolveLocation = "NHS" NHS = outpre + "NHS" Dissolve_management( owner + "V_NHS_SDO_V", NHS, "LRS_KEY;COUNTY_CD;COUNTY_NAME;DISTRICT;NHS_ID;NHS_ID_DESC", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(NHS, "readonly", "GRANT", "AS_IS") #print "NHS dissolved for viewing" #PostProcDissolveLocation = "SHLD" SHLD = outpre + "SHLD" Dissolve_management( owner + "V_SHLD_SDO_V", SHLD, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;SHLDR_ID;SHLDR_ID_DESC;FORESLOPE;SHLDR_WDTH;SHLDR_WDTH_FT;XSP;XSP_DESCR", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(SHLD, "readonly", "GRANT", "AS_IS") #print "SHLD dissolved for viewing" #PostProcDissolveLocation = "MED" MED = outpre + "MED" MakeFeatureLayer_management( owner + "V_MED_SDO_V", "MED_PRIMARY", "CRND_RTE LIKE '%EB' OR CRND_RTE LIKE '%NB'", "#", "#") Dissolve_management( "MED_PRIMARY", MED, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;MED_ID;MED_ID_DESC;MED_WDTH; MED_WDTH_FT", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(MED, "readonly", "GRANT", "AS_IS") #print "MED dissolved for viewing" #PostProcDissolveLocation = "RMBL" RMBL = outpre + "RMBL" Dissolve_management( owner + "V_RMBL_SDO_V", RMBL, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;RMBL_SHAPE;RMBL_SHAPE_DESC;HOST_PRJCT_ID;PRJCT_ID;RMBL_SOURCE;RMBL_SOURCE_DESC;XSP;XSP_DESCR", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(RMBL, "readonly", "GRANT", "AS_IS") #print "RMBL dissolved for viewing" #PostProcDissolveLocation = "SWID" SWID = outpre + "SWID" Dissolve_management( owner + "V_SWID_SDO_V", SWID, "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;SRFC_WDTH; SRFC_WDTH_FT", "BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", "MULTI_PART", "DISSOLVE_LINES") ChangePrivileges_management(SWID, "readonly", "GRANT", "AS_IS") ##PostProcDissolveLocation = "" STHN = outpre + "STHN" Dissolve_management( owner + "V_STHN_SDO_V", STHN, dissolve_field= "CRND_RTE;LRS_KEY;COUNTY_CD;COUNTY_NAME;LANE_DIRECTION;DISTRICT;DIV_UNDIV;STRAHNET;STRAHNET_DESC", statistics_fields="BCMP MIN;ECMP MAX;BSMP MIN;ESMP MAX", multi_part="MULTI_PART", unsplit_lines="DISSOLVE_LINES") ChangePrivileges_management(STHN, "readonly", "GRANT", "AS_IS") except: endingTime = datetime.datetime.now() #if PostProcDissolveLocation != "": # ScriptStatusLogging('CANP_LRS_EXPORT.py', 'PostProcDissolve failed while attempting to dissolve ' + str(PostProcDissolveLocation), # scriptFailure, startingTime, # endingTime, GetMessages(2)) #elif: #ERROR 000732: path not valid #else: # ScriptStatusLogging('CANP_LRS_EXPORT.py', 'PostProcDissolve Function', # scriptFailure, startingTime, # endingTime, GetMessages(2)) pass
def FIMS_GIS(): #arcpy.MakeFeatureLayer_management(CPMSlyr, 'CPMS', ProjectSelect) MakeFeatureLayer_management(CPMSlyr, 'CPMS') MakeFeatureLayer_management(CountyLyr, 'County') MakeFeatureLayer_management(HPMSlyr, 'HPMS') MakeFeatureLayer_management(MPOLyr, 'MPO') MakeFeatureLayer_management(CONGDistlyr, 'CONG') MakeFeatureLayer_management(ws + "/Polygons", 'Polygons') MakeTableView_management(deltbl, 'DeleteView') MakeTableView_management(newtbl, 'InsertView') #make the polygon analysis layer for Districts, Counties, and MPOs #arcpy.Union_analysis("CONG #;MPO #;County #",ws+"/Polygons","ALL","1 feet","GAPS") # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script # The following inputs are layers or table views: "CPMS", "CPMS.CPMS_STAGING_TMP" MakeTableView_management(FMIS_PROJ, "CPMS_STAGING_TMP") AddJoin_management("CPMS", "PROJECT_ID", "InsertView", "PROJECT_NUMBER", "KEEP_COMMON") Output_Event_Table_Properties = 'RID LINE CNTY_BEG CNTY_END' outtblH = ws + "/FIMS_EventTableLines" if Exists(outtblH): Delete_management(outtblH) print "locating CPMS to HPMS route" LocateFeaturesAlongRoutes_lr('CPMS', 'HPMS', "Route_ID", "0 miles", outtblH, Output_Event_Table_Properties, "FIRST", "DISTANCE", "NO_ZERO", "FIELDS", "M_DIRECTON") #the 30 foot tolerance we allowed here also created a bunch of 30' segments at project intersections. Those should be handled. #...Or the locate tolerance changed to 0 #cleansel = "RID <> CRND_RTE" #is thisnot the right way to handle this, because it will delete the short segments crossing the GIS county boundary? not really #selection statement deleted non-state highway system might be better #MakeTableView_management(outtblH, "cleanup", cleansel) #DeleteRows_management("cleanup") MakeRouteEventLayer_lr("HPMS", "Route_ID", ws + "/FIMS_EventTableLines", "rid LINE CNTY_BEG CNTY_END", "FIMS_EventTableLineLyr", "#", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT") print "Intersection routes to areas" Intersect_analysis("FIMS_EventTableLineLyr #;HPMS #;Polygons #", ws + "/FMIS_Data", "ALL", "#", "LINE") if Exists(ws + "/HPMS_DataD"): Delete_management(ws + "/HPMS_DataD") Dissolve_management( ws + "/FMIS_Data", ws + "/HPMS_DataD", "PROJECT_ID;F_SYSTEM_V;NHS_VN;DISTRICT_1;COUNTY_NUMBER;ID_1", "#", "MULTI_PART", "UNSPLIT_LINES") # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script print "locating processed data to HPMS mileage" if Exists(ws + "/FIMS_EventTable"): Delete_management(ws + "/FIMS_EventTable") LocateFeaturesAlongRoutes_lr(ws + "/HPMS_DataD", "HPMS", "Route_ID", "0 miles", ws + "/FIMS_EventTable", "RID LINE CNTY_BEG CNTY_END", "FIRST", "DISTANCE", "NO_ZERO", "FIELDS", "M_DIRECTON") #MaleTableView(ws+"/FIMS_EventTable", ) Append_management( ws + "/FIMS_EventTable", FMIS_LOAD, "NO_TEST", """ROUTE_ID "ROUTE_ID" true true false 14 Text 0 0 ,First,#,FIMS_EventTable,RID,-1,-1;BEG_CNTY_MP "BEG_CNTY_MP" true true false 8 Double 10 38 ,First,#,FIMS_EventTable,CNTY_BEG,-1,-1;END_CNTY_MP "END_CNTY_MP" true true false 8 Double 10 38 ,First,#,FIMS_EventTable,CNTY_END,-1,-1;CONGRESSIONAL_DISTRICT "CONGRESSIONAL_DISTRICT" true true false 50 Text 0 0 ,First,#,FIMS_EventTable,DISTRICT_1,-1,-1;URBAN_ID "URBAN_ID" true true false 10 Text 0 0 ,First,#,FIMS_EventTable,ID_1,-1,-1;FUN_CLASS "FUN_CLASS" true true false 3 Text 0 0 ,First,#,FIMS_EventTable,F_SYSTEM_V,-1,-1;SYSTEM_CODE "SYSTEM_CODE" true true false 10 Text 0 0 ,First,#,FIMS_EventTable,NHS_VN,-1,-1;PROJECT_NUMBER "PROJECT_NUMBER" true true false 15 Text 0 0 ,First,#,FIMS_EventTable,PROJECT_ID,-1,-1;COUNTY "COUNTY" true true false 3 Text 0 0 ,First,#,FIMS_EventTable,COUNTY_NUMBER,-1,-1""", "#") print "Rows appended to CPMS Load Table CPMS_HPMS_FMIS_DATA"
writeShp(v2_sectors, 'v2_sectors.shp') union_sectors.append('v2_sectors.shp') if len(v1_sectors) == 0: if len(v2_sectors) == 0: writeShp(dealt_obs, 'dealtobs.shp') CopyFeatures_management('cover_shp.shp', 'cover_1_shp.shp') Erase_analysis('cover_1_shp.shp', 'dealtobs.shp', 'cover_shp.shp') print 'end of loop, no sectors' #raw_input() else: Union_analysis(union_sectors, 'sectors.shp') writeShp(dealt_obs, 'dealtobs.shp') Union_analysis(['sectors.shp', 'other_sector.shp'], 'union_2.shp') Dissolve_management('union_2.shp', 'union_2_dissol.shp') Erase_analysis('union_2_dissol.shp', 'dealtobs.shp', 'cover_shp.shp') print "end of loop" #raw_input() else: Union_analysis(union_sectors, 'sectors.shp') writeShp(dealt_obs, 'dealtobs.shp') Union_analysis(['sectors.shp', 'other_sector.shp'], 'union_2.shp') Dissolve_management('union_2.shp', 'union_2_dissol.shp') Erase_analysis('union_2_dissol.shp', 'dealtobs.shp', 'cover_shp.shp') print "end of loop"
def KDOTOverlappingRoutesDissolveFix_OLD(): ######## --- Current Work Area --- ######## ###TODO: IMPORTANT!!!: Reuse and adapt the ramp integration process for the dissolve results re-integration (per dissolve set) ### -- detect duplicates in the original data and only keep one piece per piece in the dissolved set -- may require ### -- additional QC however, as the dissolve set can return more than one feature per LRSKEY and there may need to ### -- be a spatial test involved to make sure that what gets returned covers all of the area that the original ### -- features for a given LRSKEY provided. ### -- Cont'd: Spatial select on attribute selected FC to see which ones can be safely deleted. -- Need to find ### -- which spatial selection method works on segments that are exactly the same as a another segment OR which ### -- segments (for the smaller segment share a start/end point and all other points with a larger segment, but which ### -- will not select smaller segments that share only a start/end point with ### -- Test 'WITHIN' as the spatial selection method -- the dissolve will have to run prior to simplify ### -- or it will need to use the same simplification version -- okay, that should be fine. Just do it post simplify ### -- Except in cases where the geometry is identical except with there possibly being an additional vertex in one... hmm. ### -- Also test 'SHARE_A_LINE_SEGMENT_WITH' -- might work correctly, but not sure. ## Both 'WITHIN' and 'SHARE_A_LINE_SEGMENT_WITH' return 975 for the R route dissolve test data. ## Both 'WITHIN' and 'SHARE_A_LINE_SEGMENT_WITH' return 498 for the M route dissolve test data. ## 'SHARE_A_LINE_SEGMENT_WITH' is probably the safest, because one of the WITHIN types gave me an ## error in the Select By Location window the 3rd or 4th time I clicked through it, but then not ## again later. -- May have just been because I was clicking quickly, but try to: ## Stay away from buggy and buggish settings. ## Because of the ridiculously high number of fields that contain LRS information, you have to do the dissolve ## using all of them, and then compress their information into a smaller chunk and do the dissolve again. ## I.E. Five field min/max dissolve # -///////////////////- Current Work Area -///////////////////- # MakeFeatureLayer_management(routesSourceIntermediate, featureLayer) # Reparse the LRS_KEY_Prefix and use it to select dissolve targets. ParseLRS_ROUTE_PREFIX(featureLayer) #probably shouldn't count on this # existing if it's not passed into this function... use something else. # Do I, U, K, C, R, M, X, L, etc. separately to try to keep dissolve from # messing up and skipping some of the features, but returning 'Success' # as though nothing was wrong. # Then, combine them all back into one feature set. prefixesToDissolve = ['I', 'U', 'K', 'C', 'R', 'X']#, 'L'] # -- Don't try dissolving prefix L until after new unique # keys are genned. undissolvedFeatureLayer = 'undissolvedFeatureLayer' dissolvedFC_gdb = 'in_memory' dissolvedFC_basename = 'dissolvedFC_' dissolveOutputCombined = 'dissolvedOutput' # Have to add MIN_BEG_NODE, MAX_BEG_NODE, MIN_END_NODE, MAX_END_NODE fields to # the output feature class. floatFieldsToAdd = ['MIN_BEG_NODE', 'MAX_BEG_NODE', 'MIN_END_NODE', 'MAX_END_NODE'] CopyFeatures_management(routesSourceCenterlines, routesSourcePreDissolveOutput) MakeFeatureLayer_management(routesSourceCenterlines, stateSystemSelectedFeatures, selectQuery1) #/////////// print("Starting to dissolve the routes source.") stateSystemSelectedFeatures = 'StateSystem_Features' selectQuery1 = '''LRS_ROUTE_PREFIX in ('I', 'U', 'K')''' MakeFeatureLayer_management (routesSourceCenterlines, stateSystemSelectedFeatures, selectQuery1) CopyFeatures_management(stateSystemSelectedFeatures, routesSourcePreDissolveOutput) #GetCount on the features in the layer here. countResult = GetCount_management(stateSystemSelectedFeatures) intCount = int(countResult.getOutput(0)) print('Found ' + str(intCount) + ' state system features to be dissolved.') # Why isn't all of the relevant information already in the KDOT_LRS_KEY? # Why do we need 5 other fields if we're using an intelligent key? # Removed STATE_FLIP_FLAG because we've already flipped the data prior to this process, # as we should given that we want the geometry to dissolve correctly. dissolveFields = "KDOT_LRS_KEY"#"KDOT_DIRECTION_CALC;KDOT_LRS_KEY;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT" statisticsFields = "BEG_NODE MIN;BEG_NODE MAX;END_NODE MAX;END_NODE MIN;SourceFrom MIN;SourceTo MAX" multipart = "SINGLE_PART" unsplitLines = "DISSOLVE_LINES" ## Use a selection for the state system so that it will work the first time. ## Then, later expand the selection and the amount of routes that are attempted for ## the dissolve. Dissolve_management(stateSystemSelectedFeatures, routesSourceDissolveOutput, dissolveFields, statisticsFields, multipart, unsplitLines) print("Completed dissolving the routes source.") #/////////// #Add the cursor process here. undissolvedFeatureLayer = 'undissolvedFeatureLayer' prefixesToDissolve = ['I', 'U', 'K', 'C', 'R', 'X']#, 'L'] # -- Don't try dissolving prefix L until after new unique # keys are genned. dissolvedFC_gdb = 'in_memory' dissolvedFC_basename = 'dissolvedFC_' dissolveOutputCombined = 'dissolvedOutput' selectQuery0 = None for prefixItem in prefixesToDissolve: pass SelectLayerByAttribute_management(undissolvedFeatureLayer, "NEW_SELECTION", selectQuery0) for prefixItem in prefixesToDissolve: # Select by LRS_KEY_Prefix. # Move selection to a separate dataset or perform dissolve with selection. # Might work better to move it to a separate dataset, given the problems with # the feature layer dissolve attempts made earlier in this process, but # that may have been due to the fact that you had attempted at least one # from an in_memory location. # i.e. dissolvedFC_I dissolvedFC_partname = dissolvedFC_basename + prefixItem dissolvedFC_location = os.path.join(dissolvedFC_gdb, dissolvedFC_partname) selectQuery1 = """LRS_KEY_Prefix = '""" + prefixItem + """'""" SelectLayerByAttribute_management(undissolvedFeatureLayer, "NEW_SELECTION", selectQuery1) countResult = GetCount_management(undissolvedFeatureLayer) intCount = int(countResult.getOutput(0)) print("Will dissolve " + str(intCount) + " features in the " + " dissolvedFC_partname " + " feature class.") Dissolve_management(undissolvedFeatureLayer, dissolvedFC_location, dissolveFields, statisticsFields, multipart, unsplitLines) rowsToInsert = list() for prefixItem in prefixesToDissolve: dissolvedFC_partname = dissolvedFC_basename + prefixItem dissolvedFC_location = os.path.join(dissolvedFC_gdb, dissolvedFC_partname) tableFields = ['ORIGINTABLE', 'CHECKTITLE', 'OBJECTID'] newCursor = daSearchCursor(dissolvedFC_location, tableFields) for cursorRow in newCursor: rowsToInsert.append(cursorRow) try: del newCursor except: pass newCursor = daInsertCursor() #cursor out the features # then write them to the output feature class which receives its structure from using the original feature class # as a template. -- Will need to update the fields using data from the original feature class prior to the dissolve # since dissolve destroys information -- not sure how to do that just yet. Maybe select the largest feature which # shares geometry with the dissolved feature...? -- Possibly not necessary since we'll just be using the dissolved # feature to create a route now and not using it for error correction, since we have people editing the # post-conflation base data for that. # Need to not just make a template but also copy everything where the # LRS_KEY_Prefix is not in the list of prefixesToDissolve. def OverlapsMain(): print("Starting to dissolve the routes source.") stateSystemSelectedFeatures = 'StateSystem_Features' selectQuery1 = '''LRS_ROUTE_PREFIX in ('I', 'U', 'K')''' MakeFeatureLayer_management (routesSourceCenterlines, stateSystemSelectedFeatures, selectQuery1) CopyFeatures_management(stateSystemSelectedFeatures, routesSourcePreDissolveOutput) #GetCount on the features in the layer here. countResult = GetCount_management(stateSystemSelectedFeatures) intCount = int(countResult.getOutput(0)) print('Found ' + str(intCount) + ' state system features to be dissolved.') # Removed STATE_FLIP_FLAG because we've already flipped the data prior to this process. dissolveFields = "KDOT_DIRECTION_CALC;KDOT_LRS_KEY;LRS_COUNTY_PRE;LRS_ROUTE_PREFIX;LRS_ROUTE_SUFFIX;LRS_UNIQUE_IDENT" statisticsFields = "BEG_NODE MIN;BEG_NODE MAX;END_NODE MAX;END_NODE MIN;COUNTY_BEGIN_MP MIN;COUNTY_END_MP MAX" multipart = "SINGLE_PART" unsplitLines = "DISSOLVE_LINES" ## Use a selection for the state system so that it will work the first time. ## Then, later expand the selection and the amount of routes that are attempted for ## the dissolve. Dissolve_management(stateSystemSelectedFeatures, routesSourceDissolveOutput, dissolveFields, statisticsFields, multipart, unsplitLines) print("Completed dissolving the routes source.") import os from arcpy import (AddField_management, CalculateField_management, CopyFeatures_management, Dissolve_management, env, FeatureClassToFeatureClass_conversion, FlipLine_edit, GetCount_management, MakeFeatureLayer_management, SelectLayerByAttribute_management) from datareviewerchecks_config import (gdbForSourceCreation, routesSourceCenterlines, routesSourceDissolveOutput) env.workspace = gdbForSourceCreation env.overwriteOutput = True inMemFeatureClassName = 'State_System' inMemFeatureClass = os.path.join('in_memory', inMemFeatureClassName) stateSystemFeatureLayer = 'StateSystemFL' nonStateSystemFeatureLayer = 'NonStateSystemFL' 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") # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script # The following inputs are layers or table views: stateSystemFeatureLayer #review the dissolve output, go back and flag the input data OverlapsMain() StateHighwaySystemDissolve()