Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to delete all of the fields from a feature class in a simple tricky way, I don't want to loop over the fields because this method is very slow in arcpy.

I'm using a polygon feature class, I tried arcpy.MultipartToSinglepart_management but the feature class result saved all the fields.

Does anyone have any ideas?

share|improve this question
    
Check out this thread, it may give you ideas: gis.stackexchange.com/a/32731/8104 –  Aaron Sep 28 '12 at 14:00
3  
Is arcpy.ListFields() too slow? You can use that list in arcpy.DeleteField_management to delete multiple fields at once. Simply fldsToDelete = [x.name for x in arcpy.ListField_management() if not x.required] would generate that list of names not required which you can delete. Remember, if this is a shapefile, you need to keep one field (other than ObjectID and Shape) to be a valid shapefile. –  Michalis Avraam Sep 28 '12 at 15:50
add comment

2 Answers

up vote 2 down vote accepted

I think you could do this with MakeFeatureLayer on your original feature class, using field_info to "hide" all the fields, followed by CopyFeatures to get the features with no fields in a new feature class.

UPDATE

Based on @geogeek's comment I investigated to make sure that this would work - and it did. Here are some Python snippets of doing the steps manually to get the syntax right.

arcpy.MakeFeatureLayer_management("C:/avhome/arcGISdata/Exploration.gdb/Samples","Samples_Layer","#","#","OBJECTID OBJECTID HIDDEN NONE;SHAPE SHAPE HIDDEN NONE;Dip_Angle Dip_Angle HIDDEN NONE;Strike Strike HIDDEN NONE;Rock Rock HIDDEN NONE;Description Description HIDDEN NONE")

arcpy.CopyFeatures_management("Samples_Layer","C:/avhome/arcGISdata/Exploration.gdb/SamplesNoAtts","#","0","0","0")

The only attributes on output are OBJECTID and SHAPE

share|improve this answer
    
it's little hard to get or to make void field info –  geogeek Sep 28 '12 at 12:05
    
thanks a lot for the explanation, this is the simple way –  geogeek Sep 29 '12 at 7:46
add comment

You could work around it by creating a new feature class using the geometries of the old one but without the fields. The ArcGIS Resource Center has a section on working with geometry in Python. There' a section on reading and writing geometries that should cover what you need.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.