def LRS_Tester(): """makes the LRS route layer and dissolves the NG911 fields to LRS event tables""" # 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: "RoadCenterline" from arcpy import Dissolve_management as dissolve CalcField( lyr, "LRSKEY", "str(!KDOT_COUNTY_R!)+str(!KDOT_COUNTY_L!)+str(!KDOT_CITY_R!)+str(!KDOT_CITY_L!)+str(!PreCode!) + !Soundex! + str(!SuffCode!)+str(!UniqueNo!)+str(!TDirCode!)", "PYTHON_9.3", "#") CalcField( lyr, "RID", "str(!KDOT_COUNTY_R!)+str(!KDOT_COUNTY_L!)+str(!KDOT_CITY_R!)+str(!KDOT_CITY_L!)+str(!PreCode!) + !Soundex! + str(!SuffCode!)+str(!UniqueNo!)+str(!TDirCode!)", "PYTHON_9.3", "#") env.overwriteOutput = 1 dissolve( lyr, gdb + "/NG911/RCLD1", "LRSKEY", "SEGID COUNT;L_F_ADD MIN;L_T_ADD MAX;L_F_ADD RANGE;L_T_ADD RANGE;SHAPE_MILES SUM", "MULTI_PART", "DISSOLVE_LINES") dissolve( lyr, gdb + "/NG911/RCLD2", "LRSKEY", "SEGID COUNT;L_F_ADD MIN;L_T_ADD MAX;L_F_ADD RANGE;L_T_ADD RANGE;SHAPE_MILES SUM", "MULTI_PART", "UNSPLIT_LINES") #MakeRouteLayer_na() pass
def LRS_Tester(): """makes the LRS route layer and dissolves the NG911 fields to LRS event tables""" from arcpy import Dissolve_management as dissolve CalcField( lyr, "LRSKEY", "str(!KDOT_COUNTY_R!)+str(!KDOT_COUNTY_L!)+str(!KDOT_CITY_R!)+str(!KDOT_CITY_L!)+str(!PreCode!) + !Soundex! + str(!SuffCode!)+str(!UniqueNo!)+str(!TDirCode!)", "PYTHON_9.3", "#") CalcField( lyr, "RID", "str(!KDOT_COUNTY_R!)+str(!KDOT_COUNTY_L!)+str(!KDOT_CITY_R!)+str(!KDOT_CITY_L!)+str(!PreCode!) + !Soundex! + str(!SuffCode!)+str(!UniqueNo!)+str(!TDirCode!)", "PYTHON_9.3", "#") env.overwriteOutput = 1 dissolve( lyr, gdb + "/NG911/RCLD1", "LRSKEY", "SEGID COUNT;L_F_ADD MIN;L_T_ADD MAX;L_F_ADD RANGE;L_T_ADD RANGE;SHAPE_MILES SUM", "MULTI_PART", "DISSOLVE_LINES") dissolve( lyr, gdb + "/NG911/RCLD2", "LRSKEY", "SEGID COUNT;L_F_ADD MIN;L_T_ADD MAX;L_F_ADD RANGE;L_T_ADD RANGE;SHAPE_MILES SUM", "MULTI_PART", "UNSPLIT_LINES") #MakeRouteLayer_na() #This whole script started out with a goal of creating an LRS layer for NG911 field event reference, and now is set up to faciliate that #LRS methods may vary depending on use - MSAG Check, KDOT roads, etc... LRS methods will be createdin another script pass
def AliasCalc(): """"calculate the KDOT codes for state highways - the state highways are consistently stored in the Alias Table, and that is used to identify state highways for LRS in Highway Calc function""" CalcField(Alias, "KDOT_PREFIX", "!LABEL![0]", "PYTHON_9.3", "#") SelectLayerByAttribute_management( Alias, "NEW_SELECTION", "LABEL like 'K-%' OR LABEL like 'US-%' OR LABEL like 'I-%' ") CalcField(Alias, "KDOT_ROUTENAME", """!A_RD![1:].replace("S","").zfill(3)""", "PYTHON_9.3", "#") TableView(DOTRoads + r"\KDOT_RoutePre", "KDOT_RoutePre", "#") #this was not firing JoinTbl("RoadAlias", "KDOT_PREFIX", "KDOT_RoutePre", "LRSPrefix", "KEEP_COMMON") SelectLayerByAttribute_management( Alias, "NEW_SELECTION", "LABEL like 'K-%' OR LABEL like 'K %' OR LABEL like 'US-%' OR LABEL like 'US %'OR LABEL like 'I-%' OR LABEL like 'I %' " ) CalcField(Alias, "RoadAlias.KDOT_CODE", "!KDOT_RoutePre.PreCode!", "PYTHON_9.3", "#") CalcField( Alias, "RoadAlias.KDOT_ROUTENAME", expression= "!KDOT_RoutePre.LRSPrefix! + !RoadAlias.LABEL!.split()[1].zfill(3)", expression_type="PYTHON_9.3", code_block="") removeJoin("RoadAlias")
def RoadinName1(): """This module corrects the road names in the soundex code where the road is named like Road A or Road 12 """ TableView(lyr, "ROAD_NAME", "RD LIKE 'ROAD %'") CalcField("ROAD_NAME", "Soundex", """"R"+!RD![5:].zfill(3)""", "PYTHON_9.3", "#") TableView(lyr, "RD_NAME", "RD LIKE 'RD %'") CalcField(lyr, "Soundex", """("R"+!RD![1:5]).zfill(3)""", "PYTHON_9.3", "#")
def AliasCalc(): CalcField(Alias, "KDOT_PREFIX", "!LABEL![0]", "PYTHON_9.3", "#") CalcField(Alias, "KDOT_ROUTENAME", """!A_RD![1:].replace("S","").zfill(3)""", "PYTHON_9.3", "#") TableView(DOTRoads + "\KDOT_RoutePre", "KDOT_RoutePre") JoinTbl("RoadAlias", "KDOT_PREFIX", "KDOT_RoutePre", "LRSPrefix", "KEEP_COMMON") CalcField("RoadAlias", "RoadAlias.KDOT_CODE", "!KDOT_RoutePre.PreCode!", "PYTHON_9.3", "#") removeJoin("RoadAlias")
def CountyCode(): """Codify the County number for LRS (based on right side of street based on addressing direction, calculated for LEFT and RIGHT from NG911)""" TableView(DOTRoads + "\NG911_County", "NG911_County") JoinTbl(lyr, "COUNTY_L", "NG911_County", "CountyName", "KEEP_COMMON") CalcField(lyr, "KDOT_COUNTY_L", "!NG911_County.CountyNumber!", "PYTHON_9.3", "#") removeJoin(lyr) JoinTbl(lyr, "COUNTY_R", "NG911_County", "CountyName", "KEEP_COMMON") CalcField(lyr, "KDOT_COUNTY_R", "!NG911_County.CountyNumber!", "PYTHON_9.3", "#") removeJoin(lyr)
def CityCodes(): """Codify the City Limit\city number for LRS , calculated for LEFT and RIGHT from NG911)""" TableView(DOTRoads + "\City_Limits", "City_Limits") JoinTbl(lyr, "MUNI_R", "City_Limits", "CITY", "KEEP_COMMON") CalcField(lyr, "KDOT_CITY_R", "str(!City_Limits.CITY_CD!).zfill(3)", "PYTHON_9.3", "#") removeJoin(lyr) JoinTbl(lyr, "MUNI_L", "City_Limits", "CITY", "KEEP_COMMON") CalcField(lyr, "KDOT_CITY_L", "str(!City_Limits.CITY_CD!).zfill(3)", "PYTHON_9.3", "#") removeJoin(lyr) TableView(lyr, "CityRoads", "KDOT_CITY_R = KDOT_CITY_L AND KDOT_CITY_R not like '999'") CalcField("CityRoads", "KDOT_ADMO", "'W'", "PYTHON_9.3", "#")
def HighwayCalc(lyr, gdb): #Pull out State Highways to preserve KDOT LRS Key (CANSYS FORMAT - non directional CRAD) MakeTableView_management(gdb+"\RoadAlias", "RoadAlias") from arcpy import CalculateField_management as CalcField from arcpy import MakeTableView_management as TableView, SelectLayerByAttribute_management as Select from arcpy import AddJoin_management as JoinTbl, RemoveJoin_management as removeJoin Select(lyr,"NEW_SELECTION","ROUTE_ID LIKE '%X0'") CalcField(in_table="RoadCenterline",field="KDOT_ADMO",expression="'X'",expression_type="PYTHON_9.3",code_block="#") TableView(Kdotdbfp+"\RoadAlias", "RoadAlias") JoinTbl(lyr,"SEGID","RoadAlias", "SEGID") Select(lyr, "NEW_SELECTION", "RoadAlias.LABEL LIKE 'US %' OR RoadAlias.LABEL LIKE 'I %' OR RoadAlias.LABEL LIKE 'K %'" ) removeJoin(lyr) CalcField(lyr,"RID","!ROUTE_ID![:11]","PYTHON_9.3","#") Select(lyr, "REMOVE_FROM_SELECTION", "TRAVEL is null" ) CalcField(lyr,"RID","!ROUTE_ID![:11]+!TRAVEL!","PYTHON_9.3","#")
def RouteCalc(): """calculate what should be a nearly unique LRS Route key based on the decoding and street name soundex/numdex function""" # Trying to make the CalcField call unnecessary as RoadinName includes the functionality # of numdex. # Instead of calling numdex here, rewrite and incorporate numdex and soundex functionality into the RoadinName function. #CalcField(lyr,"Soundex","numdex(!RD!)","PYTHON_9.3","#") RoadinName(lyr, soundexNameExclusions) CalcField( lyr, "RID", "str(!KDOT_COUNTY_R!)+str(!KDOT_COUNTY_L!)+str(!KDOT_CITY_R!)+str(!KDOT_CITY_L!)+str(!PreCode!) + !Soundex! + str(!SuffCode!)+str(!UniqueNo!)+str(!TDirCode!)", "PYTHON_9.3", "#")
def ScratchCalcs(): CalcField( "RoadCenterline", "RoadCenterline.Soundex", """!RoadAlias.A_RD![0] + !RoadAlias.A_RD![1:].replace("S","").zfill(3)""", "PYTHON_9.3", "#") CalcField(in_table="RoadCenterline", field="RoadCenterline.KDOTPreType", expression="!RoadAlias.A_RD![0] ", expression_type="PYTHON_9.3", code_block="#") CalcField(in_table="RoadCenterline", field="RoadCenterline.PreCode", expression="'0'", expression_type="PYTHON_9.3", code_block="#") CalcField(in_table="RoadCenterline", field="RoadCenterline.KDOT_ADMO", expression="'S'", expression_type="PYTHON_9.3", code_block="#")
def HighwayCalc(): """Pull out State Highways to preserve KDOT LRS Key (CANSYS FORMAT - non directional CRAD) for the KDOT primary route""" if Exists(gdb + "\RoadAlias_Sort"): Delete(gdb + "\RoadAlias_Sort") else: pass Sort_management(Alias, gdb + "\RoadAlias_Sort", "KDOT_CODE ASCENDING;KDOT_ROUTENAME ASCENDING", "UR") #Remember to check the primary route heirarchy calculates correctly where US rides US and I rides I Heriarchy = ["K", "U", "I"] for routeClass in Heriarchy: rideselect = "KDOT_PREFIX LIKE '" + routeClass + "%'" print rideselect, routeClass TableView(gdb + "\RoadAlias_Sort", "RoadAlias_Sort", rideselect) JoinTbl(lyr, "SEGID", "RoadAlias_Sort", "SEGID", "KEEP_COMMON") CalcField(lyr, lyr + ".KDOTPreType", "!RoadAlias_Sort.KDOT_PREFIX!", "PYTHON_9.3", "#") CalcField( lyr, lyr + ".Soundex", "!RoadAlias_Sort.KDOT_PREFIX!+!RoadAlias_Sort.KDOT_ROUTENAME!", "PYTHON_9.3", "#") CalcField(lyr, "KDOT_ADMO", "'S'", "PYTHON_9.3", "#") CalcField(lyr, "PreCode", "0", "PYTHON_9.3", "#") removeJoin(lyr) CalcField( lyr, "RID", "str(!KDOT_COUNTY_R!)+str(!KDOT_COUNTY_L!)+str(!KDOT_CITY_R!)+str(!KDOT_CITY_L!)+str(!PreCode!) + !Soundex! + str(!SuffCode!)+str(!UniqueNo!)+str(!TDirCode!)", "PYTHON_9.3", "#") CalcField(lyr, "LRSKEY", "str(!RID!)", "PYTHON_9.3", "#")
def CalcAdminFields(lyr, Kdotdbfp): from arcpy import CalculateField_management as CalcField from arcpy import MakeTableView_management as TableView from arcpy import AddJoin_management as JoinTbl, RemoveJoin_management as removeJoin CalcField(lyr,"UniqueNo",'000',"PYTHON_9.3","#") CalcField(lyr,"KDOT_START_DATE","1/1/1901","PYTHON_9.3","#") CalcField(lyr,"KDOTPreType","!ROUTE_ID![3]","PYTHON_9.3","#") TableView(lyr, "NewLocal", "KDOT_ADMO is null") CalcField("NewLocal","KDOT_ADMO","'L'","PYTHON_9.3","#") CalcField(lyr,"PreCode","0","PYTHON_9.3","#") CalcField(lyr,"KDOT_CITY_L","999","PYTHON_9.3","#") CalcField(lyr,"KDOT_CITY_R","999","PYTHON_9.3","#") TableView(Kdotdbfp+"\\NG911_RdDir", "NG911_RdDir") CalcField(lyr,"PreCode","0","PYTHON_9.3","#") JoinTbl(lyr,"PRD","NG911_RdDir", "RoadDir", "KEEP_COMMON") CalcField(lyr,"PreCode","!NG911_RdDir.RdDirCode!","PYTHON_9.3","#") removeJoin(lyr) TableView(Kdotdbfp+"\NG911_RdTypes", "NG911_RdTypes") CalcField(lyr,"SuffCode","0","PYTHON_9.3","#") JoinTbl(lyr,"STS","NG911_RdTypes", "RoadTypes", "KEEP_COMMON") CalcField(lyr,"SuffCode","!NG911_RdTypes.LRS_CODE_TXT!","PYTHON_9.3","#") removeJoin(lyr)
def CalcAdminFields(): """Populate Admin Fields with Default or Derived values""" CalcField(lyr, "UniqueNo", '000', "PYTHON_9.3", "#") CalcField(lyr, "KDOT_START_DATE", "1/1/1901", "PYTHON_9.3", "#") CalcField( lyr, "KDOTPreType", "!ROUTE_ID![3]", "PYTHON_9.3", "#" ) #PreType is a conflated field, consider changing this to calculate from NENA fields TableView(lyr, "NewPretype", "KDOTPreType is Null") CalcField("NewPretype", "KDOTPreType", "'L'", "PYTHON_9.3", "#") CalcField(lyr, "KDOT_ADMO", "'X'", "PYTHON_9.3", "#") CalcField(lyr, "PreCode", "0", "PYTHON_9.3", "#") CalcField(lyr, "KDOT_CITY_L", "999", "PYTHON_9.3", "#") CalcField(lyr, "KDOT_CITY_R", "999", "PYTHON_9.3", "#") CalcField(lyr, "TDirCode", "0", "PYTHON_9.3", "#") CalcField(lyr, "SHAPE_MILES", "!Shape_Length!/5280.010560021", "PYTHON_9.3", "#") #There are slightly more than 5280 miles per US Survey foot TableView(DOTRoads + "\\NG911_RdDir", "NG911_RdDir") JoinTbl(lyr, "PRD", "NG911_RdDir", "RoadDir", "KEEP_COMMON") CalcField(lyr, "PreCode", "!NG911_RdDir.RdDirCode!", "PYTHON_9.3", "#") removeJoin(lyr) TableView(DOTRoads + "\NG911_RdTypes", "NG911_RdTypes") CalcField(lyr, "SuffCode", "0", "PYTHON_9.3", "#") JoinTbl(lyr, "STS", "NG911_RdTypes", "RoadTypes", "KEEP_COMMON") CalcField(lyr, "SuffCode", "!NG911_RdTypes.LRS_CODE_TXT!", "PYTHON_9.3", "#") removeJoin(lyr)