2

I have a shapefile. I would like to know if it is possible to classify the different layers in that shapefile (like highways, local roads, rail lines, etc.) with MTFCC and extract a separate shapefile from the existing one.

So for example, if I had a shapefile of our existing county with all vectors present could I make another, separate shapefile, of that same county containing only highways and local roads?

This is all using PyQGIS v2.14.0

2

There are existing algorithms from the Processing Toolbox which you can call. We could use two such algorithms:

  1. Select by expression - Selects all features based on an expression.
  2. Save selected features - Saves the selected features in a shapefile.

import processing

layer = qgis.utils.iface.activeLayer()
expression = """ "fieldName" = 'value_1' OR "fieldName" = 'value_2' """
result = "C:/Users/You/Desktop/result.shp"

processing.runalg("qgis:selectbyexpression", layer, expression, 0)
processing.runalg("qgis:saveselectedfeatures", layer, result)
1
  • @Mr.Elephant - Most welcome, glad it worked =) – Joseph Jul 25 '16 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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