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 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 writeStewardPointCounts(): MakeFeatureLayer_management(originalPointsSource, originalPointsAsLayer) MakeFeatureLayer_management(simplifiedPointsSource, simplifiedPointsAsLayer) allStewardsDict = dict() #Programatically grab the stewards instead of manually listing them here newCursor = daSearchCursor(originalPointsAsLayer, ["OID@", "STEWARD"]) for cursorItem in newCursor: allStewardsDict[cursorItem[1]] = 'True' if 'newCursor' in locals(): try: del newCursor except: print("The cursor exists, but it could not be successfully removed.") else: print("The cursor has already been removed.") try: wHandle = open(outputFile,'w') columnNames = "StewardID , OriginalCount , SimplifiedCount\n" wHandle.write(columnNames) # For each steward in the list, get a count of all of the original centerline # points and the the simplified road centerlines points. # Next, write the data out to a text file in comma separated form. for stewardItem in allStewardsDict.keys(): if stewardItem is not None: selectionQuery = """ "STEWARD" = '""" + stewardItem + """' """ SelectLayerByAttribute_management(originalPointsAsLayer, selectionTypeToUse, selectionQuery) oCountResult = GetCount_management(originalPointsAsLayer) originalCount = int(oCountResult.getOutput(0)) SelectLayerByAttribute_management(simplifiedPointsAsLayer, selectionTypeToUse, selectionQuery) sCountResult = GetCount_management(simplifiedPointsAsLayer) simplifiedCount = int(sCountResult.getOutput(0)) strToWrite = "'" + stewardItem + "'" + ", " + str(originalCount) + ", " + str(simplifiedCount) + "\n" print("Writing " + strToWrite + " to the file: " + outputFile + ".") wHandle.write(strToWrite) else: print("The stewardItem is None, so it will be skipped.") except: errorInfo = sys.exc_info()[0] errorInfo1 = sys.exc_info()[1] print("An error occurred: " + str(errorInfo) + str(errorInfo1)) try: wHandle.close() except: raise try: del errorInfo del errorInfo1 except: pass
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 KDOTKeyCalculation_Modified(): # Until the KDOT process is included here, # this defaults to the Transcend process. #FieldPopulation with selections and FieldCalculate: MakeFeatureLayer_management(routesSourceCenterlines, featureLayer) tempDesc = Describe(featureLayer) 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(featureLayer, "NEW_SELECTION", selectionQuery) # SourceRouteId = StateKey1 CalculateField_management(featureLayer, "SourceRouteId", "!StateKey1!", "PYTHON_9.3") # SourceFromMeasure = STATE_BEGIN_MP CalculateField_management(featureLayer, "SourceFromMeasure", "!STATE_BEGIN_MP!", "PYTHON_9.3") # SourceToMeasure = STATE_END_MP CalculateField_management(featureLayer, "SourceToMeasure", "!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(featureLayer, "NEW_SELECTION", selectionQuery) # SourceRouteId = LRSKEY CalculateField_management(featureLayer, "SourceRouteId", "!LRSKEY!", "PYTHON_9.3") # SourceFromMeasure = NON_STATE_BEGIN_MP CalculateField_management(featureLayer, "SourceFromMeasure", "!NON_STATE_BEGIN_MP!", "PYTHON_9.3") # SourceToMeasure = NON_STATE_END_MP CalculateField_management(featureLayer, "SourceToMeasure", "!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(featureLayer, "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(featureLayer, "SourceRouteID", calcExpression1, "VB")
def CrashOffsetPoints(gdb): #buffer and intersect the crash location to an offset distance, and select the points that hit the "on Road" from arcpy import SelectLayerByAttribute_management, AddJoin_management, Intersect_analysis, Buffer_analysis Buffer_analysis( in_features="Geocoding Result: Geocoding_Result_9", out_feature_class= "//gisdata/arcgis/GISdata/Accident Geocode/GC_OFFSET_20150210.gdb/Geocoding_Result_9_Buffer", buffer_distance_or_field="AT_ROAD_KDOT_DIST_FEET", line_side="FULL", line_end_type="ROUND", dissolve_option="NONE", dissolve_field="", method="PLANAR") AddJoin_management(in_layer_or_view="RoadCenterline", in_field="SEGID", join_table="RoadAlias", join_field="RoadAlias.SEGID", join_type="KEEP_ALL") Intersect_analysis( in_features="Geocoding_Result_9_Buffer #;RoadCenterline #", out_feature_class= "//gisdata/arcgis/GISdata/Accident Geocode/GC_OFFSET_20150210.gdb/Geocoding_Result_9_Buffer_In", join_attributes="ALL", cluster_tolerance="-1 Unknown", output_type="POINT") SelectLayerByAttribute_management( in_layer_or_view="Geocoding_Result_9_Buffer_In", selection_type="NEW_SELECTION", where_clause= "ON_ROAD_KDOT_NAME like RoadAlias_KDOT_ROUTENAME OR ON_ROAD_KDOT_NAME like RoadCenterline_RD" )
def OffsetDirectionMatrix(gdb): #select the intersected coordinate that best describes the reported location of the on road from the intersection based on the CrashOffsetPoints function from arcpy import AddXY_management, AddJoin_management, ListFields, da, SelectLayerByAttribute_management, AddFieldDelimiters GeocodedLayer = 'Geocoding Result: Geocoding_Result_9' IntersectLayer = 'Geocoding_Result_9_Buffer_In' AddXY_management(IntersectLayer) AddJoin_management(IntersectLayer, "ACCIDENT_KEY", GeocodedLayer, "ACCIDENT_KEY") FieldsList = ListFields(IntersectLayer) CursorFieldList = [ 'X', 'Y', 'AT_ROAD_KDOT_DIRECTION', 'POINT_X', 'POINT_Y', 'OBJECTID', 'ACCIDENT_KEY' ] # cursor to add to list the Accident IDs and Object IDs CoordFinder = da.SearchCursor(IntersectLayer, CursorFieldList) # @UndefinedVariable coordlist = [] rowDictionary = dict() for row in CoordFinder: print #print('{0}, {1}, {2}, {3}, {4}'.format(row[0], row[1], row[2], row[3], row[4])) if str(row[2]) == "E": print row[0] EastCoord = max(row[0], row[3]) coordlist.append(EastCoord) rowDictionary print coordlist FinalEastCoordinate = max(coordlist) FinalEastCoordInt = int(FinalEastCoordinate) print FinalEastCoordinate CoordSelExpression = 'POINT_X -' + str(FinalEastCoordInt) + " < 1" SelectLayerByAttribute_management(IntersectLayer, "NEW_SELECTION", CoordSelExpression)
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 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 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 ProjDelete( ): #delete rows from the FMIS load table that are about to be processed delcount = GetCount_management( r'Database Connections\CANT_CPMS.sde\CPMS.CPMS_FMIS_GIS_DEL_ROWS') print str(delcount) + " records to delete" deletelist = list() if delcount == 0: print "no records to delete, ending" pass else: MakeTableView_management(FMIS_LOAD, "FMIS_TABLE") MakeTableView_management(deltbl, "deletes") with da.SearchCursor(deltbl, "PROJECT_NUMBER") as delcur: # @UndefinedVariable for row in delcur: DelXID = ("{0}".format(row[0])) #print DelXID + " is being deleted from the FMIS table" #AddJoin_management(layer_name,"CROSSINGID", deltbl, "CROSSINGID", "KEEP_ALL") #delsel = "PROJECT_NUMBER LIKE '"+DelXID+"'" #print delsel deletelist.append(DelXID) #SelectLayerByAttribute_management("FMIS_TABLE","ADD_TO_SELECTION", delsel) #print str(deletelist) delsel = "PROJECT_NUMBER IN " + str(deletelist) #for ProjectNumber in deletelist: print delsel SelectLayerByAttribute_management("FMIS_TABLE", "NEW_SELECTION", delsel) #DeleteRows_management("FMIS_TABLE") print "Delete function completed"
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 Custom_Erase(inFeature1, inFeature2, outFeature): # Instead of erase, might try a union, then selection for only the features # that do not have their centers within the 2nd feature class, # or that are not entirely within the 2nd feature class, # then output the selected features. # MakeFeatureLayer, Union, SelectByLocation, CopyFeatures. tempUnionFeatureClass = r'in_memory\UnionTemp' unionList = list() unionList.append(inFeature1) unionList.append(inFeature2) Union_analysis(unionList, tempUnionFeatureClass, "ALL") tempUnionLayer = MakeFeatureLayer_management(tempUnionFeatureClass, "UnionLayer") tempFeature2 = MakeFeatureLayer_management(inFeature2, "Feature2") SelectLayerByLocation_management(tempUnionLayer, "HAVE_THEIR_CENTER_IN", tempFeature2) SelectLayerByLocation_management(tempUnionLayer, "WITHIN", tempFeature2, "0 Feet", "ADD_TO_SELECTION") CopyFeatures_management( tempUnionLayer, r'\\gisdata\ArcGIS\GISdata\GDB\CCL_Scratch_Boundary.gdb\TempUnionSelection' ) SelectLayerByAttribute_management(tempUnionLayer, "SWITCH_SELECTION") CopyFeatures_management( tempUnionLayer, r'\\gisdata\ArcGIS\GISdata\GDB\CCL_Scratch_Boundary.gdb\TempUnionSelectionSwitch' ) CopyFeatures_management(tempUnionLayer, outFeature)
def DeleteDeletedRows(FMIS_DEL, FMIS_LOAD): #delete rows from the FMIS table programmed to be deleted according to the CPMS view MakeTableView_management(FMIS_DEL, "RowstoDelete") MakeTableView_management(FMIS_LOAD, "DeleteThese") delcount = GetCount(FMIS_DEL) #delete rows from SDE CIIMS that are removed from CANSYS CIIMS #search cursor to match the crossing ID in the delete view SetLogHistory(False) DeleteList = [] with da.SearchCursor("RowstoDelete", "PROJECT_NUMBER") as delcur: # @UndefinedVariable for row in delcur: DelXID = ("{0}".format(row[0])) DeleteList.append(DelXID) print "list completed" for record in DeleteList: #print DelXID + " is being deleted from the FMIS table" #add the the crossing ID for the row to be deleted to a selection set delsel = "PROJECT_NUMBER LIKE '%s'" % record #print delsel SelectLayerByAttribute_management("DeleteThese", "ADD_TO_SELECTION", delsel) #delete the selected rows DeleteRows_management("DeleteThese") del FMIS_DEL, FMIS_LOAD, delsel print "Delete function completed"
def DirectionalUrbanClass(): #do the same as for State Sys but for Non State Urban Classified Highways (Nusys) FeatureVerticesToPoints_management("RoadCenterlinesC", "in_memory/UrbanPoints", "MID") FeatureClassToFeatureClass_conversion( NSND, "in_memory", "NSND_NPD", where_clause="NETWORK_DIRECTION IN ( 'SB' , 'WB' )") LocateFeaturesAlongRoutes_lr("UrbanPoints", "NSND_NPD", "NE_UNIQUE", "200 Feet", "in_memory/UrbanPointsMeasures", "RID POINT MEAS", "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON") Delete_management("UrbanPoints") #is the query stil valid for non state system? Explore hte NE Unique. State System did not use the county number prefix SelectLayerByAttribute_management( "UrbanPointsMeasures", "NEW_SELECTION", """SUBSTRING( "RID", 4, 7) NOT LIKE SUBSTRING("NON_State_System_LRSKey" ,4, 7)""" ) DeleteRows_management(in_rows="UrbanPointsMeasures") MakeRouteEventLayer_lr("NSND_NPD", "NE_UNIQUE", "UrbanPointsMeasures", "rid POINT MEAS", "UrbanPointEvents", offset_field="Distance", add_error_field="ERROR_FIELD", add_angle_field="ANGLE_FIELD", angle_type="NORMAL", complement_angle="ANGLE", offset_direction="RIGHT", point_event_type="POINT") MakeFeatureLayer_management("UrbanPointEvents", "UNPD_ID", """"Distance">=0""") SelectLayerByLocation_management("UNPD_ID", "INTERSECT", "RoadCenterlinesC", "1 Feet", "NEW_SELECTION") #at this point, there are a lot of false positives, places with single carriagway roads and nusys divided #we need to incorporate the check overlap process to identify where their are single and dual carriagways here #starting with the technique to find sausages or dual carraigeways #SpatialJoin_analysis("UNPD_ID", "RoadCenterlinesC", "in_memory/ValidateSausages120", "JOIN_ONE_TO_ONE", "KEEP_ALL", '#', "INTERSECT", "120 Feet", "Distance") #this Spatial Join step is improving the results, removing most false positives. It still shows overlapping segments #it would be improved even more, potentially, by testing the non-primary direction against dissolve somehow. #except, the calculate method is by segment to the source, a dissolve would complicate the process of calculating back to the source data #we are looking for count grater than 0 of the offset point to hte segment, so a dissolved segment should work import EliminateOverlaps from EliminateOverlaps import CollectorDissolve #set the roadcenterline input and dissolve output for RoadCenterline dissolve for this subroutine roadcenterlines = "RoadCenterlinesC" ClassOutput = r"in_memory/RMC2" CollectorDissolve() SpatialJoin_analysis("UNPD_ID", "RMC2dissolve", "in_memory/ValidateSausages120", "JOIN_ONE_TO_ONE", "KEEP_ALL", '#', "INTERSECT", "120 Feet", "Distance")
def __next__(self): try: next_FID = next(self.OIDs)[0] except StopIteration: self.OIDs = SearchCursor(self.filepath, "OID@") raise StopIteration next_filepath = f"{self.filepath}_FID={next_FID}" MakeFeatureLayer_management(self.filepath, next_filepath) SelectLayerByAttribute_management(next_filepath, "NEW_SELECTION", f"FID={next_FID}") return ArcShpObject(next_filepath, id(next_filepath), self.domain)
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 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 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 PointDelete( fc, layer_name, tbl, table_name ): #delete rows from SDE CIIMS that are removed from CANSYS CIIMS 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.CIIMS_VWCROSSINGGIS3.CROSSINGID IS NULL") DeleteRows_management("Static_Crossings") del fc, layer_name, tbl, table_name print "Delete function completed"
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 checkFeatureLocations(gdb): userMessage("Checking feature locations...") from os import path from arcpy import MakeFeatureLayer_management, SelectLayerByAttribute_management, SelectLayerByLocation_management, GetCount_management, Delete_management, da values = [] #make sure feature are all inside authoritative boundary #get authoritative boundary authBound = path.join(gdb, "NG911", "AuthoritativeBoundary") ab = "ab" MakeFeatureLayer_management(authBound, ab) for dirpath, dirnames, filenames in da.Walk(gdb, True, '', False, ["FeatureClass"]): for filename in filenames: if filename != "AuthoritativeBoundary": #get full path name & create a feature layer fullPath = path.join(gdb, filename) fl = "fl" MakeFeatureLayer_management(fullPath, fl) #select by location to get count of features outside the authoritative boundary SelectLayerByLocation_management(fl, "INTERSECT", ab) SelectLayerByAttribute_management(fl, "SWITCH_SELECTION", "") #get count of selected records result = GetCount_management(fl) count = int(result.getOutput(0)) #report results if count > 0: fields = ("OBJECTID") with da.SearchCursor(fl, fields) as rows: for row in rows: val = (today, "Feature not inside authoritative boundary", filename, "", row[0]) values.append(val) else: userMessage(filename + ": all records inside authoritative boundary") #clean up Delete_management(fl) userMessage("Completed check on feature locations") if values != []: RecordResults("fieldValues", values, gdb)
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 PointDelete( fc, layer_name, deltbl, table_name ): #delete rows from SDE CIIMS that are removed from CANSYS CIIMS MakeFeatureLayer_management(fc, layer_name) MakeTableView_management(deltbl, table_name) with da.SearchCursor(deltbl, "CROSSINGID") as delcur: for row in delcur: DelXID = ("{0}".format(row[0])) print DelXID + " is being deleted from the CIIMS table" #AddJoin_management(layer_name,"CROSSINGID", deltbl, "CROSSINGID", "KEEP_ALL") delsel = "CROSSINGID LIKE '" + str(row)[3:10] + "'" SelectLayerByAttribute_management(layer_name, "ADD_TO_SELECTION", delsel) DeleteRows_management(layer_name) del fc, layer_name, deltbl, table_name print "Delete function completed"
def delForTesting(): env.workspace = repo whereClause = "ObjectID = 91783" enterprisedbRoutes = gdb + "\INTERMODAL.DBO.KTRIPS_ROUTES" loadedRoutesLayer = 'routesAsLyr' MakeFeatureLayer_management(enterprisedbRoutes, loadedRoutesLayer, "#", "#") SelectLayerByAttribute_management(loadedRoutesLayer, "NEW_SELECTION", whereClause) currentCount = GetCount_management(loadedRoutesLayer) print "Selected " + str(currentCount) + " rows to delete." # Probably have to disconnect users before the next part will work. =( if int(str(currentCount)) > 0: print 'Deleting selected rows...' DeleteFeatures_management(loadedRoutesLayer) else: print 'Will not delete as there are no rows selected.'
def PointDelete(fc, layer_name, deltbl, table_name): #delete rows from SDE CIIMS that are removed from CANSYS CIIMS MakeFeatureLayer_management(fc, layer_name) MakeTableView_management(deltbl, table_name) #search cursor to match the crossing ID in the delete view with da.SearchCursor(deltbl, "CROSSINGID") as delcur: # @UndefinedVariable for row in delcur: DelXID = ("{0}".format(row[0])) print DelXID + " is being deleted from the CIIMS table" #add the the crossing ID for the row to be deleted to a selection set delsel = "CROSSINGID LIKE '" + str(row)[3:10] + "'" SelectLayerByAttribute_management(layer_name, "ADD_TO_SELECTION", delsel) #delete the selected rows DeleteRows_management(layer_name) del fc, layer_name, deltbl, table_name print "Delete function completed"
def withProperty(self, sql): """ :param sql: sql expression :returns: feature that meets the properties of the sql expression """ name = "wProp_" + str(self.sObj) outputLocation = "in_memory\\" + name selByAtt = SelectLayerByAttribute_management(self.filepath, "NEW_SELECTION", sql) CopyFeatures_management(selByAtt, outputLocation) wProp = utils.makeObject(outputLocation) # update cc instance's attributes desc = Describe(outputLocation) wProp.domain = desc.extent wProp.filepath = outputLocation wProp.filename = os.path.basename(outputLocation) return wProp
def calibrationCCL(): 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_BEGIN","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(connection0+"/"+schema+"CCL_LRS_ROUTEbase","CCL_LRS",connection1+"CALIBRATION_POINTS_CCL","CCL_LRS","CCL_MEASURE",connection1+"CCL_LRS_ROUTE","DISTANCE","1 Feet","BETWEEN","NO_BEFORE","NO_AFTER","IGNORE","KEEP","INDEX") AddField_management(connection1+NewRoute, "NETWORKDATE", "DATE") CalculateField_management(connection1+NewRoute,"NETWORKDATE","datetime.datetime.now( )","PYTHON_9.3","#") MakeFeatureLayer_management(connection1+"CCL_LRS_ROUTE", NewRoute)
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 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"