<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Get access to polygon containing point using Python arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747129#M57760</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Ian&lt;/P&gt;&lt;P&gt;Thank you so much for your reply! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt; It was helpful. I had to modify your code slightly to get it to print. It works much faster now (takes about 10 seconds instead of taking a minute like before). Modified working code is pasted below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1406234129194257 jive_text_macro" jivemacro_uid="_1406234129194257" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Input point coordinates&lt;/P&gt;
&lt;P&gt;locX = 1303479.87779&lt;/P&gt;
&lt;P&gt;locY = 485423.249288&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;dataMxdPath = r"C:\Projects\Parcels.mxd"&lt;/P&gt;
&lt;P&gt;dataMxd = arcpy.mapping.MapDocument(dataMxdPath)&lt;/P&gt;
&lt;P&gt;parcelsLayer = arcpy.mapping.ListLayers(dataMxd, "Parcels")[0]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;point = arcpy.Point(locX, locY)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;with arcpy.da.SearchCursor(parcelsLayer, ["OBJECTID","SHAPE@","LEGAL_DESC"] ) as cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polygonGeom = row[1] # SHAPE@ has index 1 in the fields array above&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if polygonGeom.contains(point):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0] # Prints OBJECTID value (Field index is 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[2] # Prints LEGAL_DESC value (Field index is 2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 24 Jul 2014 20:40:05 GMT</pubDate>
    <dc:creator>Montgomery_CountyPlanning_Depa</dc:creator>
    <dc:date>2014-07-24T20:40:05Z</dc:date>
    <item>
      <title>Get access to polygon containing point using Python arcpy</title>
      <link>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747127#M57758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14062292815587729" jivemacro_uid="_14062292815587729" modifiedtitle="true"&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;import arcpy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;# Input point coordinates&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;locX = 1303479.87779&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;locY = 485423.249288&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;dataMxdPath = r"C:\Projects\Parcels.mxd"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;dataMxd = arcpy.mapping.MapDocument(dataMxdPath)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;parcelsLayer = arcpy.mapping.ListLayers(dataMxd, "Parcels")[0]&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;point = arcpy.Point(locX, locY)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;for row in arcpy.SearchCursor(&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: 'courier new', courier; font-size: 12px;"&gt;parcelsLayer&lt;/SPAN&gt;):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; polygonGeom = row.SHAPE&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if polygonGeom.contains(point):&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.OBJECTID&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 19:19:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747127#M57758</guid>
      <dc:creator>Montgomery_CountyPlanning_Depa</dc:creator>
      <dc:date>2014-07-24T19:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Get access to polygon containing point using Python arcpy</title>
      <link>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747128#M57759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried using a data access cursor(arcpy.da.SearchCursor)?&amp;nbsp; Its significantly faster than the old cursor.&amp;nbsp; Also, your current cursor uses all fields, which takes mroe time, you can specify only the geometry field, which should cut down processing time.&amp;nbsp; I don't see how using any geoprocessing tools would speed things up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for arcpy.da.SearchCursor usage and syntax:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000011000000" title="http://resources.arcgis.com/en/help/main/10.1/index.html#//018w00000011000000" rel="nofollow noopener noreferrer" target="_blank"&gt;ArcGIS Help 10.1&lt;/A&gt;‌&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

import arcpy&amp;nbsp; 


# Input point coordinates&amp;nbsp; 
locX = 1303479.87779&amp;nbsp; 
locY = 485423.249288&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp; 
dataMxdPath = r"C:\Projects\Parcels.mxd"&amp;nbsp; 
dataMxd = arcpy.mapping.MapDocument(dataMxdPath)&amp;nbsp; 
parcelsLayer = arcpy.mapping.ListLayers(dataMxd, "Parcels")[0]&amp;nbsp; 


point = arcpy.Point(locX, locY)&amp;nbsp; 


with arcpy.da.SearchCursor(parcelsLayer, ["SHAPE@"] ) as cursor: 


&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polygonGeom = row[0]&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if polygonGeom.contains(point):&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row.OBJECTID&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&amp;nbsp; 






&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also I added the with statement for memory's sake.&amp;nbsp; Your original code doesn't delete the cursor object after the script ends, but the with takes care of that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:46:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747128#M57759</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2021-12-12T07:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: Get access to polygon containing point using Python arcpy</title>
      <link>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747129#M57760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Ian&lt;/P&gt;&lt;P&gt;Thank you so much for your reply! &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt; It was helpful. I had to modify your code slightly to get it to print. It works much faster now (takes about 10 seconds instead of taking a minute like before). Modified working code is pasted below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1406234129194257 jive_text_macro" jivemacro_uid="_1406234129194257" modifiedtitle="true"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# Input point coordinates&lt;/P&gt;
&lt;P&gt;locX = 1303479.87779&lt;/P&gt;
&lt;P&gt;locY = 485423.249288&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;dataMxdPath = r"C:\Projects\Parcels.mxd"&lt;/P&gt;
&lt;P&gt;dataMxd = arcpy.mapping.MapDocument(dataMxdPath)&lt;/P&gt;
&lt;P&gt;parcelsLayer = arcpy.mapping.ListLayers(dataMxd, "Parcels")[0]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;point = arcpy.Point(locX, locY)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;with arcpy.da.SearchCursor(parcelsLayer, ["OBJECTID","SHAPE@","LEGAL_DESC"] ) as cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; polygonGeom = row[1] # SHAPE@ has index 1 in the fields array above&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if polygonGeom.contains(point):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[0] # Prints OBJECTID value (Field index is 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row[2] # Prints LEGAL_DESC value (Field index is 2)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 20:40:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747129#M57760</guid>
      <dc:creator>Montgomery_CountyPlanning_Depa</dc:creator>
      <dc:date>2014-07-24T20:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: Get access to polygon containing point using Python arcpy</title>
      <link>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747130#M57761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please mark as answered to facilitate others finding a response that provided useful information.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 20:42:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747130#M57761</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-07-24T20:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Get access to polygon containing point using Python arcpy</title>
      <link>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747131#M57762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad you got it working faster now.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 20:47:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747131#M57762</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-24T20:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Get access to polygon containing point using Python arcpy</title>
      <link>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747132#M57763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might also try this.&amp;nbsp; If your parcels have a spatial index, this should be pretty fast too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;arcpy.SelectLayerByLocation(in_layer=arcpy.PointGeometry(point), select_features=parcelsLayer)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 23:35:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-access-to-polygon-containing-point-using/m-p/747132#M57763</guid>
      <dc:creator>TomSellsted</dc:creator>
      <dc:date>2014-07-24T23:35:41Z</dc:date>
    </item>
  </channel>
</rss>

