Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- This script updates remaining attributes and should be run after
- each session of digitizing neighborhood and subneighbrhood polygons.
- '''
- import arcpy
- import time
- # city variable
- city = 'chandler'
- county = 'maricopa'
- state = 'az'
- workspace = 'C:\\Users\\noah\Desktop\\gundog\\{0}\\data.gdb' .format(city)
- arcpy.env.workspace = workspace
- def updateNeighborhoods():
- # fc = 'lewisville_neighborhoods'
- # fc = 'denton_neighborhoods'
- fc = 'neighborhoods'
- fields = ['name','city', 'county', 'state', 'area', 'last_updated', "SHAPE@AREA"]
- edit = arcpy.da.Editor(workspace)
- edit.startEditing(False, True)
- edit.startOperation()
- with arcpy.da.UpdateCursor(fc,fields) as cursor:
- for row in cursor:
- # update city
- row[1] = city.title()
- cursor.updateRow(row)
- # update date
- if row[5] == None:
- row[5] = time.strftime('%m/%d/%Y')
- cursor.updateRow(row)
- # update county
- row[2] = county.title()
- cursor.updateRow(row)
- # update state
- row[3] = state.title()
- cursor.updateRow(row)
- calc = [["area", "!SHAPE.AREA@ACRES!"]]
- for field,expression in calc:
- arcpy.CalculateField_management(fc,field,expression, "PYTHON_9.3")
- edit.stopOperation()
- edit.stopEditing(True)
- def updateSubNeighborhoods():
- fc = 'subneighborhoods'
- fields = ['name','city', 'county', 'state', 'area', 'last_updated', 'neighborhood', "SHAPE@AREA"]
- '''
- add functions later for...
- legal_name
- businesss_id
- mgmt_co
- '''
- edit = arcpy.da.Editor(workspace)
- edit.startEditing(False, True)
- edit.startOperation()
- with arcpy.da.UpdateCursor(fc,fields) as cursor:
- for row in cursor:
- # update city
- row[1] = city.title()
- cursor.updateRow(row)
- # update date
- if row[5] == None:
- row[5] = time.strftime('%m/%d/%Y')
- cursor.updateRow(row)
- # update county
- row[2] = county.title()
- cursor.updateRow(row)
- # update state
- row[3] = state.title()
- cursor.updateRow(row)
- # update Sub_name
- if row[6] == None:
- row[6] = row[0]
- cursor.updateRow(row)
- # calculate landArea and Neighborhood fields
- # Remove phase, etc. and any trailing whitespace with (!name!.split("-")[0] ) and then (!Neighborhood!.rstrip()).
- calc = [["area", "!SHAPE.AREA@ACRES!"], ["neighborhood", "!name!.split(\"-\")[0]"],["neighborhood", "!neighborhood!.rstrip()"]]
- for field,expression in calc:
- arcpy.CalculateField_management(fc,field,expression, "PYTHON_9.3")
- edit.stopOperation()
- edit.stopEditing(True)
- updateNeighborhoods()
- updateSubNeighborhoods()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement