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 run into a problem and can't figure out how to solve this one.

I use the ModelBuilder and have a shapefile with loads of information. This information needs to be reduced. Therefore I want to select several rows (not all of them) out of several columns by attribute to delete them.

So for example, column X contains data with attributes a, b and c. I only want to delete c. Since I use the ModelBuilder, I need a tool from the toolbox which does that (preferably) in one step.

Any ideas?

share|improve this question

5 Answers 5

Edit: The first method I posted wouldn't work. This one should though.

One straightforward way to do this would be to select everything you want to keep via Make Feature Layer with a where clause of X <> c. Then, use Copy Features to save the result.

share|improve this answer
    
+1 A straight-forward, simple approach. –  Aaron Jun 20 at 16:04
    
I'll try that one. Thanks! I thought there might be a tool like 'Select' but working the opposite way. Thanks :) –  Stophface Jun 20 at 16:05
    
Just tried it. Its not working. Feature I saved is empty. Once I made the feature layer through selection and then delet the rows, the file must be empty... ? –  Stophface Jun 20 at 16:25
    
@Stophface, yes, I made a mistake. If you select everything you want to get rid of and then delete it, you'll be left with nothing. Try the 2nd option, where you select what you want to keep and then save to disk. –  Paul Jun 20 at 16:35
    
I've edited my post to reflect this. –  Paul Jun 20 at 16:43

To do this in one step I would use the Select (Analysis) tool which:

Extracts features from an input feature class or input feature layer, typically using a select or Structured Query Language (SQL) expression and stores them in an output feature class.

For your where_clause use:

"X" <> 'c'
share|improve this answer

I don't know if you're saying you want to delete the data in specific columns for specific rows or if you want to delete specific rows all together. If it is the latter, there is another answer already that uses Delete Rows that would likely work for you. If you are trying to just delete specific data from specific records though, the typical workflow for a situation like this, at least to me, would be something like the following:

Make Feature Layer (No SQL expression at this point)

Select Layer By Attribute (write the selection for the first column here, ex: ColumnX = 'c' or ColumnX IN ('a', 'd') )

Calculate Field (set expression type to Python or Python_9.3, set the expression to 0 if a numeric field or '' if a text field, and select the column in question ex: ColumnX as the Field Name)

Select Layer by Attribute (make sure Selection Type param is set to NEW_SELECTION and then write a selection for the next field you want to delete data from, ex: ColumnY = 3 or ColumnY IN (1, 4) )

Calculate Field (use same parameters as before but do for the relevant column, ex: ColumnY)

Repeat this select Layer by Attribute and Calculate Field operation until you have all data cleared from all fields as desired. At the end, depending on if your workflow needs to continue onto other steps or not, you may want to run Select Layer by Attribute a final time and set the Selection Type parameter to CLEAR_SELECTION

Yes, this is a lot longer than you were probably hoping for, but... Again, this is if your question was getting at trying to just delete all the occurrences of c from column x in your example. If you were trying to delete the entire row/record for any records that have c as the column x value, then try Paul or Erica's suggestions.

share|improve this answer
    
I have several columns with several attrbiutes i.e. column x with the attributes a,b,c and column y with the attributes e,r and t. I want to delet from column x the rows with the attribute a and from column y the rows with the attributes r and t. –  Stophface Jun 20 at 16:00
    
Alright. I will try that one. Why do I need to calculate field? –  Stophface Jun 20 at 17:59
    
Well, like I said in the answer, that is only to delete select data from select records. EX: You have a feature with ID=123, Name=ABC, ColumnX=C, etc.... Using the answer above, it would give you ID=123, Name=ABC, ColumnX= , etc... It would NOT delete the entire feature. It uses the calculate field to clear out the unwanted values. If you are wanting the delete the entire feature, I would go back and re-try and figure out what went wrong with Paul's answer. Try it on a copy of data though to test it until you get it working how you want. –  John Jun 20 at 18:14
    
thanks. Lets see how it works :) –  Stophface Jun 20 at 18:23
    
What I do not understand is how i set the expression in calculating field... And what do you mean by "use the same parameters as before but for the relevant column"? Im sorry. I just started to learn ArcGis... I am pretty new and not sure what to do where... –  Stophface Jun 20 at 18:54

In two steps:

MakeFeatureLayer_management with the where clause X = c.

-or if you already have a layer-

SelectLayerByAttribute_management with the where clause X = c.

-then-

DeleteFeatures_management using the layer.

Be careful that the selection is done properly on the layer otherwise it will delete all the features in that feature class. It is much safer to use Copy Features or Select to make a new layer as Paul and PolyGeo have said, so I would recommend doing it that way, however the question was Deleting features (rows) from shapefile (attribute table) using ModelBuilder? and that is how to do that.

share|improve this answer
    
I did it this way: With the "select Tool" I simply select everything I dont want. That creates a new layer. With the "erase Tool" I use my original Data and erase from that with the new created file through the "select command". Thank you all for your help guys! –  Stophface Jun 21 at 16:06

USE A SELECT BY ATTRIBUTES "TEST" = 'A' OR "TEST" = 'B' THEN USE THE MERGE TOOL THIS ALLOWS YOU TO ESSENTIALLY SELCT OUT TO A NEW FEATURE CLASS AND DROP ANY EXTRA FIELDS TOO

THE DELETE TOOL IS SLOW, THE DELETE FIELD IS SLOW, AND EDIT SESSIONS CAN BE A PAIN

share|improve this answer

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.