I have two layers both containing roads of the same area. One si from OSM, and the other is from another source. Both networks are quite dense and for the most part, they contain the same roads, although their geometries do not overlap. In this photo green lines are OSM roads, and purple ones are the other shapefile. As you can see, in some places a road is represented in both OSM and the other layer, but some roads are present only in OSM layer, and other ones only in this other layer.

enter image description here

I need to combine these two into one shapefile which contains one combined network of roads, but in a way that I remove the lines which refer to the same road. So I need to remove the duplicates, but they aren't 100% duplicates since their geometries aren't the same. In some places lines are paralell, in other places they intersect.

Is there a way to do this in QGIS or Postgresql, so that I don't have to do it all manually and delete the ones that refer to the same road? I tried to do a spatial join in Postgresql using ST_DWithin with a small distance, but then some lines which are nearby or perpendicular get selected as well.

  • 1
    Do you need attributes from one or both layers? You could try what I usually did with a similar need in my work. I would thicken the gray lines of the layer that had the most lines and draw that over the other layer which was in red, and then easily select all the red lines to add to the first layer. It's not elegant but it look little thought and it worked.
    – John
    Commented Dec 15, 2023 at 17:49
  • Check if your software has any 'conflation' tools.
    – mkennedy
    Commented Dec 17, 2023 at 16:27

1 Answer 1


If this is OSM data, one very different but possibly easier approach you could use is map matching. Basically you map match all of your point to point linestrings and group them by the map matched osm way and keep just one. You can use the Valhalla project for this which builds its graph from OpenStreetMap. They have a free API you can use for this use case (some scripting will be required) and let it do the heavy lifting for you. In the response you will find the way IDs. From the docs

You can turn a GPS trace into a set of way IDs that match the trace.

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.