[GIS] Merging features (lines) in shapefile with same name using Python and QGIS

pythonqgis

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).

Best Answer

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.