Advertisement
wtgeographer

updateTables

May 22nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 KB | None | 0 0
  1.  
  2. '''
  3. This script updates remaining attributes and should be run after
  4. each session of digitizing neighborhood and subneighbrhood polygons.
  5. '''
  6.  
  7. import arcpy
  8. import time
  9.  
  10. # city variable
  11. city = 'chandler'
  12. county = 'maricopa'
  13. state = 'az'
  14.  
  15. workspace = 'C:\\Users\\noah\Desktop\\gundog\\{0}\\data.gdb' .format(city)
  16.  
  17. arcpy.env.workspace = workspace
  18.  
  19.  
  20. def updateNeighborhoods():
  21.  
  22.     # fc = 'lewisville_neighborhoods'  
  23.     # fc = 'denton_neighborhoods'
  24.     fc = 'neighborhoods'
  25.     fields = ['name','city', 'county', 'state', 'area', 'last_updated', "SHAPE@AREA"]
  26.  
  27.     edit = arcpy.da.Editor(workspace)
  28.     edit.startEditing(False, True)
  29.     edit.startOperation()
  30.  
  31.     with arcpy.da.UpdateCursor(fc,fields) as cursor:
  32.         for row in cursor:
  33.  
  34.             # update city
  35.             row[1] = city.title()
  36.             cursor.updateRow(row)
  37.  
  38.             # update date
  39.             if row[5] == None:
  40.                 row[5] =  time.strftime('%m/%d/%Y')
  41.                 cursor.updateRow(row)
  42.  
  43.             # update county
  44.             row[2] =  county.title()
  45.             cursor.updateRow(row)
  46.  
  47.             # update state
  48.             row[3] =  state.title()
  49.             cursor.updateRow(row)
  50.  
  51.     calc = [["area", "!SHAPE.AREA@ACRES!"]]
  52.     for field,expression in calc:
  53.         arcpy.CalculateField_management(fc,field,expression, "PYTHON_9.3")
  54.  
  55.     edit.stopOperation()
  56.     edit.stopEditing(True)
  57.    
  58.  
  59.  
  60. def updateSubNeighborhoods():
  61.  
  62.     fc = 'subneighborhoods'
  63.     fields = ['name','city', 'county', 'state', 'area', 'last_updated', 'neighborhood', "SHAPE@AREA"]
  64.  
  65.     '''
  66.     add functions later for...
  67.     legal_name
  68.     businesss_id
  69.     mgmt_co
  70.     '''
  71.  
  72.     edit = arcpy.da.Editor(workspace)
  73.     edit.startEditing(False, True)
  74.     edit.startOperation()
  75.  
  76.     with arcpy.da.UpdateCursor(fc,fields) as cursor:
  77.         for row in cursor:
  78.  
  79.             # update city
  80.             row[1] = city.title()
  81.             cursor.updateRow(row)
  82.  
  83.             # update date
  84.             if row[5] == None:
  85.                 row[5] =  time.strftime('%m/%d/%Y')
  86.                 cursor.updateRow(row)
  87.  
  88.             # update county
  89.             row[2] =  county.title()
  90.             cursor.updateRow(row)
  91.  
  92.             # update state
  93.             row[3] =  state.title()
  94.             cursor.updateRow(row)
  95.  
  96.             # update Sub_name
  97.             if row[6] == None:
  98.                 row[6] =  row[0]
  99.                 cursor.updateRow(row)
  100.  
  101.  
  102.     # calculate landArea and Neighborhood fields
  103.    
  104.     #  Remove phase, etc. and any trailing whitespace with (!name!.split("-")[0] ) and then (!Neighborhood!.rstrip()).
  105.     calc = [["area", "!SHAPE.AREA@ACRES!"], ["neighborhood", "!name!.split(\"-\")[0]"],["neighborhood", "!neighborhood!.rstrip()"]]
  106.     for field,expression in calc:
  107.         arcpy.CalculateField_management(fc,field,expression, "PYTHON_9.3")
  108.  
  109.     edit.stopOperation()
  110.     edit.stopEditing(True)
  111.  
  112.  
  113. updateNeighborhoods()
  114. updateSubNeighborhoods()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement