<?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: arcpy problem grabbing SHAPE@ token using index in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135511#M50269</link>
    <description>&lt;P&gt;Copy/paste error indeed. I've editted the original post so the indentation should be correct now. Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jan 2022 16:55:24 GMT</pubDate>
    <dc:creator>lkline97</dc:creator>
    <dc:date>2022-01-20T16:55:24Z</dc:date>
    <item>
      <title>arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135425#M50254</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have written code that selects rows of a buffer shapefile based on that file's intersection with a polygon that represents the extent of a raster. In the photo below, the code selects all of the red dots for this given polygon.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 221px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31888i4AF68FB567F9181B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Using a cursor, I am going through those selected buffers and clipping an associated raster by each buffer. The code below was working when I wrote it three months ago; however, since updating, I am having a problem grabbing the SHAPE@ token as a polygon to clip the raster. &lt;STRONG&gt;EDIT:&lt;/STRONG&gt;&amp;nbsp;I would have been using Version 2.8.3 when I wrote and ran the code successfully, and I have Version 2.9.1 now.&lt;/P&gt;&lt;P&gt;I believe I've isolated the problem to the row[1] command. Previously, I'm under the impression that I was grabbing a polygon object. Now, however, my output for the lines,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;print(' row: ', row)
print(' row[1]: ', row[1])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is showing row[1] as two different outputs, a Polygon object that I want and the geoprocessing geometry object that it now gives me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;row: ['LCRas_0', &amp;lt;Polygon object at 0x1f56ab62108[0x1f56db53300]&amp;gt;]
row[1]: &amp;lt;geoprocessing describe geometry object object at 0x000001F56DB53300&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The clip code that once worked is now giving me a blank output. I've also tried Extract by Mask, but receive an error (good ole 99999) when I try to specify that the output extent should be that of the buffer.&lt;/P&gt;&lt;P&gt;Could this be a bug in the versions, or am I missing something simple? Thank you for any input!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;env.workspace = r'I:\test\Polygons'
arcpy.env.addOutputsToMap = False
fields = ['RasterName', 'SHAPE@']
j=0 #code was made pieacemeal to work on 3 comps; number changes depending where in the shapefile you're at
buff_file = r"I:\test\test_buffs.shp"

for poly in listp:
#record lc file that corresponds
     lc_file = poly[:-9].replace(" ", "")
     path = r"I:\test\Classified"
     cor_rast = os.path.join(path, str(lc_file+"_classified.tif"))
     raster_xmin = arcpy.GetRasterProperties_management(cor_rast, "LEFT")
     raster_xmax = arcpy.GetRasterProperties_management(cor_rast, "RIGHT")
     raster_ymin = arcpy.GetRasterProperties_management(cor_rast, "BOTTOM")
     raster_ymax = arcpy.GetRasterProperties_management(cor_rast, "TOP")
     extent = raster_xmin[0] + " " + raster_ymin[0] + " " + raster_xmax[0] + " " + raster_ymax[0]
     print('Starting arcpy.da.UpdateCursor')

     with arcpy.da.UpdateCursor(arcpy.management.SelectLayerByLocation(buff_file, "INTERSECT", poly),fields) as cursor: #select by polygon
          for row in cursor:
               rname = str("LCRas_" + str(j)) #make raster name
               path = r"I:\test\Rasters" #set path where raster output will happen
               rpath = os.path.join(path, str(rname+".tif")) #create name of raster file
               print(' Starting arcpy.Clip_management for ', rpath)
               print(' cor_rast: ', cor_rast)
               print(' raster_xmin: ', raster_xmin)
               print(' raster_xmax: ', raster_xmax)
               print(' raster_ymin: ', raster_ymin)
               print(' raster_ymax: ', raster_ymax)
               print(' extent: ', extent)
               print(' row: ', row)
               print(' row[1]: ', row[1])
               arcpy.Clip_management(cor_rast, extent, rpath, row[1], "0", "ClippingGeometry", 'MAINTAIN_EXTENT') #extract raster from land cover
               print(' Ended arcpy.Clip_management for ', rpath)
               row[0] = rname #set row to equal raster name
               cursor.updateRow(row) #updates row to have raster column
               j=j+1
print('Ended arcpy.da.UpdateCursor')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. I am cross-posting this on GIS stack exchange and will share any updates if I get them there as well.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 16:54:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135425#M50254</guid>
      <dc:creator>lkline97</dc:creator>
      <dc:date>2022-01-20T16:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135473#M50265</link>
      <description>&lt;P&gt;I haven't had a chance to dive in, but you should always share what version it last worked for you and what version you are using now.&amp;nbsp; Saying "since updating, I am having a problem" doesn't give folks much to go on, especially if you think the issue is related to a change in Pro versions.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 16:18:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135473#M50265</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-01-20T16:18:49Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135479#M50266</link>
      <description>&lt;P&gt;Thank you for the feedback! I will edit this into the post, but I would have been using Version 2.8.3 when I wrote and ran the code successfully, and I have Version 2.9.1 now.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 16:21:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135479#M50266</guid>
      <dc:creator>lkline97</dc:creator>
      <dc:date>2022-01-20T16:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135501#M50267</link>
      <description>&lt;P&gt;Your indentation doesn't appear to be correct... perhaps a copy paste issue&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank"&gt;Code formatting ... the Community Version - Esri Community&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 16:48:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135501#M50267</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-01-20T16:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135511#M50269</link>
      <description>&lt;P&gt;Copy/paste error indeed. I've editted the original post so the indentation should be correct now. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 16:55:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135511#M50269</guid>
      <dc:creator>lkline97</dc:creator>
      <dc:date>2022-01-20T16:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135688#M50299</link>
      <description>&lt;P&gt;I just applied the 2.9.1 patch, and I ran some basic tests against polygon feature classes, and I am not seeing what you are seeing.&amp;nbsp; I get &amp;lt;Polygon object at ...&amp;gt; when printing row and row[1].&lt;/P&gt;&lt;P&gt;Can you share a sample of the data set?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 23:14:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135688#M50299</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-01-20T23:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135939#M50342</link>
      <description>&lt;P&gt;Hmm, interesting. I hope it's okay to share through a Google Drive link as the files are too large to share here. You can find those &lt;A href="https://drive.google.com/drive/folders/1iuD8bdFW43w6rifdht420s4ScuIvK0dX?usp=sharing" target="_self"&gt;here&lt;/A&gt;. line 7 references a variable listp that I didn't specify above; that should be set to the shapefile in the Polygons folder. Please let me know if I can clarify anything, and I appreciate the help!&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 18:29:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135939#M50342</guid>
      <dc:creator>lkline97</dc:creator>
      <dc:date>2022-01-21T18:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135988#M50353</link>
      <description>&lt;P&gt;It looks like that's working as intended.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(r'path/to/some_polygon.shp', 'SHAPE@') as cursor:
    for row in cursor:
        print(row)
        print(type(row))
        print(row[0])
        print(type(row[0]))

[&amp;lt;Polygon object at 0x286a858f748[0x286a80f2a20]&amp;gt;]
&amp;lt;class 'list'&amp;gt;
&amp;lt;geoprocessing describe geometry object object at 0x00000286A80F2A20&amp;gt;
&amp;lt;class 'arcpy.arcobjects.geometries.Polygon'&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you're still getting the Polygon? The output you showed is "printing" that object, which does not necessarily show the type, but shows the string conversion such as a Describe object.&lt;BR /&gt;&lt;BR /&gt;Perhaps the problem is elsewhere?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 20:28:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1135988#M50353</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-21T20:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1136024#M50359</link>
      <description>&lt;P&gt;Once you get a polygon there is loads you can get&lt;/P&gt;&lt;LI-CODE lang="python"&gt;p = array_poly(sq2, "POLYGON")
p
[(&amp;lt;Polygon object at 0x190d54416c8[0x190d53f25a0]&amp;gt;,), ... snip ...,
 (&amp;lt;Polygon object at 0x190d5441888[0x190d5455510]&amp;gt;,)]

p0 = p[0][0]
dir(p0)
['JSON', 'WKB', 'WKT', '__add__', '__class__', '__cmp__', '__delattr__',
 '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__from_scripting_arc_object__', '__ge__', '__geo_interface__',
 '__getSVG__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__',
 '__module__', '__ne__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__sub__',
 '__subclasshook__', '__type_mapping__', '__type_string__', '__weakref__', '__xor__', '_arc_object', '_fromGeoJson', '_go', '_passthrough',
 '_repr_svg_', 'angleAndDistanceTo', 'area', 'boundary', 'buffer', 
 'centroid', 'clip', 'contains', 'convexHull', 'crosses', 'cut',
 'densify', 'difference', 'disjoint', 'distanceTo', 'equals', 'extent', 
 'firstPoint', 'generalize', 'getArea', 'getGeohash', 'getLength', 'getPart',
 'hasCurves', 'hullRectangle', 'intersect', 'isMultipart', 'labelPoint', 
 'lastPoint', 'length', 'length3D', 'measureOnLine', 'overlaps', 'partCount',
 'pointCount', 'pointFromAngleAndDistance', 'positionAlongLine', 'projectAs',
 'queryPointAndDistance', 'segmentAlongLine', 'snapToLine',
 'spatialReference', 'symmetricDifference', 'touches', 'trueCentroid', 'type', 'union', 'within']&lt;/LI-CODE&gt;&lt;P&gt;until such time, you have just the polygon&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="polygon.png" style="width: 323px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31999iE01B1327190CF352/image-size/medium?v=v2&amp;amp;px=400" role="button" title="polygon.png" alt="polygon.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But there is lots of other stuff you can explore on your own from the above&lt;/P&gt;&lt;LI-CODE lang="python"&gt;p0.isMultipart
False

p0.hullRectangle
'2.94135809733738 11.7648938434666 11.1766832588924 9.70596830869874 8.23532516155499 -2.05892553476782 0 0'&lt;/LI-CODE&gt;&lt;P&gt;Or if you want to convert shapes or get things like the convex hull etc&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ch.png" style="width: 323px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/32002i09D93DC8F58F5777/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ch.png" alt="ch.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;explore, there is loads of stuff that can be obtained directly from the object itself&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 21:37:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1136024#M50359</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-01-21T21:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy problem grabbing SHAPE@ token using index</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1136395#M50432</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;It looks like I may have sent us on a wild goose chase. There seems to have been an issue with the extent rather than the polygon. By chance I realized that the output from the code above was not a blank raster, but instead one at such a large scale that I couldn't see the small 0.6 radius raster.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I ran the Clip Raster tool in ArcGIS Pro, I got the following Python output for clipping the raster by the first buffer successfully:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.Clip(cor_rast, "464910.1475 4860275.062 535365.525099999 4890685.978", path, "test_buffs", "15", "ClippingGeometry", "NO_MAINTAIN_EXTENT")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;This produces a raster with the appropriate final extent of "465252.920&amp;nbsp;465254.140&amp;nbsp;4860631.900&amp;nbsp;4860633.120".&lt;/P&gt;&lt;P&gt;When I used this code:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for poly in listp:
#record lc file that corresponds
     lc_file = poly[:-9].replace(" ", "")
     path = r"I:\test\Classified"
     cor_rast = os.path.join(path, str(lc_file+"_classified.tif"))
     raster_xmin = arcpy.GetRasterProperties_management(cor_rast, "LEFT")
     raster_xmax = arcpy.GetRasterProperties_management(cor_rast, "RIGHT")
     raster_ymin = arcpy.GetRasterProperties_management(cor_rast, "BOTTOM")
     raster_ymax = arcpy.GetRasterProperties_management(cor_rast, "TOP")
     extent = raster_xmin[0] + " " + raster_ymin[0] + " " + raster_xmax[0] + " " + raster_ymax[0]&lt;/LI-CODE&gt;&lt;P&gt;to get the extent for the&amp;nbsp; classified raster, I instead got that the extent of the classified raster is&lt;/P&gt;&lt;PRE&gt;464479.22 4859161.04 465380.34 4860963.28&lt;/PRE&gt;&lt;P&gt;Instead of setting extent in line 33 as the raster extent, I changed it to be the polygon extent. This was successful. The fixed code is below. I have no idea why the code worked when I wrote it three months ago, but it seems to be in order now! Thank you to everyone for the help; it made me sit and consider my code more critically.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;env.workspace = r'I:\test\Polygons'
arcpy.env.addOutputsToMap = False
fields = ['RasterName', 'SHAPE@']
j=0 #code was made pieacemeal to work on 3 comps; number changes depending where in the shapefile you're at
buff_file = r"I:\test\test_buffs.shp"

for poly in listp:
    #record lc file that corresponds
    lc_file = poly[:-9].replace(" ", "")
    path = r"I:\test\Classified"
    cor_rast = os.path.join(path, str(lc_file+"_classified.tif"))
    print('Starting arcpy.da.UpdateCursor')   
    
    with arcpy.da.UpdateCursor(arcpy.management.SelectLayerByLocation(buff_file, "INTERSECT", poly),fields) as cursor: #select by polygon
        for row in cursor:
            rname = str("LCRas_" + str(j)) #make raster name
            path = r"I:\test\Rasters" #set path where raster output will happen
            rpath = os.path.join(path, str(rname+".tif")) #create name of raster file
            extent = row[1].extent
            extentBuff = str(extent.XMin) + " " + str(extent.YMin) + " " + str(extent.XMax) + " " + str(extent.YMax)            
            arcpy.management.Clip(cor_rast, extentBuff, rpath, row[1], "15", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
            print('   Ended arcpy.Clip_management for ', rpath)
            row[0] = rname #set row to equal raster name
            cursor.updateRow(row) #updates row to have raster column 
            j=j+1  
    print('Ended arcpy.da.UpdateCursor')&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 24 Jan 2022 14:57:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-problem-grabbing-shape-token-using-index/m-p/1136395#M50432</guid>
      <dc:creator>lkline97</dc:creator>
      <dc:date>2022-01-24T14:57:39Z</dc:date>
    </item>
  </channel>
</rss>

