AnsweredAssumed Answered

Loading multiple features from shapefile before processing

Question asked by amilt on Oct 14, 2012
Latest reply on Oct 30, 2012 by amilt
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:

# define the input file shapefile = '_myfile.shp'  # import arcpy import arcpy arcpy.overwriteOutput = True  # set the cursor shpName = arcpy.Describe(shapefile).shapeFieldName cursor = arcpy.SearchCursor(shapefile)  # get the features BEFORE doing processing # WHERE THINGS GET FUNKY features = [r.getValue(shpName) for r in cursor]  cursor = None r = None  # to illustrate these are all the same, save them results = [] for i in xrange(len(features)):     fName = '_myfeat%i.shp' % i     results.append(arcpy.CopyFeatures_management(features[i], fName)


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?).

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.

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.

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.

Outcomes