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).
-
Is this the earlier Q&A that you are referring to, or was it another? Either way, whenever referencing earlier Q&As all you have to do is to copy/paste their URLs into your question and they act as magic links to automatically display their titles. Would you be able to use the edit button to clarify which Q&A you are referencing, please?– PolyGeo ♦Commented Sep 14, 2015 at 2:43
-
possible duplicate of How to merge multiple overlapping lines using python?– Brad NesomCommented Sep 14, 2015 at 2:50
-
gis.stackexchange.com/questions/138667/… is not the same thing. The merge is not based on geometry - it's based on a non spatial attribute– DjbCommented Sep 14, 2015 at 2:54
-
@user1987819872313 if you think it is not a duplicate then I recommend editing that into the beginning of your question and say precisely why not.– PolyGeo ♦Commented Sep 14, 2015 at 4:10
-
possible duplicate of gis.stackexchange.com/questions/44639/…– AndreJCommented Sep 14, 2015 at 6:39
2 Answers
I would use the two following functions:
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).
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.
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!