<?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: Loading multiple features from shapefile before processing in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86298#M6785</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
features = [r.Shape for r in cursor]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;I tried this and it works just fine. However, I am using 10.1 (but I didn't use da.searchcursor).&amp;nbsp; I suspect it will work on 10.0.&lt;BR /&gt;&lt;BR /&gt;Also, you can use the in_memory workspace to make a temporary featureclass instead of writing out a shapefile.&lt;BR /&gt;&lt;BR /&gt;Mike&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your solution didnt work. I am using ArcMap 10.0, which may be the problem. I will have to look into the in_memory workspace, which I didnt know existed. Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 23:18:41 GMT</pubDate>
    <dc:creator>AustinMilt</dc:creator>
    <dc:date>2021-12-10T23:18:41Z</dc:date>
    <item>
      <title>Loading multiple features from shapefile before processing</title>
      <link>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86294#M6781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to load multiple features from a shapefile into a list before processing them; processing must come after. However, when I try to do this, I end up with the features all referencing the same object rather than having separate objects. Some code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# define the input file shapefile = '_myfile.shp'&amp;nbsp; # import arcpy import arcpy arcpy.overwriteOutput = True&amp;nbsp; # set the cursor shpName = arcpy.Describe(shapefile).shapeFieldName cursor = arcpy.SearchCursor(shapefile)&amp;nbsp; # get the features BEFORE doing processing # WHERE THINGS GET FUNKY features = [r.getValue(shpName) for r in cursor]&amp;nbsp; cursor = None r = None&amp;nbsp; # to illustrate these are all the same, save them results = [] for i in xrange(len(features)): &amp;nbsp;&amp;nbsp;&amp;nbsp; fName = '_myfeat%i.shp' % i &amp;nbsp;&amp;nbsp;&amp;nbsp; results.append(arcpy.CopyFeatures_management(features&lt;I&gt;, fName)&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Well, I just tried running my own code and got even worse results. This time, instead of the features all being the same, I had one feature that was completely out of whack, with an infinite inside-out rectangle extending to the left, and all other saved features being empty (but with the same extent?).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I then ran it two more times on the same file, and ArcMap crashed when I tried to load the individual shapefiles into the program.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I then ran it again on another shapefile and got similar behavior, where one feature from the shapefile was present, and all the others are empty.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any clues as to how to amend this? The major problem is that I am processing the features after loading all of them into Python. If I copy the features to their own shapefiles as soon as I load them, then the problem goes away. However, I'd like to avoid making a separate shapefile for each and every feature due to I/O time and file sizes.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 18:36:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86294#M6781</guid>
      <dc:creator>AustinMilt</dc:creator>
      <dc:date>2012-10-14T18:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Loading multiple features from shapefile before processing</title>
      <link>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86295#M6782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I too have seen this before and it isn't so intuitive from the online samples - and I may not explain it well, but I'll give it a shot.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The cursor row object is a reference, a 'pointer' if you will...so when you go to the next row, it's actually referencing the next geometry.&amp;nbsp; (At least that's how I understand it.)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Methods have changed for 10.1 and I'm still at 10, so I cannot test this - however, I think it's a little more straightforward at 10.1 so I think it's easier to show that 1st.&amp;nbsp; I think you need the object reference like this for the list you seem to be after (this should only store a list of the geometry objects):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;features = [r[0] for r in arcpy.da.SearchCursor(shapefile, ("SHAPE@"))]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 10.1 documentation actually states a geometry object is returned using the '@' token.&amp;nbsp; Also notice the use of the da (data access module), supposedly a performance enhancement, although I am not sure it is efficient to load the geometry as you wish into a list - better test it out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For 10.0, which I am a little more familiar with, but haven't tested this at length enough to say it'll work, I think you have to 'load' the geometry into a separate object you create, as in the script excerpt shown (this is not what I wrote, but a webhelp sample):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;########################################&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create an empty Geometry object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;g = arcpy.Geometry()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Run the CopyFeatures tool, setting the output to the geometry object.&amp;nbsp; GeometryList&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp; is returned as a list of geometry objects.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;geometryList = arcpy.CopyFeatures_management("c:/temp/outlines.shp", g)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;########################################&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I didn't know CopyFeatures could be used directly - that a cursor is not necessary to do exactly what you want (although I suppose you'll be opening a cursor to then write further output).&amp;nbsp; This short script in its entirety can be found here (at the bottom of the page):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using geometry objects with geoprocessing tools&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Resource Center » Professional Library » Geoprocessing » Geoprocessing with Python » Accessing geographic data in Python&lt;/SPAN&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/" rel="nofollow" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Oct 2012 00:43:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86295#M6782</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-10-21T00:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Loading multiple features from shapefile before processing</title>
      <link>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86296#M6783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
features = [r.Shape for r in cursor]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I tried this and it works just fine. However, I am using 10.1 (but I didn't use da.searchcursor).&amp;nbsp; I suspect it will work on 10.0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, you can use the in_memory workspace to make a temporary featureclass instead of writing out a shapefile.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:18:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86296#M6783</guid>
      <dc:creator>MikeHunter</dc:creator>
      <dc:date>2021-12-10T23:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: Loading multiple features from shapefile before processing</title>
      <link>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86297#M6784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I think I too have seen this before and it isn't so intuitive from the online samples - and I may not explain it well, but I'll give it a shot.&lt;BR /&gt;The cursor row object is a reference, a 'pointer' if you will...so when you go to the next row, it's actually referencing the next geometry.&amp;nbsp; (At least that's how I understand it.)&lt;BR /&gt;&lt;BR /&gt;Methods have changed for 10.1 and I'm still at 10, so I cannot test this - however, I think it's a little more straightforward at 10.1 so I think it's easier to show that 1st.&amp;nbsp; I think you need the object reference like this for the list you seem to be after (this should only store a list of the geometry objects):&lt;BR /&gt;&lt;BR /&gt;features = [r[0] for r in arcpy.da.SearchCursor(shapefile, ("SHAPE@"))]&lt;BR /&gt;&lt;BR /&gt;The 10.1 documentation actually states a geometry object is returned using the '@' token.&amp;nbsp; Also notice the use of the da (data access module), supposedly a performance enhancement, although I am not sure it is efficient to load the geometry as you wish into a list - better test it out.&lt;BR /&gt;&lt;BR /&gt;For 10.0, which I am a little more familiar with, but haven't tested this at length enough to say it'll work, I think you have to 'load' the geometry into a separate object you create, as in the script excerpt shown (this is not what I wrote, but a webhelp sample):&lt;BR /&gt;&lt;BR /&gt;########################################&lt;BR /&gt;# Create an empty Geometry object&lt;BR /&gt;#&lt;BR /&gt;g = arcpy.Geometry()&lt;BR /&gt;&lt;BR /&gt;# Run the CopyFeatures tool, setting the output to the geometry object.&amp;nbsp; GeometryList&lt;BR /&gt;#&amp;nbsp; is returned as a list of geometry objects.&lt;BR /&gt;#&amp;nbsp; &lt;BR /&gt;geometryList = arcpy.CopyFeatures_management("c:/temp/outlines.shp", g)&lt;BR /&gt;########################################&lt;BR /&gt;&lt;BR /&gt;I didn't know CopyFeatures could be used directly - that a cursor is not necessary to do exactly what you want (although I suppose you'll be opening a cursor to then write further output).&amp;nbsp; This short script in its entirety can be found here (at the bottom of the page):&lt;BR /&gt;&lt;BR /&gt;Using geometry objects with geoprocessing tools&lt;BR /&gt;Resource Center » Professional Library » Geoprocessing » Geoprocessing with Python » Accessing geographic data in Python&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_geometry_objects_with_geoprocessing_tools/002z0000001z000000/&lt;/A&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That worked! I wont claim to understand why, but I greatly appreciate the help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's great to know you can have arcpy write to in-memory variables using a predefined Geometry object. I will be using that in the near future.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Oct 2012 13:52:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86297#M6784</guid>
      <dc:creator>AustinMilt</dc:creator>
      <dc:date>2012-10-30T13:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Loading multiple features from shapefile before processing</title>
      <link>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86298#M6785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
features = [r.Shape for r in cursor]
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;I tried this and it works just fine. However, I am using 10.1 (but I didn't use da.searchcursor).&amp;nbsp; I suspect it will work on 10.0.&lt;BR /&gt;&lt;BR /&gt;Also, you can use the in_memory workspace to make a temporary featureclass instead of writing out a shapefile.&lt;BR /&gt;&lt;BR /&gt;Mike&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your solution didnt work. I am using ArcMap 10.0, which may be the problem. I will have to look into the in_memory workspace, which I didnt know existed. Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 23:18:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loading-multiple-features-from-shapefile-before/m-p/86298#M6785</guid>
      <dc:creator>AustinMilt</dc:creator>
      <dc:date>2021-12-10T23:18:41Z</dc:date>
    </item>
  </channel>
</rss>

