Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. # import arc module and datetime
  2. import arcpy, datetime
  3.  
  4. # Get start time
  5. start = datetime.datetime.now()
  6.  
  7. #Create an error class
  8. class NoExist(Exception):
  9. pass
  10.  
  11. #Get Dataset locations (need to turn this into a toolbox)
  12. dataSetFolder = arcpy.GetParameterAsText(0)
  13. propertyDataset = arcpy.GetParameterAsText(1)
  14. suburbsDataset = arcpy.GetParameterAsText(2)
  15.  
  16. #Test locations exist
  17. try:
  18.  
  19. if not arcpy.Exists(dataSetFolder):
  20. raise NoExist
  21. elif not arcpy.Exists(propertyDataset):
  22. raise NoExist
  23. elif not arcpy.Exists(suburbsDataset):
  24. raise NoExist
  25.  
  26. arcpy.env.workspace = dataSetFolder
  27.  
  28. # if data doesnt exist display error message
  29. except NoExist:
  30. print "No data available"
  31. arcpy.AddMessage("No data available")
  32.  
  33. # construct variable list
  34. fc_p = propertyDataset
  35. fc_s = suburbsDataset
  36. fields = arcpy.ListFields(fc_p)
  37. LOCALITYList = []
  38.  
  39. # build query (blank string) and assign fields to variables
  40. query = '"LOCALITY" = '''
  41. field_p = ['FID','LOCALITY']
  42. field_s = ['FID', 'ADMINAREA']
  43.  
  44. # Make feature layers of each of the files
  45. arcpy.MakeFeatureLayer_management(fc_s,'suburbs_lyr')
  46. arcpy.MakeFeatureLayer_management(fc_p,'properties_lyr')
  47.  
  48.  
  49. # use update cursor to identify properties without associated locality
  50. with arcpy.da.UpdateCursor('properties_lyr', field_p,query) as Urows:
  51. for Urow in Urows:
  52. # second query for FID while using cursor through rows
  53. query2 = '"FID" = ' + str(Urow[0])
  54. # make a temp layer with the results and then select properties which are contained in suburbs layer
  55. arcpy.MakeFeatureLayer_management(fc_p,'Temp_properties_lyr', query2)
  56. arcpy.SelectLayerByLocation_management('suburbs_lyr', "CONTAINS", 'Temp_properties_lyr')
  57. # Search cursor to scroll through suburbs
  58. for Srow in arcpy.da.SearchCursor('suburbs_lyr',field_s):
  59. #variable to record result of ADMINAREA in search cursor
  60. Suburb = Srow[1]
  61. # set value of temp properties layer LOCALITY to Suburbs ADMINAREA
  62. Urow[1] = Suburb
  63. print Urow
  64. # continue through rows
  65. Urows.updateRow(Urow)
  66. # place reults into list
  67. LOCALITYList.append(Suburb)
  68. # delete temp properties layer
  69. arcpy.Delete_management('Temp_properties_lyr')
  70.  
  71. #Delete cursors
  72. del Urows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement