Select to view content in your preferred language

Get attributes from many shapefiles?

3831
24
Jump to solution
03-02-2017 08:40 AM
MichaelLenore1
Deactivated User

I have a very large .gdb (15000+ shapefiles). I know that's unusually and impractially large, but it's the result of an iterative model. I need an Excel sheet with all of those shapefiles' attributes. I tried merging them but it's too many. Is there some other way? 

Tags (2)
24 Replies
Lake_Worth_BeachAdmin
Frequent Contributor

Correct. The code tells the script each feature has rows and to look at the rows. However if there is no row to look at it raises an error.

0 Kudos
MichaelLenore1
Deactivated User

Is there a way to get the script to skip blank FCs? There shouldn't be any but I can't be sure. 

0 Kudos
Lake_Worth_BeachAdmin
Frequent Contributor

I would wait to see what the script author has to say but I just ran this script on a file GDB on my work machine and got this result:

>>>
Listing feature classes...
Found 473 feature classes
[u'OBJECTID', u'Shape', u'FINALNAME', u'CHARACTR', u'created_user', u'created_date', u'last_edited_user', u'last_edited_date', u'Shape_Length', u'Shape_Area']
Writing to C:\Users\jhead\Desktop\SDE_FC_Attributes.csv
WATER_BODIES
STORM_CDM_LakeWorthStructures

Traceback (most recent call last):
File "C:\Users\jhead\Desktop\Scripts\ArcPy\List_Feature_Class_Attributes_GDB.py", line 24, in <module>
for row in sc:
RuntimeError: A column was specified that does not exist.
>>>

0 Kudos
FilipKrál
Frequent Contributor

Hi Michael and Joseph,

The initial piece of code demonstrated how one would go around solving the problem but there are things one needs to add to make it more bulletproof. If I added them in the first place, the code would be too long and hard to understand. 

One important assumption in the initial code is that all feature classes in the geodatabase have the same columns. Why else would you want to join them all into one result? I suspect Joseph is seeing the error because the script encountered a feature class that does not fit this assumption.

When it comes to empty feature classes, i.e. feature classes with no rows, the code the `for row in rows` loop should not raise an exception as long fc has all the expected columns. The subsequent `del row` statement may raise an exception though. You can to comment out the `del row` statement.

One way to deal with these strange cases is to add some try-except statements and handle the failing feature classes in some other way. I'll leave that up to you.

Cheers,

Filip.

Lake_Worth_BeachAdmin
Frequent Contributor

Correct, the test GDB I tried the script on contained FC that would NOT have the same field names so that makes sense. 

thank you

0 Kudos