ArcGIS Desktop – Selecting ArcSDE Polygon by Point Using ArcPy

arcgis-10.0arcpyenterprise-geodatabaseperformanceselect

I keep thinking that I must be missing something, but there does not seem to be a tool in ArcGIS 10 to select features (in particular polygons) from a layer at a point (X,Y) location via ArcPy. The parameters for such a tool would just be a layer name and an XY location.

At the moment I workaround this by creating a point featureclass containing the point and performing a SelectLayerByLocation on it. However, when the polygon feature class is in Oracle (accessed via ArcSDE 9.x) and contains 3.5 million polygons the time taken to make the selection can be more than 5 mins when I think a second or two (with less code) would be more appropriate. The feature class has a spatial index and I've tried using arcpy.env.extent (which SelectLayerByLocation appears to ignore) to restrict the geographic area accessed but the performance remains very poor.

Is there a quicker way to do this using ArcGIS Desktop 10 and ArcPy?

Best Answer

Another approach to this would be to use the Spatial Join tool. Use the point as your input feature layer as above and the polygon layer as your identity features.
Unlike SelectLayerByLocation, SpatialJoin does honor the extent environment.

targetlayer = layername
joinlayer=arcpy.PointGeometry(arcpy.Point(x, y))
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(targetlayer)
arcpy.SpatialJoin_analysis(targetlayer, joinlayer, outputlayer, "JOIN_ONE_TO_MANY", "KEEP_COMMON", fieldmappings)

JOIN_ONE_TO_MANY might seem counter-intuitive, but since you only have one join feature, the main function of this option is to turn off aggregationand merge rules. KEEP_COMMON will make sure that your output is restricted only to the polygon that intersects your point. The Fieldmappings will restrict the output attributes to the shape and attributes of the polygon layer only; the default would include the point layer's attributes too.

The rest of the defaults will work fine, so you can leave off the remaining arguments.

Related Question