Select to view content in your preferred language

Calculating distance between a table of specific points xy and specific polylines

3503
11
01-16-2014 11:36 AM
NinaKruse1
Emerging Contributor
Hello,

I have a question which I can only solve with a code I guess, so I need your help.

Background is, that in a context of population survey, people where asked to tell their zipcode, later one they set a point on googlemaps which result their adress coordinates and so after geocoding their point of adress (including street, zip code, ...). Unfortunetly the two zip codes (first variable and that from the geocoding) do not coincide in 25% of the data. Now I want to calculate the distance between the geocode point (xy) and the zip code border of the zip code the particular person named at the beginning of the survey.

As I have a huge amout of data my question is now how I can calculate the distance between the geocode point and the zip code border which the person told.

So ich have the attribute table + shapefile with the xy coordinates and one with the zip codes.

I thank you for any advice!!
Tags (2)
0 Kudos
11 Replies
NeilAyres
MVP Alum
Very cool Chris.
polyGeomDict = {r[0]:(r[1]) for r in arcpy.da.SearchCursor(polyFC, ["COUNTY_CD","SHAPE@"])}

Those nested thingys still give me the shakes, but I must try to use them more.
And I presume (can't remember), that if the point is inside the correct poly, the distance returned = 0.
If not the distance is to the nearest boundary.
So if the purpose is to identify those points mis-coded, then a simple text field with "Inside" or "Outside" could also be added.
Lets hope that Nina gets back to you and gives you a tick!!!

Cheers,
Neil
0 Kudos
ChrisSnyder
Honored Contributor
Comprehensions (list and dictionary flavors) are pretty darn cool, but in reality they are just a shortened/efficient form of a for loop. And yes, if the point is inside the poly, it has a distance of 0, otherwise, the closest distance is returned.

Seems like what I recall with geom objects in a dictionary (for me at least a few years back) was that certain reported properties, such as .area or .length were incorrect as compared with the geom object itself (not stored in a dictionary)... basically like the ESRI geom object wasn't 100% (but maybe 80%?) compatible with Python. As I recall Jason Scheirer from ESRI also chimed in with some info on this at the time, but again I can't seem to find the post!

Question for any ESRI people in the know (cough... Jason): Are geometry objects stored in Python dictionaries 100% kosher now? Have they always been or am I getting dementia already?
0 Kudos