I'm working on a pet project. The blue circles in the map below are highway exits. They exists in pairs of two (one for each side). I'd like to replace them with one point in the middle, indicating that in roughly that area one can access the highway. How would I go about achieving this in QGIS?
You can achieve this in a single step using a virtual layer.
Extending on this post, it is possible to join the point layer with itself based on point proximity. For every pair of points within the given distance, the virtual layer will make a line and finally return a point at the line centroid.
Let's note that the distance is in the layer CRS unit, so make sure to use a CRS whose units is in meters, or if it is in lat-long use a much smaller distance threshold (like 0.01 degrees for roughly 1 km)
Go to the menu
Layer > Add Layer > Add/Edit Virtual Layer... and enter the following query.
Note that the line is created once between 2 points (A-B is the same as B-A).
select st_centroid(make_line(a.geometry, b.geometry)) as geometry, a.id as fromID, b.id as toID FROM myPointLayer a JOIN myPointLayer b ON ST_Distance(a.geometry, b.geometry) < 2000 AND a.id < b.id
Thanks to the suggestions of the respondents I figured out a solution. Since I'm sure that in this setting nearby points belong together as one highway entrance point, I:
- Created buffer zones using MMQGIS such that all pairs overlap.
- Dissolved them using Geoprocessing tools, which creates a multiple part polygon.
- Used multiple to single part to make sure we have individual polygons.
- Calculated the centroids using geometry tools.
I figured out that step 3 was necessary thanks to this answer:
Here's my end result (dissolved polygons deleted):