1

I used 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'm using the ModelBuilder, I need a tool from the toolbox which does that (preferably) in one step.

Any ideas?

5 Answers 5

7

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.

0
3

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'
0

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.

0
0

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.

0
0

Use a select by attributes "Test" = 'a' or "Test" = 'b'

Then use the merge tool. This allows you to essentially select 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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