Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # import arc module and datetime
- import arcpy, datetime
- # Get start time
- start = datetime.datetime.now()
- #Create an error class
- class NoExist(Exception):
- pass
- #Get Dataset locations (need to turn this into a toolbox)
- dataSetFolder = arcpy.GetParameterAsText(0)
- propertyDataset = arcpy.GetParameterAsText(1)
- suburbsDataset = arcpy.GetParameterAsText(2)
- #Test locations exist
- try:
- if not arcpy.Exists(dataSetFolder):
- raise NoExist
- elif not arcpy.Exists(propertyDataset):
- raise NoExist
- elif not arcpy.Exists(suburbsDataset):
- raise NoExist
- arcpy.env.workspace = dataSetFolder
- # if data doesnt exist display error message
- except NoExist:
- print "No data available"
- arcpy.AddMessage("No data available")
- # construct variable list
- fc_p = propertyDataset
- fc_s = suburbsDataset
- fields = arcpy.ListFields(fc_p)
- LOCALITYList = []
- # build query (blank string) and assign fields to variables
- query = '"LOCALITY" = '''
- field_p = ['FID','LOCALITY']
- field_s = ['FID', 'ADMINAREA']
- # Make feature layers of each of the files
- arcpy.MakeFeatureLayer_management(fc_s,'suburbs_lyr')
- arcpy.MakeFeatureLayer_management(fc_p,'properties_lyr')
- # use update cursor to identify properties without associated locality
- with arcpy.da.UpdateCursor('properties_lyr', field_p,query) as Urows:
- for Urow in Urows:
- # second query for FID while using cursor through rows
- query2 = '"FID" = ' + str(Urow[0])
- # make a temp layer with the results and then select properties which are contained in suburbs layer
- arcpy.MakeFeatureLayer_management(fc_p,'Temp_properties_lyr', query2)
- arcpy.SelectLayerByLocation_management('suburbs_lyr', "CONTAINS", 'Temp_properties_lyr')
- # Search cursor to scroll through suburbs
- for Srow in arcpy.da.SearchCursor('suburbs_lyr',field_s):
- #variable to record result of ADMINAREA in search cursor
- Suburb = Srow[1]
- # set value of temp properties layer LOCALITY to Suburbs ADMINAREA
- Urow[1] = Suburb
- print Urow
- # continue through rows
- Urows.updateRow(Urow)
- # place reults into list
- LOCALITYList.append(Suburb)
- # delete temp properties layer
- arcpy.Delete_management('Temp_properties_lyr')
- #Delete cursors
- del Urows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement