postpone creating spatial index?

346
2
Jump to solution
10-09-2013 11:18 AM
brucesimonson
New Contributor III
Hi Gang,

I am using python to create and populate a feature class in a file geodatabase.  There are many shapefiles involved (ca 500).  These are appended to the target output feature class inside a for loop, as such:

for shp in shpList:     arcpy.Append_management( shp, outputfc )


This works fine.

However, I think that the Append_management function regenerates the spatial index for the outputfc, after each call (within the loop).  If I'm right, this takes about 12 minutes per shapefile in my case, and this amounts to 100 hours of processing time to generate this spatial index, over and over again.

Is there any way to postpone the generation of the spatial index, until after all of the shapefiles have been loaded?  Certainly after they are loaded, I can call:

arcpy.AddSpatialIndex_management( outputfc )


and save my poor CPU from regenerating the spatial index so many times.

Fingers crossed ...

Cheers,
-Bruce
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
brucesimonson
New Contributor III
Neil!

The append tool allows you to input a whole bunch of feature at once into the append routine.
If your variable shpList is a real python list like ["Shape1.shp", "Shape2.shp", ...]
Then just pass the entire list into Append_management instead of doing it one at a time.

Cheers,
Neil


Exactly right!  Cut processing time to 5% in my case.  Blessings on you.

Here's what it took in my case. 

arcpy.CopyFeatures_management( shpList[0], combined_fc ) arcpy.Append_management( shpList[1:], combined_fc )


The first line creates a feature class in my file geodatabase, by copying the first shapefile in the list "shpList" to my consolidated feature class "combined_fc".  The second line appends the remaining shapefiles into this "combined_fc", starting with element "1" (the 2nd in the list), up through the end of the list.  The spatial index appears to be created once, after all the shapefiles in the list have been loaded.

Excellent.

Cheers,
-Bruce

View solution in original post

0 Kudos
2 Replies
NeilAyres
MVP Alum
The append tool allows you to input a whole bunch of feature at once into the append routine.
If your variable shpList is a real python list like ["Shape1.shp", "Shape2.shp", ...]
Then just pass the entire list into Append_management instead of doing it one at a time.

Cheers,
Neil
0 Kudos
brucesimonson
New Contributor III
Neil!

The append tool allows you to input a whole bunch of feature at once into the append routine.
If your variable shpList is a real python list like ["Shape1.shp", "Shape2.shp", ...]
Then just pass the entire list into Append_management instead of doing it one at a time.

Cheers,
Neil


Exactly right!  Cut processing time to 5% in my case.  Blessings on you.

Here's what it took in my case. 

arcpy.CopyFeatures_management( shpList[0], combined_fc ) arcpy.Append_management( shpList[1:], combined_fc )


The first line creates a feature class in my file geodatabase, by copying the first shapefile in the list "shpList" to my consolidated feature class "combined_fc".  The second line appends the remaining shapefiles into this "combined_fc", starting with element "1" (the 2nd in the list), up through the end of the list.  The spatial index appears to be created once, after all the shapefiles in the list have been loaded.

Excellent.

Cheers,
-Bruce
0 Kudos