Correctly Setting Spatial Reference for Geometry Objects when Geoprocessing

المشرف العام

Administrator
طاقم الإدارة
I'm attempting to find the nearest distance between a set of points, and a set of polygons. I don't want to use near tables because I have to do this operation for a large number of different selections on my polygon file, and I don't want to generate that many tables - all I need is a number. I'm trying to do this using geometry objects and the distanceTo() method, and storing a variable that keeps the smallest value for distanceTo(). In the end, it should just give me a single number: the shortest distance.

My problem so far has to do with spatial references I think. My point file is in UTM, and my polygon file is in state plain. Originally, the numbers I was getting were too large - millions of feet apart. So, I grabbed the spatial reference from my point file, and inserted it into both of my geometry objects when using the searchCursor. But now the numbers being returned are all 0 - and I know that my points don't all intersect.

I also know that all my selections on the polygon file are working properly - I've checked them ad nauseum - so I really don't think I'm getting erroneous numbers because of that.

So, my question is, have I entered the spatial references correctly? And if so, what else could be causing this issue? Is there something (there are probably many things...) that I don't understand about the distanceTo() tool?

shortestDistance = 10000000pointFile = r"c:\data\points"desc = arcpy.Describe(pointFile)sr = desc.spatialReferencepolyFile = r"c:\data\polys"#these files get turned into feature layers#in order to perform spatial selections#and attribute queriesfor row in arcpy.da.SearchCursor(polyFile, ["SHAPE@"], spatial_reference=sr): for part in row[0]: for pnt in part: if pnt: x = pnt.X y = pnt.Y point = arcpy.Point(x, y) array.add(point) else: arcpy.AddMessage("Polygon with Interior Ring") vegPoly = arcpy.Polygon(array)for row in arcpy.da.SearchCursor(pointFile, ["SHAPE@XY"], spatial_reference=sr): #make it a point geom x, y = row[0] point = arcpy.Point(x, y) centroid = arcpy.PointGeometry(point) distance = centroid.distanceTo(vegPoly) if distance < shortestDistance: shortestDistance = distancearcpy.Delete_management("veg_lyr")

أكثر...
 
أعلى