I have the following problem: I have two street datasets from completely different sources. I need some attributes from one dataset (red lines) to be joined into the other one (green lines). Until now I tried to make a buffer and afterwards join the green lines with the buffer...it worked, until I was facing some specific problem. The buffer does not always cover the green line in extreme situations and the attributes will be lost (see attached picture). Do you have any other ideas? I was working in PostGIS so far, but I am also open for other solutions.

1 Answer 1


I would try to find the nearest feature from the reference layer.

SELECT DISTINCT ON (a.id) a.id,  b.column1
FROM green a
-- find all the points you want to snap to within the given distance in units of crs
LEFT JOIN red b ON (ST_DWithin(a.wkb_geometry, b.wkb_geometry, 150))
-- order by distance (see spatal operators, mainly <#>, st_distance might be handy as well, though not that efficient)
ORDER BY id, a.wkb_geometry <-> b.wkb_geometry;

This way you can retrieve attributes of the nearest feature for every green line. Note that you might need to fiddle with ST_DWithin distance parameter a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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