"and the zip code border of the zip code the particular person named at the beginning of the survey"
#assumes the pnts and zipcode polys are in the same PRJ, distances are in PRJ's map units... peoplePntsFC = r"C:\temp\people.shp" #a pnt FC, with a field that has the claimed zip code zipCodeFC = r"C:\temp\zipcodes.shp" #polygon FC of zipcodes arcpy.AddField(peoplePntsFC, "DIST_TO_ZIP", "DOUBLE") updateRows = arcpy.da.UpdateCursor(peoplePntsFC, ["SHAPE@", "ZIP_CODE" "DIST_TO_ZIP"]) for updateRow in updateRows: pntObj = updateRow[0] zipCode = updateRow[1] zipPolyObj = arcpy.da.SearchCursor(zipCodeFC, ["SHAPE@"], "ZIP_CODE = " + str(zipCode)).next()[0] updateRow[2] = pntObj.distanceTo(zipPolyObj) updateRows.updateRow(updateRow) del updateRow, updateRows
You could write a script to do this, but how about just using the Near tool: http://resources.arcgis.com/en/help/main/10.2/index.html#//00080000001q000000
Okay, I guess you would have to write a script.Probably a better/faster way to do this (how many people pnts do you have)? I wonder if the geom objectects still get corrupted if they get put into a Python dictionary?? Perfomace trick would be to access the geometry of the zip code polys as quickly as possible...Anyway, some code (UNTESTED!) might look like this:#assumes the pnts and zipcode polys are in the same PRJ, distances are in PRJ's map units... peoplePntsFC = r"C:\temp\people.shp" #a pnt FC, with a field that has the claimed zip code zipCodeFC = r"C:\temp\zipcodes.shp" #polygon FC of zipcodes arcpy.AddField(peoplePntsFC, "DIST_TO_ZIP", "DOUBLE") updateRows = arcpy.da.UpdateCursor(peoplePntsFC, ["SHAPE@", "ZIP_CODE" "DIST_TO_ZIP"]) for updateRow in updateRows: pntObj = updateRow[0] zipCode = updateRow[1] zipPolyObj = arcpy.da.SearchCursor(zipCodeFC, ["SHAPE@"], "ZIP_CODE = " + str(zipCode)).next()[0] updateRow[2] = pntObj.distanceTo(zipPolyObj) updateRows.updateRow(updateRow) del updateRow, updateRows
As I have no experience with pyton yet
#assumes the pnts and polys are in the same PRJ, distances are in PRJ's map units... import arcpy, time #a pnt FC, with a field that has the claimed county code pntsFC = r"C:\csny490\temp\test.gdb\random_pnts" #polygon FC of counties (with a field for COUNTY_CD) polyFC = r"C:\csny490\temp\test.gdb\counties" #add a field to store the distance arcpy.AddField_management(pntsFC, "DIST_TO_CNTY", "DOUBLE") #put the county geometry into a dictionary for faster lookups polyGeomDict = {r[0]:(r[1]) for r in arcpy.da.SearchCursor(polyFC, ["COUNTY_CD","SHAPE@"])} #start a timer time1 = time.clock() #initialize an update cursor updateRows = arcpy.da.UpdateCursor(pntsFC, ["SHAPE@","CLAIMED_CD","DIST_TO_CNTY"]) #a for loop to iterate through the points for updateRow in updateRows: #get a hook to the 1st two updatecursor field values pntObj, countyCode = updateRow[0:2] #set the DIST_TO_CNTY value to be the distanace of the pnt to the specified polygon updateRow[2] = pntObj.distanceTo(polyGeomDict[countyCode]) #commit the update to disk updateRows.updateRow(updateRow) #del the update cursor objects del updateRow, updateRows #stop the timer time2 = time.clock() #report the time it took to calc the distances print "Took " + str(time2 - time1) + " seconds!"
polyGeomDict = {r[0]:(r[1]) for r in arcpy.da.SearchCursor(polyFC, ["COUNTY_CD","SHAPE@"])}
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.