I have one Point Shapefile with the correct geographic position, lets call it A.

I have another Point Shapefile with the attributes I need, but with an offset of 0,7m or so (it varies a bit from point to point, but its very close to Point A).Lets call it B.

I would like to combine those two features automatically, so that I will have a Point Shapefile with the correct geographic position from A and the needed attributes from B. There's thousands of them so I cannot insert the attributes manually. Is there a way to work with buffers or something?

(QGIS, etc.)

  • Is there any case involving more than two points (with your given offset) ? – snaileater Mar 14 '18 at 11:59
  • No, there is not. – KATRIN Mar 14 '18 at 12:05

This solution is also based on a QGIS virtual layer and ideas from Finding nearest neighbors between two tables with point locations in SpatiaLite?

SELECT a.id, b.name, min(ST_Distance(a.geometry, b.geometry)) AS distance, a.geometry 
FROM points_exact AS a, points_near AS b   
    WHERE ST_Contains(ST_Expand(a.geometry,5),b.geometry)
        GROUP BY a.id
        ORDER BY a.id

enter image description here

From the SpatiaLite 4.2.0 SQL functions reference list:

ST_Expand - returns the rectangle bounding g as a Polygon. The bounding rectangle is expanded in all directions by an amount specified by the second argument.

There you can set your offset search value (0.7m).

The result is a temporary layer with the id from the layer points_exact with the attribute name of the points_near layer and the distance. You can right click Save As to a new vector layer (shapefile).


I really recommend not to use the ST_Buffer function for larger data sets. In a test case I did a query on two point layers, each with a feature count of over 7000 points. Using ST_Expand and ST_Contains took about 3 minutes. With ST_Buffer I killed the QGIS process after half an hour. I also recommend to disable rendering (bottom right of the QGIS Canvas) before running the query and adding the results to the project because it takes the same amount of time to render the features. Without rendering you can easily right click and Save As immediately.

enter image description here

| improve this answer | |

You can use a virtual layer in QGIS with the following definition:

select B.b1, B.b2, A.geometry 
from A, B 
where st_intersects(B.geometry, st_buffer(A.geometry, 1))

B.b1 and B.b2 are attributes from Layer B, the Geometry comes from Layer A where a buffer (in this example the buffer width is 1) around A intersects B.

| improve this answer | |
  • ST_Buffer is slow when working with larger data sets. – Stefan Mar 14 '18 at 13:43
  • when i try this i get an exponential amount of features. i tried various buffer widths and it didnt change? – KATRIN Mar 14 '18 at 14:45
  • @KATRIN - In which projection is your data stored (4326 (degrees), or a metric system)? – Stefan Mar 14 '18 at 14:50
  • 3857, pseudo mercator – KATRIN Mar 14 '18 at 14:55
  • Are you sure the projection of the LAYERs are 3857? Or do you mean your project projection? If your working with degrees the query above uses a buffer of 1 degree, which is quite big. – Stefan Mar 14 '18 at 15:00
  1. Create a buffer which is big enough to cover your offset-points (Layer B) (MMQGIS - Create Buffer)
  2. Do a spatial join (plugin: spatialJoin) with your buffer as target layer. The layer to join is the ones with the offset (Layer B). Now you have the buffer combined with the attribute you need.
  3. Do another spatial join, this time your target layer is your geographically correct layer (Layer A). The layer to join is your buffer. The result will be your Layer A combined with the attribute from Layer B.
| improve this answer | |

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.