AnsweredAssumed Answered

Get access to polygon containing point using Python arcpy

Question asked by mcplng on Jul 24, 2014
Latest reply on Jul 24, 2014 by tsellste

Hello all,


I have a parcels layer in SDE GDB which contains over 300,000 polygons. I want to print attributes of a parcel polygon which "contains" an input point. The following code works but it is slow (takes about a minute to run). Is there a way to re-write this code (possibly using an Intersect or Spatial Join approach) for faster performance? Please provide some sample code. Thanks!


import arcpy

# Input point coordinates
locX = 1303479.87779
locY = 485423.249288

dataMxdPath = r"C:\Projects\Parcels.mxd"
dataMxd = arcpy.mapping.MapDocument(dataMxdPath)
parcelsLayer = arcpy.mapping.ListLayers(dataMxd, "Parcels")[0]

point = arcpy.Point(locX, locY)

for row in arcpy.SearchCursor(parcelsLayer):
    polygonGeom = row.SHAPE
    if polygonGeom.contains(point):
        print row.OBJECTID