2

I am working with the NHD flowline dataset (USGS) and some of the line features have the same name. I want to merge the line features that have the same name. For example: There are three features that have the name "Kings River" and four features that have the name "Boulder Creek" how do I write a python script that merges these features based on the name? The question How to merge multiple overlapping lines using python? deals with a merge that is based on geometry - I need to merge the line features based on a non spatial attribute (name of flowline).

2

I would use the two following functions:

  1. Vector > Data Management Tools > Merge Shapefiles to One... in order to make one shapefile from the different ones you have (it seems that they are all line geometries so this will work).

  2. Vector > Geoprocessing Tools > Dissolve in order to merge the features based on the name attribute (this function asks for a merge attribute).

I have not tried this on a sample but it should work. 'hope I understood your problem correctly.

1

As mentioned by @wiltomap (and basically building on what he said), the Dissolve function sounds like it should do what you're asking for - merging multiple features by their common attribute name. If you want it using Python, you could use the following:

import processing

layer = qgis.utils.iface.activeLayer()
field = 'FieldName'
output = "C:\Users\you\Desktop\\result.shp"
processing.runalg("qgis:dissolve", layer, 'False', field, output)

Hope this helps!

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.