Hi all,
I am writing a Python script in which I build a geodatabase, based on several inputs.
At one point, I am looping over a number of points (X,Y) which need to be treated individually using several criteria.
One criterium is the polygon in which this point is located. This polygon comes from a feature table with a number of other fields.
There are several tools (Intersect, SelectByLocation, SpatialJoin, ....) which might help doing this, but they all are based on input and output tables.
How can I extract this one polygon, and linked fields, from that table, without having to make temporary input and output tables ?
In an ideal world, it could look like this :
for i in range (0, numberOfPoints):
inputPoint = arcpy.Point(X, Y)
findFeature(tableWithPolygons, inputPoint, outputFeature)
myValue = outputFeature.value
# based on this value, I can do further processing
Thanks for pointing me in the right direction
Does some part of this involve the ArcGIS API for Python or are you just using ArcPy, or aren't you sure? I am sharing with Python since this seems to be ArcPy related.
I don't clearly understand the difference between ArcPy and ArcGIS API for Python.
Aren't they both using Python functions to get things automated which you can do manually in ArcGIS Pro ?
With the information provided, I can only provide a rough workflow that may or may not meet your needs:
SR = arcpy.Describe(tableWithPolygons).spatialReference
layerPolygon = arcpy.MakeFeatureLayer_management(tableWithPolygons, "layerPolygon")
for i in range(0, numberofPoints):
inputPointGeometry = arcpy.PointGeometry(arcpy.Point(X,Y), SR)
arcpy.SelectLayerByLocation_management(
layerPolygon,
"INTERSECT",
inputPointGeometry,
"",
"NEW_SELECTION"
)
with arcpy.da.SearchCursor(layerPolygon, "*") as cur:
for row in cur:
myValue = # retrieve value(s)
# based on this value, I can do further processing
A few comments:
Hello Joshua,
Sorry for the late reply (I'm leaving my current position, and have lots of things to wrap up).
Thanks for the code snippet.
I've implemented your proposal (with a few modifications), and it works OK.
Unfortunately I cannot avoid temporary layers.
It's quite time consuming (a query for every single point), but I cannot do it with the complete table, because the Intersect tool doesn't keep my features in the same order, and this is something I MUST have.
Thanks again.
If the polygon data set is already loaded into ArcMap as a layer, you don't need to create another layer, you can just use the already created one. If the script is run outside of ArcMap, creating a feature layer in memory for processing isn't really an issue because the layer will go away when the script finishes.