def AttribFields(fc, tbl, layer_name, table_name, workspace): #Updates the crossing type attribute values in the GIS database from the CANSYS table. I believe this should work but needs to be tested more. try: MakeFeatureLayer_management(fc, layer_name) MakeQueryTable_management(tbl, table_name, "USE_KEY_FIELDS", "CIIMS.CIIMS_VWCROSSINGGIS3.CROSSINGID", "#", "#") AddJoin_management(layer_name, "CROSSINGID", table_name, "CROSSINGID", "KEEP_ALL") SelectLayerByAttribute_management( layer_name, "NEW_SELECTION", "CIIMS.Static_Crossings.CROSSINGTYPE <> vwcrossings3.CROSSINGTYPE") with da.Editor( workspace) as edit: # @UnusedVariable @UndefinedVariable CalculateField_management(layer_name, 'CIIMS.Static_Crossings.CROSSINGTYPE', '!vwcrossings3.CROSSINGTYPE!', 'PYTHON_9.3') CalculateField_management(layer_name, "CIIMS.Static_Crossings.LOADDATE", "datetime.datetime.now( )", "PYTHON_9.3", "#") del layer_name, fc, table_name, tbl print "attrib fields updated for crossing type" except ExecuteError: print(GetMessages(2)) endingTime = datetime.datetime.now() ScriptStatusLogging('POINT_UPDATE_PROD.py', 'CIIMS.Static_Crossings', scriptFailure, startingTime, endingTime, GetMessages(2))
def preparingSourceCountyData(): print("Starting the preparingSourceCountyData function!") if Exists(preRouteSourceCRML): try: Delete_management(preRouteSourceCRML) except: print("Could not delete the features located at: " + str(preRouteSourceCRML) + ".") else: pass # Make a copy CopyFeatures_management(routesSourceCountyLRSArnold, preRouteSourceCRML) # Remove unnecessary fields preRouteSourceCRMLDescription = Describe(preRouteSourceCRML) preRouteSourceCRMLOIDFieldName = preRouteSourceCRMLDescription.OIDFieldName preRouteSourceCRMLShapeFieldName = preRouteSourceCRMLDescription.shapeFieldName preRouteSourceCRMLShapeAndOIDFieldNames = [ preRouteSourceCRMLOIDFieldName, preRouteSourceCRMLShapeFieldName ] preRouteSourceCRMLFieldObjectsList = ListFields(preRouteSourceCRML) preRouteSourceFieldNames = [ x.name for x in preRouteSourceCRMLFieldObjectsList ] fieldNamesToKeep = [ y for y in preRouteSourceFieldNames if y in preRouteSourceCRMLFields or y in preRouteSourceCRMLShapeAndOIDFieldNames ] fieldNamesToRemove = [ z for z in preRouteSourceFieldNames if z not in fieldNamesToKeep ] for fieldNameItem in fieldNamesToRemove: DeleteField_management(preRouteSourceCRML, fieldNameItem) print("Done deleting unnecessary fields.") MakeFeatureLayer_management(preRouteSourceCRML, fcAsFeatureLayerLG) selectionQueryL1 = """ SourceRouteId IS NULL OR LRS_ROUTE_PREFIX IN ('I', 'U', 'K') """ SelectLayerByAttribute(fcAsFeatureLayerLG, NEW_SELECTION_CONST, selectionQueryL1) CopyFeatures_management(fcAsFeatureLayerLG, stateRoutesAndNullRouteIDs) DeleteRows_management(fcAsFeatureLayerLG) selectionQueryL2 = """ SourceFromMeasure IS NULL OR SourceToMeasure IS NULL """ SelectLayerByAttribute(fcAsFeatureLayerLG, NEW_SELECTION_CONST, selectionQueryL2) CopyFeatures_management(fcAsFeatureLayerLG, preRouteSourceNoMeasures) selectionQueryL3 = """ SourceFromMeasure IS NULL """ SelectLayerByAttribute(fcAsFeatureLayerLG, NEW_SELECTION_CONST, selectionQueryL3) CalculateField_management(fcAsFeatureLayerLG, "SourceFromMeasure", "0", PYTHON_9_3_CONST) selectionQueryL4 = """ SourceToMeasure IS NULL """ SelectLayerByAttribute(fcAsFeatureLayerLG, NEW_SELECTION_CONST, selectionQueryL4) CalculateField_management(fcAsFeatureLayerLG, "SourceToMeasure", "!SHAPE.LENGTH@MILES!", PYTHON_9_3_CONST)
def createSourceRoutes123(): from arcpy import CreateRoutes_lr, FlipLine_edit, AddField_management, FeatureClassToFeatureClass_conversion, SelectLayerByAttribute_management, CalculateField_management from KhubCode25.KhubCode25Config import localProFileGDBWorkspace fileformatDateStr = startDateTime.strftime("%Y%m%d") localfilegdb = localProFileGDBWorkspace + '\\' + 'KhubRoadCenterlines' + fileformatDateStr + '.gdb' FeatureClassToFeatureClass_conversion( localfilegdb + "\\All_Road_Centerlines", "in_memory", "SourceRoadCenterlines123", "LRS_ROUTE_SUFFIX in ( '0' , 'A' , 'B' , 'C' , 'Y' , 'S' ) AND LRS_ROUTE_PREFIX in ( 'I' , 'K' , 'U' )" ) #flip backward routes #selecting by End less than begin mileage: 3/7/2018, 14948 routes need flipped #Selection by State Flip Flag = "Y" 3/7/2018, 14752 routes need flipped #for county_log_end < county_log_begin AND STATE_FLIP_FLAG NOT LIKE 'Y' there are 5 records, all 5 are K-14 on the mitchell/jewell county line #flip flag has become unreliable, do not use, just use mileage relationship AddField_management("SourceRoadCenterlines123", "TmpDblVal", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") SelectLayerByAttribute_management("SourceRoadCenterlines123", "NEW_SELECTION", "county_log_end < county_log_begin") CalculateField_management("SourceRoadCenterlines123", "TmpDblVal", "!county_log_begin!", "PYTHON") CalculateField_management("SourceRoadCenterlines123", "county_log_begin", "!county_log_end!", "PYTHON", "") CalculateField_management("SourceRoadCenterlines123", "county_log_end", "!TmpDblVal!", "PYTHON", "") FlipLine_edit("SourceRoadCenterlines123") #once these lines have been flipped, we will flag them with an F in the state flip flag field CalculateField_management("SourceRoadCenterlines123", "STATE_FLIP_FLAG", "'F'", "PYTHON")
def calibrationCCL_Edit(): print "deriving CCL LRS starting points and calibrations" CCLEnd = "!" + schema + "CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE! - !" + schema + "CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!" CCLBeg = "!" + schema + "CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE! - !" + schema + "CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!" MakeFeatureLayer_management(LineFeatureClass, "CITY_CONNECTING_LINK_RESET") resln = "CITY_CONNECTING_LINK_RESET" AddField_management(resln, "CCL_BEGIN", "DOUBLE", 12, 3) AddField_management(resln, "CCL_END", "DOUBLE", 12, 3) AddJoin_management("CITY_CONNECTING_LINK_RESET", "CCL_LRS", connection1 + "CITY_CONNECTING_LINK_STATE_D", "CCL_LRS", "KEEP_ALL") CalculateField_management(resln, "CCL_BEGIN", CCLBeg, "PYTHON") CalculateField_management(resln, "CCL_END", CCLEnd, "PYTHON") print "calibrating LRS - point calibration method" #statecalpoints = stateroutelyr+"_Point" #print statecalpoints #MakeFeatureLayer_management(statecalpoints, "smlrs_pt") #print connection1+"CITY_CONNECTING_LINK_STATE_D" #MakeFeatureLayer_management(connection1+"CITY_CONNECTING_LINK_STATE_D", "dissolved_res_sects") #intersects = ["dissolved_res_sects", "smlrs_pt"] #Intersect_analysis(intersects,connection0+"\CALIBRATION_POINTS_CCL","ALL","#","POINT") #print connection1+"CALIBRATION_POINTS_CCL" #MakeFeatureLayer_management(connection1+"CALIBRATION_POINTS_CCL", "Calibrators") #querystr = "Substring( CCL_LRS,4, 12)<> LRS_ROUTE" #SelectLayerByAttribute_management("Calibrators","NEW_SELECTION",querystr) #DeleteRows_management("Calibrators") MakeFeatureLayer_management(connection1 + "CITY_CONNECTING_LINK_STATE", "CCL_sections") #DeleteIdentical_management("Calibrators","LRS_KEY;POINT_X;POINT_Y;POINT_M","#","0") AddField_management("CCL_sections", "CCL_BEGIN", "DOUBLE", "#", "#", "#", "#", "NULLABLE", "NON_REQUIRED", "#") AddField_management("CCL_sections", "CCL_END", "DOUBLE", "#", "#", "#", "#", "NULLABLE", "NON_REQUIRED", "#") AddJoin_management("CCL_sections", "CCL_LRS", "dissolved_res_sects", "CCL_LRS", "KEEP_ALL") CalculateField_management( "CCL_sections", schema + "CITY_CONNECTING_LINK_STATE.CCL_BEGIN", "!" + schema + "CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE! - !" + schema + "CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!", "PYTHON", "#") CalculateField_management( "CCL_sections", schema + "CITY_CONNECTING_LINK_STATE.CCL_END", "!" + schema + "CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE! - !" + schema + "CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!", "PYTHON", "#") #AddField_management(connection1+"CALIBRATION_POINTS_CCL","CCL_MEASURE", "DOUBLE", 12, 3) #CalculateField_management("Calibrators","CCL_MEASURE","!POINT_M! - !MIN_BEG_STATE_LOGMILE!","PYTHON","#") CreateRoutes_lr(LineFeatureClass, NewRouteKey, connection1 + NewRoute + "base", "TWO_FIELDS", NewBeg, NewEnd, "UPPER_LEFT", "1", "0", "IGNORE", "INDEX") CalibrateRoutes_lr(connection1 + "CCL_LRS_ROUTEbase", "CCL_LRS", r"D:\workspaces\pythontests.gdb\CCL_Point_Calibrators", "point_LRS", "point_Loc", connection1 + "CCL_LRS_ROUTE", "MEASURES", "10 Feet", "BETWEEN", "NO_BEFORE", "NO_AFTER", "NO_IGNORE", "KEEP", "INDEX") AddField_management(connection1 + NewRoute, "NETWORKDATE", "DATE") CalculateField_management(connection1 + NewRoute, "NETWORKDATE", "datetime.datetime.now( )", "PYTHON_9.3", "#") MakeFeatureLayer_management(connection1 + "CCL_LRS_ROUTE", NewRoute)
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 LatLongFields(fc, tbl, layer_name, table_name, workspace): #Updates the XY attributes values in the GIS database from the CANSYS table try: MakeFeatureLayer_management(fc, layer_name) MakeTableView_management(tbl, table_name) AddJoin_management(layer_name, "CROSSINGID", table_name, "CROSSINGID", "KEEP_ALL") SelectLayerByAttribute_management( layer_name, "NEW_SELECTION", "CIIMS.Static_Crossings.CROSSINGLATITUDE <> CIIMS.CIIMS_VWCROSSINGGIS3.CROSSINGLATITUDE OR CIIMS.Static_Crossings.CROSSINGLONGITUDE <> CIIMS.CIIMS_VWCROSSINGGIS3.CROSSINGLONGITUDE" ) with da.Editor(workspace) as edit: CalculateField_management( layer_name, 'CIIMS.Static_Crossings.CROSSINGLATITUDE', '!CIIMS.CIIMS_VWCROSSINGGIS3.CROSSINGLATITUDE!', 'PYTHON_9.3') CalculateField_management( layer_name, 'CIIMS.Static_Crossings.CROSSINGLONGITUDE', '!CIIMS.CIIMS_VWCROSSINGGIS3.CROSSINGLONGITUDE!', 'PYTHON_9.3') CalculateField_management(layer_name, "CIIMS.Static_Crossings.LOADDATE", "datetime.datetime.now( )", "PYTHON_9.3", "#") del layer_name, fc, table_name, tbl except ExecuteError: print(GetMessages(2))
def copyfromstaged(lyrlist, admin, fdset, fcoutpath): for lyr in lyrlist: print(fcoutpath + admin + '.' + lyr) if Exists(fcoutpath + admin + '.' + lyr): DeleteFeatures_management(fcoutpath + admin + '.' + lyr) Append_management(ws + "/" + tempgdb + '/' + lyr, fcoutpath + admin + '.' + lyr, "NO_TEST", "#") print "updated " + lyr + " in " + fcoutpath else: FeatureClassToFeatureClass_conversion( ws + "/" + tempgdb + '/' + lyr, fcoutpath, lyr) print "copied new " + lyr + " feature class to " + fcoutpath print " Check roles and privleges on this " + lyr + " at " + fcoutpath try: CalculateField_management(fcoutpath + admin + '.' + lyr, "NETWORKDATE", "datetime.datetime.now( )", "PYTHON_9.3", "#") print "copy date field updated" except: AddField_management(fcoutpath + admin + '.' + lyr, "NETWORKDATE", "DATE") CalculateField_management(fcoutpath + admin + '.' + lyr, "NETWORKDATE", "datetime.datetime.now( )", "PYTHON_9.3", "#") print "copy date field added and updated" pass return
def LatLongFields(fc, tbl, layer_name, table_name, workspace): #Updates the XY attributes values in the GIS database from the CANSYS table try: MakeFeatureLayer_management(fc, layer_name) MakeQueryTable_management(tbl, table_name, "USE_KEY_FIELDS", "CIIMS.CIIMS_VWCROSSINGGIS3.CROSSINGID", "#", "#") AddJoin_management(layer_name, "CROSSINGID", table_name, "CROSSINGID", "KEEP_ALL") #select the rows where the CIIMS position has been changed SelectLayerByAttribute_management( layer_name, "NEW_SELECTION", "CIIMS.Static_Crossings.CROSSINGLATITUDE <> vwcrossings3.CROSSINGLATITUDE OR CIIMS.Static_Crossings.CROSSINGLONGITUDE <> vwcrossings3.CROSSINGLONGITUDE" ) with da.Editor( workspace) as edit: # @UnusedVariable @UndefinedVariable CalculateField_management( layer_name, 'CIIMS.Static_Crossings.CROSSINGLATITUDE', '!vwcrossings3.CROSSINGLATITUDE!', 'PYTHON_9.3') CalculateField_management( layer_name, 'CIIMS.Static_Crossings.CROSSINGLONGITUDE', '!vwcrossings3.CROSSINGLONGITUDE!', 'PYTHON_9.3') CalculateField_management(layer_name, "CIIMS.Static_Crossings.LOADDATE", "datetime.datetime.now( )", "PYTHON_9.3", "#") del layer_name, fc, table_name, tbl except ExecuteError: print(GetMessages(2)) endingTime = datetime.datetime.now() ScriptStatusLogging('POINT_UPDATE_PROD.py', 'CIIMS.Static_Crossings', scriptFailure, startingTime, endingTime, GetMessages(2))
def calculateMeasuresForLocalRoutes(routesToMeasure, subsetSelectionQuery): # Make a feature layer # Select it with the subsetSelectionQuery # If the number of selected features is at least 1 # Then, run the calculateField_management calls for # the selected features. fcAsFeatureLayerForMeasuring = 'FCAsFeatureLayer_Measures' if Exists(fcAsFeatureLayerForMeasuring): Delete_management(fcAsFeatureLayerForMeasuring) else: pass MakeFeatureLayer_management(routesToMeasure, fcAsFeatureLayerForMeasuring) SelectLayerByAttribute_management(fcAsFeatureLayerForMeasuring, 'CLEAR_SELECTION') SelectLayerByAttribute_management(fcAsFeatureLayerForMeasuring, 'NEW_SELECTION', subsetSelectionQuery) countResult = GetCount_management(fcAsFeatureLayerForMeasuring) intCount = int(countResult.getOutput(0)) print('There were ' + str(intCount) + ' features selected in the fcAsFeatureLayerForMeasuring layer.') if intCount >= 1: expressionText1 = 0 CalculateField_management(fcAsFeatureLayerForMeasuring, startMeasure, expressionText1, "PYTHON_9.3") expressionText2 = 'float("{0:.3f}".format(!Shape_Length! / 5280.00))' CalculateField_management(fcAsFeatureLayerForMeasuring, endMeasure, expressionText2, "PYTHON_9.3") else: print "Not calculating due to lack of selected features."
def CountyCode(lyr): MakeTableView_management(Kdotdbfp+"\NG911_County", "NG911_County") AddJoin_management(lyr,"COUNTY_L","NG911_County", "CountyName", "KEEP_COMMON") CalculateField_management(lyr,"KDOT_COUNTY_L","!NG911_County.CountyNumber!","PYTHON_9.3","#") RemoveJoin_management(lyr) AddJoin_management(lyr,"COUNTY_R","NG911_County", "CountyName", "KEEP_COMMON") CalculateField_management(lyr,"KDOT_COUNTY_R","!NG911_County.CountyNumber!","PYTHON_9.3","#") RemoveJoin_management(lyr)
def CityCodes(lyr, Kdotdbfp): #Codify the City Limit\city number for LRS , calculated for LEFT and RIGHT from NG911) MakeTableView_management(Kdotdbfp+"\City_Limits", "City_Limits") AddJoin_management(lyr,"MUNI_R","City_Limits", "CITY", "KEEP_COMMON") CalculateField_management(lyr,"KDOT_CITY_R","str(!City_Limits.CITY_CD!).zfill(3)","PYTHON_9.3","#") RemoveJoin_management(lyr) AddJoin_management(lyr,"MUNI_L","City_Limits", "CITY", "KEEP_COMMON") CalculateField_management(lyr,"KDOT_CITY_L","str(!City_Limits.CITY_CD!).zfill(3)","PYTHON_9.3","#") RemoveJoin_management(lyr)
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 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 KDOTKeyCalculation_NewFieldLogic(): MakeFeatureLayer_management(routesSourceCenterlines, fcAsFeatureLayer) # As long as the KDOT_LRS_KEY is not null, calculate from the # current fields. selectionQuery = """ "KDOT_LRS_KEY" IS NOT NULL """ SelectLayerByAttribute_management(fcAsFeatureLayer, "NEW_SELECTION", selectionQuery) # SourceRouteId = KDOT_LRS_KEY CalculateField_management (fcAsFeatureLayer, n1RouteId, "!KDOT_LRS_KEY!", "PYTHON_9.3") # SourceFromMeasure = county_log_begin CalculateField_management (fcAsFeatureLayer, n1FromMeas, "!county_log_begin!", "PYTHON_9.3") # SourceToMeasure = county_log_end CalculateField_management (fcAsFeatureLayer, n1ToMeas, "!county_log_end!", "PYTHON_9.3")
def Calc(): SelectLayerByAttribute_management(in_layer_or_view="NonStateAll", selection_type="NEW_SELECTION", where_clause="1=1") CalculateField_management("NonStateAll", "SHARED.NON_STATE_SYSTEM.LRS_BEG_CNTY_LOGMILE", "[updatetblh.AdjBegin]", "VB", "") CalculateField_management("NonStateAll", "SHARED.NON_STATE_SYSTEM.LRS_END_CNTY_LOGMILE", "[updatetblh.AdjEnd]", "VB", "") print "adjusted begin and end logmiles were recalculated to the source GISPROD database" print "end your edit session"
def RouteCalc(RID): Class = RID[3] if Class in ("R", "M"): Class = "RM" else: pass print RID tablename = Class+RID SelectLayerByAttribute_management("NonStateAll", "NEW_SELECTION", "1=1") CalculateField_management("NonStateAll", "SHARED.NON_STATE_SYSTEM.LRS_BEG_CNTY_LOGMILE", "["+tablename+".NEW_BEGLOG]", "VB", "") CalculateField_management("NonStateAll", "SHARED.NON_STATE_SYSTEM.LRS_END_CNTY_LOGMILE", "["+tablename+".NEW_ENDLOG]", "VB", "") CalculateField_management("NonStateAll", "SHARED.NON_STATE_SYSTEM.LENGTH", "["+tablename+".AdjLength]", "VB", "") print "adjusted begin and end logmiles were recalculated to the source GISPROD database" print "end your edit session"
def CITY (): itemname = "CITY" cantbl = itemname+"_ln_1" domname0 = 'CITY_TYPE' domstate = """IAL_DOMAIN = 'CITY_TYPE' AND IAL_END_DATE is NULL""" domfields = "CT_CITY_NBRR_INCORPORATED_CITY" domtbl = itemname+"_"+domfields disfields = domfields domname = "CT_CITY_NBR" MakeTableView_management("Database Connections/ATLASPROD.odc/V_NM_CTY",domname) TableToTable_conversion(domname, wsouttbl, domname+"R", "#") MakeTableView_management(wsouttbl+"//"+cantbl,itemname+"PD",""""NE_OWNER" IN ( 'EB' , 'NB' )""","#") DissolveRouteEvents_lr(itemname+"PD","LRS_ROUTE LINE Beg_State_Logmile End_State_Logmile", "CITY_NBR", wsouttbl+"//"+itemname+"_SD","LRS_ROUTE LINE Beg_State_Logmile End_State_Logmile","CONCATENATE","INDEX") AddIndex_management(wsouttbl+"//"+itemname+"_SD","CITY_NBR","CITY_NBR","NON_UNIQUE","NON_ASCENDING") AddField_management(wsouttbl+"//"+domname+"R", "CITY_NBR", "FLOAT", "#", "#", "#") CalculateField_management(wsouttbl+"//"+domname+"R", "CITY_NBR", "[CITY_NUMBER]", "VB") MakeTableView_management(wsouttbl+"//"+itemname+"_SD", itemname+"_view", "#") AddJoin_management(itemname+"_view", "CITY_NBR", wsouttbl+"//"+domname+"R", "CITY_NBR", "KEEP_ALL") TableToTable_conversion(itemname+"_view", wsouttbl, itemname+"_EVENT", "#") AssignDomainToField_management(wsouttbl+"//"+itemname+"_EVENT",domfields,domname0) DeleteField_management(wsouttbl+"//"+itemname+"_EVENT","CTYR_OBJECTID;CTYR_IIT_NE_ID;CTYR_IIT_INV_TYPE;CTYR_IIT_PRIMARY_KEY;CTYR_IIT_START_DATE;CTYR_IIT_DATE_CREATED;CTYR_IIT_DATE_MODIFIED;CTYR_IIT_CREATED_BY;CTYR_IIT_MODIFIED_BY;CTYR_IIT_ADMIN_UNIT;CTYR_IIT_NOTE;CTYR_IIT_PEO_INVENT_BY_ID;CTYR_NAU_UNIT_CODE;CTYR_IIT_END_DATE;CTYR_CITY_NBR") MakeRouteEventLayer_lr(wsouttbl+"//SMLRS","LRS_ROUTE",wsouttbl+"//"+itemname+"_EVENT","LRS_ROUTE LINE Beg_State_Logmile End_State_Logmile",itemname+"_ITEM","#","ERROR_FIELD","NO_ANGLE_FIELD","NORMAL","ANGLE","LEFT","POINT") FeatureClassToFeatureClass_conversion(itemname+"_ITEM", wsouttbl, itemname) DeleteField_management(wsouttbl+"//"+itemname,"CTYR_OBJECTID;CTYR_IIT_NE_ID;CTYR_IIT_INV_TYPE;CTYR_IIT_PRIMARY_KEY;CTYR_IIT_START_DATE;CTYR_IIT_DATE_CREATED;CTYR_IIT_DATE_MODIFIED;CTYR_IIT_CREATED_BY;CTYR_IIT_MODIFIED_BY;CTYR_IIT_ADMIN_UNIT;CTYR_IIT_NOTE;CTYR_IIT_PEO_INVENT_BY_ID;CTYR_NAU_UNIT_CODE;CTYR_IIT_END_DATE;CTYR_CITY_NBR") print "we have cities"
def NONSTATE_INT(): print "add intersection points where state routes intersect non-state routes" MakeFeatureLayer_management(nonstate, 'NON_STATE_SYSTEM', "CITYNUMBER IS NOT NULL AND CITYNUMBER<999") MakeFeatureLayer_management(connection1 + NewRoute, NewRoute) Intersect_analysis( "CCL_LRS_ROUTE #;'NON_STATE_SYSTEM' #", connection1 + "Intersect_NONSTATE", "ALL", "5 Feet", "POINT" ) #this doesnt reference the newroute variable, its easier that way MakeFeatureLayer_management(connection1 + "Intersect_NONSTATE", "NSI") LocateFeaturesAlongRoutes_lr("NSI", "CCL_LRS_ROUTE", NewRouteKey, "5 Feet", connection1 + "INTR_CCL_NS", "CCL_LRS POINT MEASURE", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") MakeRouteEventLayer_lr("CCL_LRS_ROUTE", NewRouteKey, connection1 + "INTR_CCL_NS", "CCL_LRS POINT MEASURE", "INTR_CCL_NS Events", "#", "ERROR_FIELD", "ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT") AddField_management("INTR_CCL_NS Events", "CITY", "TEXT", "#", "#", "100") AddJoin_management("INTR_CCL_NS Events", "CITYNUMBER", citylimits, "CITYNUMBER") #CalculateField_management("INTR_CCL_NS Events", schema+"INTR_CCL_NS_Features.CITY", "!GIS_DEV.CITY_LIMITS.CITY!", "PYTHON_9.3") #Preupdate CalculateField_management("INTR_CCL_NS Events", schema + "INTR_CCL_NS_Features.CITY", "!GIS.CITY_LIMITS.CITY!", "PYTHON_9.3") RemoveJoin_management("INTR_CCL_NS Events", "#") print "NonState_Int completed successfully."
def AnnualizeData(YearToAnnualize): annualLayer = gdb + "\KTRIPS.SDE.Ktrips_Annual" currentyYear = gdb + "\KTRIPS.SDE.Ktrips_CurrentYear" SelectYear = YearSelTest CalcYear = str(int(YearSelTest - 1)) YearSelTest = "TripYear = '" + SelectYear + "'" if Exists("Check1"): Delete_management("Check1") MakeFeatureLayer_management(annualLayer, "Check1", YearSelTest) CheckExistence = GetCount_management("Check1") print CheckExistence if int(str(CheckExistence)) > 0: print "This source file info is already in the target feature" runnext = False elif int(str(CheckExistence)) == 0: print 'the information is new for this source file and will be added.' runnext = True Append_management(currentyYear, annualLayer, "NO_TEST", "#") CalculateField_management(annualLayer, "TripYear", CalcYear, "PYTHON_9.3") TruncateTable_management(currentyYear) else: print 'something isnt working here' print runnext pass
def AddInsert(fc, layer_name, newtbl, workspace): MakeTableView_management(newtbl, "NEWROWS_View", "#", "#", "#") addcount = int(GetCount_management("NEWROWS_View").getOutput(0)) if addcount == 0: print "no new records" pass else: MakeFeatureLayer_management(fc, layer_name) MakeXYEventLayer_management( "NEWROWS_View", "CROSSINGLONGITUDE", "CROSSINGLATITUDE", "NEWROWS_Layer", "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],VERTCS['NAVD_1988',VDATUM['North_American_Vertical_Datum_1988'],PARAMETER['Vertical_Shift',0.0],PARAMETER['Direction',1.0],UNIT['Meter',1.0]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;0.001;0.001;IsHighPrecision", "#") FeatureClassToFeatureClass_conversion( "NEWROWS_Layer", "D:/Temp", "LOADTHIS1.shp", "#", """CROSSINGID "CROSSINGID" true false false 30 Text 0 0 ,First,#,Database Connections/sdedev_ciims.sde/CIIMS.NEWROWS_Features,CROSSINGID,-1,-1;CROSSINGLA "CROSSINGLA" true true false 8 Double 10 38 ,First,#,Database Connections/sdedev_ciims.sde/CIIMS.NEWROWS_Features,CROSSINGLATITUDE,-1,-1;CROSSINGLO "CROSSINGLO" true true false 8 Double 10 38 ,First,#,Database Connections/sdedev_ciims.sde/CIIMS.NEWROWS_Features,CROSSINGLONGITUDE,-1,-1;CROSSINGTY "CROSSINGTY" true true false 2 Text 0 0 ,First,#,Database Connections/sdedev_ciims.sde/CIIMS.NEWROWS_Features,CROSSINGTYPE,-1,-1""", "#") Append_management( "D:/Temp/LOADTHIS1.shp", layer_name, "NO_TEST", """CROSSINGID "CROSSINGID" true false false 30 Text 0 0 ,First,#,D:/Temp/LOADTHIS1.shp,CROSSINGID,-1,-1;CROSSINGLATITUDE "CROSSINGLATITUDE" true true false 8 Double 10 38 ,First,#,D:/Temp/LOADTHIS1.shp,CROSSINGLA,-1,-1;CROSSINGLONGITUDE "CROSSINGLONGITUDE" true true false 8 Double 10 38 ,First,#,D:/Temp/LOADTHIS1.shp,CROSSINGLO,-1,-1;CROSSINGTYPE "CROSSINGTYPE" true true false 2 Text 0 0 ,First,#,D:/Temp/LOADTHIS1.shp,CROSSINGTY,-1,-1;LOADDATE "LOADDATE" true true false 36 Date 0 0 ,First,#""", "#") Delete_management("D:/Temp/LOADTHIS1.shp", "#") updatelyr = layer_name + "new" MakeFeatureLayer_management(layer_name, updatelyr, "LOADDATE IS NULL") with da.Editor(workspace) as edit: CalculateField_management(updatelyr, "LOADDATE", "datetime.datetime.now( )", "PYTHON_9.3", "#") del fc, layer_name, newtbl, workspace, updatelyr print "new rows inserted into Static_Crossings"
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 MSAG_CHECK_LRS1(): #Add fields to model the MSAG Street keys and ranges AddField_management("RoadCenterline", "MSAG_KEY", "TEXT", "#", "#", "#", "#", "NULLABLE", "NON_REQUIRED", "#") AddField_management("RoadCenterline", "MSAG_HIGH", "TEXT", "#", "#", "6", "#", "NULLABLE", "NON_REQUIRED", "#") AddField_management("RoadCenterline", "MSAG_LOW", "TEXT", "#", "#", "6", "#", "NULLABLE", "NON_REQUIRED", "#") #these are the rows where the left from address is the lowest valid address range number SelectLayerByAttribute_management( "RoadCenterline", "NEW_SELECTION", "(PARITY_L in ( 'E' , 'O' ) AND L_F_ADD < R_T_ADD AND L_F_ADD < R_F_ADD AND L_F_ADD <= L_T_ADD ) OR (PARITY_R= 'Z' AND PARITY_L in ( 'E' , 'O' ))" ) CalculateField_management("RoadCenterline", "MSAG_LOW", "!L_F_ADD!", "PYTHON_9.3", "#") #these are the rows where the right from address is the lowest valid address range number SelectLayerByAttribute_management( "RoadCenterline", "NEW_SELECTION", "(PARITY_R in ( 'E' , 'O' ) AND R_F_ADD < R_T_ADD AND R_F_ADD < L_F_ADD AND R_F_ADD <= L_T_ADD ) OR (PARITY_L= 'Z' AND PARITY_R in ( 'E' , 'O' ))" ) CalculateField_management("RoadCenterline", "MSAG_LOW", "!R_F_ADD!", "PYTHON_9.3", "#") #these are the rows where the left TO address is the lowest valid address range number SelectLayerByAttribute_management( "RoadCenterline", "NEW_SELECTION", "(PARITY_L in ( 'E' , 'O' ) AND L_T_ADD < L_F_ADD AND L_T_ADD < R_T_ADD AND L_T_ADD <= R_T_ADD ) OR (PARITY_R= 'Z' AND PARITY_L in ( 'E' , 'O' ))" ) CalculateField_management("RoadCenterline", "MSAG_LOW", "!L_F_ADD!", "PYTHON_9.3", "#") #these are the rows where the right TO address is the lowest valid address range number SelectLayerByAttribute_management( "RoadCenterline", "NEW_SELECTION", "(PARITY_R in ( 'E' , 'O' ) AND R_F_ADD < R_T_ADD AND R_F_ADD < L_F_ADD AND R_F_ADD <= L_T_ADD ) OR (PARITY_L= 'Z' AND PARITY_R in ( 'E' , 'O' ))" ) CalculateField_management("RoadCenterline", "MSAG_LOW", "!R_F_ADD!", "PYTHON_9.3", "#")
def modeler(ShapeFileDate): env.workspace = repo filename1 = repo + r"/" + ShapeFileDate SourceFileTxt = str(ShapeFileDate.replace("-", "_")) print "modeling the data schema" if Exists(filename1): Generalize_edit(filename1, "60 Feet") AddIndex_management(filename1, "PRMT_ID", "", "NON_UNIQUE", "NON_ASCENDING") AddField_management(filename1, "SourceFile", "TEXT") AddField_management(filename1, "Tonnage", "Double") AddField_management(filename1, "WidthFt", "Double") AddField_management(filename1, "HeightFt", "Double") AddField_management(filename1, "LengthFt", "Double") MakeTableView_management(filename1, "Ton_Calc", "#", "#", "#") CalculateField_management("Ton_Calc", "SourceFile", "'" + SourceFileTxt + "'", "PYTHON_9.3", "#") CalculateField_management("Ton_Calc", "Tonnage", "40", "PYTHON_9.3", "#") CalculateField_management("Ton_Calc", "LengthFt", "Round([LENGTH] /12,2)", "VB", "#") CalculateField_management("Ton_Calc", "HeightFt", "Round([HEIGHT] /12,2)", "VB", "#") CalculateField_management("Ton_Calc", "WidthFt", "Round([WIDTH] /12,2)", "VB", "#") MakeTableView_management(filename1, "ActualTon_Calc", """"GVW" >80000""", "#", "#") CalculateField_management("ActualTon_Calc", "Tonnage", "!GVW!/2000", "PYTHON_9.3", "#")
def KDOTKeyCalculation_OLD(): # Until the KDOT process is included here, # this defaults to the Transcend process. #FieldPopulation with selections and FieldCalculate: MakeFeatureLayer_management(routesSourceIntermediate, fcAsFeatureLayer) try: RemoveDomainFromField_management(fcAsFeatureLayer, "LRS_ROUTE_PREFIX") except: print("Could not remove the domain from 'LRS_ROUTE_PREFIX'.") print("It may have not existed previously.") pass tempDesc = Describe(fcAsFeatureLayer) print("Calculating values for new LRS and measure fields in " + returnFeatureClass(tempDesc.catalogPath) + ".") try: del tempDesc except: pass # Select LRS_ROUTE_PREFIX IN ('I', 'U', 'K') selectionQuery = """ "LRS_ROUTE_PREFIX" IN ('I', 'U', 'K') """ SelectLayerByAttribute_management(fcAsFeatureLayer, "NEW_SELECTION", selectionQuery) # SourceRouteId = StateKey1 CalculateField_management (fcAsFeatureLayer, n1RouteId, "!StateKey1!", "PYTHON_9.3") # SourceFromMeasure = STATE_BEGIN_MP CalculateField_management (fcAsFeatureLayer, n1FromMeas, "!STATE_BEGIN_MP!", "PYTHON_9.3") # SourceToMeasure = STATE_END_MP CalculateField_management (fcAsFeatureLayer, n1ToMeas, "!STATE_END_MP!", "PYTHON_9.3") # Select LRS_ROUTE_PREFIX NOT IN ('I', 'U', 'K') AND LRSKEY IS NOT NULL selectionQuery = """ "LRS_ROUTE_PREFIX" NOT IN ('I', 'U', 'K') AND "LRSKEY" IS NOT NULL """ SelectLayerByAttribute_management(fcAsFeatureLayer, "NEW_SELECTION", selectionQuery) # SourceRouteId = LRSKEY CalculateField_management (fcAsFeatureLayer, n1RouteId, "!LRSKEY!", "PYTHON_9.3") # SourceFromMeasure = NON_STATE_BEGIN_MP CalculateField_management (fcAsFeatureLayer, n1FromMeas, "!NON_STATE_BEGIN_MP!", "PYTHON_9.3") # SourceToMeasure = NON_STATE_END_MP CalculateField_management (fcAsFeatureLayer, n1ToMeas, "!NON_STATE_END_MP!", "PYTHON_9.3") # Select LRS_ROUTE_PREFIX IN ('C') AND LRSKEY NOT LIKE '%W0' selectionQuery = """ "LRS_ROUTE_PREFIX" IN ('C') AND "LRSKEY" NOT LIKE '%W0' """ SelectLayerByAttribute_management(fcAsFeatureLayer, "NEW_SELECTION", selectionQuery) # SourceRouteID = left([LRSKEY], 11) & "W0" # This is the VB version. # Python version would be calcExpression1 = "!LRSKEY![0:11] + 'W0'" calcExpression1 = 'Left([LRSKEY] ,11 ) & "W0"' CalculateField_management(fcAsFeatureLayer, n1RouteId, calcExpression1, "VB") #interchangeRampsMappings.addFieldMap(fm_Field4) #interchangeRampsMappings.addFieldMap(fm_Field5) print("These are the keys that were found in the repairedRampsKeysList, but not in the routesSourceCenterlinesKeysList.") print("These need to be appended into the routesSourceCenterlines.")
def LaneClass(): MakeFeatureLayer_management(laneclass, 'LNCL', "LANE_DIRECTION in ( 'EB' , 'NB' )") LocateFeaturesAlongRoutes_lr("LNCL", connection1 + "CCL_LRS_ROUTE", NewRouteKey, "0.1 FEET", connection1 + "LANECLASS_CCL", "CCL_LRS LINE CCL_BEGIN CCL_END", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") AddField_management(connection1 + "LANECLASS_CCL", "Lanes", "LONG") MakeTableView_management(laneclass, "LANECLASS_CCL_tbl", "LANE_DIRECTION in ( 'EB' , 'NB' )") CalculateField_management(connection1 + "LANECLASS_CCL", "Lanes", 'Left([LNCL_CLS_ID_DESC],1)', "VB")
def FormatGeocoding(): fcname = "ReferencePosts" fcnameout = "CardinalRefposts" cardfcfull = gdbin + r"/" + fcnameout print cardfcfull from arcpy import AddField_management, CalculateField_management, FeatureClassToFeatureClass_conversion try: FeatureClassToFeatureClass_conversion(gdbin + r"/" + fcname, gdbin, fcnameout, """DIRECTION in (1, 3)""") AddField_management(cardfcfull, "Address", "TEXT", "", "", "55", "", "NULLABLE", "NON_REQUIRED", "") AddField_management(cardfcfull, "CountyNum", "TEXT", "", "", "3", "", "NULLABLE", "NON_REQUIRED", "") except: print "stuff exists" address = """Int([REFPOST]) &" "& [LRS]""" print address countynum = 'Left( [LRS_KEY],3)' CalculateField_management(cardfcfull, "CountyNum", countynum, "VB") CalculateField_management(cardfcfull, "Address", address, "VB")
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 RouteCalc(RID): Class = RID[3] if Class in ("R", "M"): Class = "RM" else: pass print RID RID_ = RID.replace('-', '_') tablename = Class + RID_ SelectLayerByAttribute_management("NonStateUpdate", "NEW_SELECTION", "1=1") CalculateField_management("NonStateUpdate", "SHARED.NON_STATE_SYSTEM.LRS_BEG_CNTY_LOGMILE", "[" + tablename + ".NEW_BEGLOG]", "VB", "") CalculateField_management("NonStateUpdate", "SHARED.NON_STATE_SYSTEM.LRS_END_CNTY_LOGMILE", "[" + tablename + ".NEW_ENDLOG]", "VB", "") CalculateField_management("NonStateUpdate", "SHARED.NON_STATE_SYSTEM.LENGTH", "[" + tablename + ".AdjLength]", "VB", "") print "adjusted begin and end logmiles were recalculated to the source GISPROD database" print "end your edit session" #Delete_management("in_memory/"+tablename) print "RteCalc script completed successfully"
def AttribFields(fc, tbl, layer_name, table_name, workspace): #Updates the crossing type attribute values in the GIS database from the CANSYS table. I believe this should work but needs to be tested more. try: MakeFeatureLayer_management(fc, layer_name) MakeTableView_management(tbl, table_name) AddJoin_management(layer_name, "CROSSINGID", table_name, "CROSSINGID", "KEEP_ALL") SelectLayerByAttribute_management( layer_name, "NEW_SELECTION", "CIIMS.Static_Crossings.CROSSINGTYPE <> CIIMS.CIIMS_VWCROSSINGGIS3.CROSSINGTYPE" ) with da.Editor(workspace) as edit: CalculateField_management( layer_name, 'CIIMS.Static_Crossings.CROSSINGTYPE', '!CIIMS.CIIMS_VWCROSSINGGIS3.CROSSINGTYPE!', 'PYTHON_9.3') CalculateField_management(layer_name, "CIIMS.Static_Crossings.LOADDATE", "datetime.datetime.now( )", "PYTHON_9.3", "#") del layer_name, fc, table_name, tbl print "attrib fields updated for crossing type" except ExecuteError: print(GetMessages(2))
def STATE_INT(): print "add intersect intersection points that are state - state intersections and interchanges" MakeFeatureLayer_management(interchange, 'INTR', "ON_STATE_NONSTATE = 'S'") LocateFeaturesAlongRoutes_lr("INTR", "CCL_LRS_ROUTE", NewRouteKey, "5 Feet", connection1 + "INTR_CCL", "CCL_LRS POINT MEASURE", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") MakeRouteEventLayer_lr("CCL_LRS_ROUTE", NewRouteKey, connection1 + "INTR_CCL", "CCL_LRS POINT MEASURE", "INTR_CCL_Events", "#", "ERROR_FIELD", "ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT") AddField_management("INTR_CCL_Events", "CITY", "TEXT", "#", "#", "100") AddField_management("INTR_CCL_Events", "CITYNUMBER", "Long", "#", "#", "#") CalculateField_management("INTR_CCL_Events", "CITYNUMBER", "int(!CCL_LRS![0:3])", "PYTHON_9.3") AddJoin_management("INTR_CCL_Events", "CITYNUMBER", citylimits, "CITYNUMBER") #CalculateField_management("INTR_CCL_Events", schema+"INTR_CCL_Features.CITY", "!GIS_DEV.CITY_LIMITS.CITY!", "PYTHON_9.3") #Preupdate CalculateField_management("INTR_CCL_Events", schema + "INTR_CCL_Features.CITY", "!GIS.CITY_LIMITS.CITY!", "PYTHON_9.3") RemoveJoin_management("INTR_CCL_Events", "#") print "State_Int completed successfully."