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 have a feature (polygon) with nearly 60 fields in it. Now I want to delete all fields except 20(or a list of) and they are not one after one, no they are somewhere in the droplist. But to select for a tons around 40 feature shape files would be a huge searching and clicking time...because he update for every new loaded feature his droplist and i can start searching again and again. Normally it must be go the opposite way...or? I am looking for a tool or script by "invers droping". From the web I didnt get a useful solution. maybe someone here?

Thanks for hints...if I forget something to explain, i can draw a scetch...

share|improve this question
    
So you have a feature class with multiple features (your polygons). This feature class has multiple fields (attributes) defined, around 60 ones. Your goal is to be able to delete all fields except those you want to define and you don't want to select 40 fields in the list of fields in the Delete Fielf GP tool. Correct? –  Alex Tereshenkov Jun 12 at 18:51
    
Yes, this i called invert delete :-) –  user32330 Jun 12 at 19:16
    
There was a command in ArcInfo Workstation called PULLITEMS that worked the way you describe. Its bonus behaviour was that it could re-order items/fields at the same time. I think you will find an existing ArcGIS Idea to have a Pull Fields tool implemented in ArcGIS for Desktop. –  PolyGeo Jun 12 at 19:46

2 Answers 2

if you stay with the tools, you can first select all the fields then unselect the ones that you want to keep.

You could also create a Python script to do this, but if you don't have a fixed rule and you need to enter the field names manually, this will not help.

import arcpy   

# if you can use a key to identify the fields to remove, then it's solved
fields = arcpy.Listfields(fc) 

# manually enter field names to keep here
# include mandatory fields name such as OBJECTID and Shape in keepfields
keepfields = ["OBJECTID","Shape","fld1","fld3,"fld20"]

dropfields = [x.name for x in fields if x.name not in keepFields]

arcpy.DeleteFields_management(fc, dropFields)
share|improve this answer
    
My list of fields which i need are in each feature class same. So this list of the 20 are fixed. But if i call everytime the tool, he reads the fieldlist again an i can start search in the list which ones i want. With python script i am not too much expired. In the arc tool help for deletefield is a stand-alone script example, but i didn't get it to run as script. this is new to me. I can post this script and maybe we could develop some code in it... –  user32330 Jun 12 at 19:20
    
you can use the above script directly in the command prompt in ArcMap. you just need to change "fc" by the name of your feature class. –  radouxju Jun 12 at 19:30
    
Thanks. I will try it. This is what I looked for with the "if ... not in" :-) –  user32330 Jun 12 at 19:44
    
+1 Not only is this script very functional, it also shows how Python can be used to create very clean workflows by the list comprehension. –  Aaron Jun 12 at 20:03
    
Yes I find this command: listfields() by searching the web but didnt know how to use it with python and arcgis...i am a little newbie by using python to make some automated workflows... –  user32330 Jun 12 at 20:38

Deleting the fields directly is an excellent and simple approach. However, you may want to be more conservative and create a copy of the original feature classes with only the fields you need. One approach is to create a model in ModelBuilder to do this for you. In the attached model, you can see an iterator is used to loop through all of the feature classes in a workspace. Feature Class To Feature Class (Conversion) is used to copy the features and delete the unnecessary fields. You can call the name variable for the output by using %name%. In this case, I attached _copy to the output name by using %name%_copy in the output parameter.

enter image description here

enter image description here

share|improve this answer
    
Have you tried using a model with an iterator? –  Aaron Jun 12 at 20:31
    
I tried this, but in the result feature class where less attributes as in the original one...and i didnt find out why it was like that. And one problem is that this tool shows the arrow up and arrow down to sort the fields but this is not working...nothing happens. –  user32330 Jun 12 at 20:40
    
Could I use the Expression(optional) with some SQL-Code to select the fields i want? How it could look like? –  user32330 Jun 18 at 11:42
    
I write in it SELECT a, b FROM feature class, but the verify-button gaves me an error, and wrote that already a SELECT * FROM feature class WHERE SELECT a, b FROM feature class is invalid. So I understand that this Expression makes already a selection on all fields. Can I modify that after the WHERE he choose the fields I want or is that not possible? –  user32330 Jun 18 at 11:57

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.