1

Is there a tool or workflow that can create a feature at minimum distance or equal distance between several points?

This is now a QGIS question but to clarify I've attached a couple images to show what I mean with three points:

Below are a couple candidate points:

enter image description here

Here I've created a some Thiessen Polygons:

enter image description here

Then I convert the vertices of the Thiessen polygons to points and select the point at the center:

enter image description here

This is just a simple example of what I'd like to learn how to do on a larger scale, e.g. to create more than one "minimum distance" points over an area containing a lot more candidate points. The goal is to automate this as well so the user doesn't have to go in and select the points located between the desired points and omit those on the edge.

  • I would have thought that creating thiessen/voronoi polygons, extracting the nodes and then using a spatial query to remove those along the edge would be the way forward. Could be achieved entirely in postgis/spatialite/qgis virtual layers – George of all trades Jan 25 '17 at 16:15
  • 1
    @Casey C I just posted a working solution for QGIS, but I didn't realize that your attached images were created using ArcGIS: I hope you can test it anyway. – mgri Jan 25 '17 at 18:32
  • What is "minimum distance" you refer to? Is it the midpoint between adjacent Points? – klewis Jan 25 '17 at 19:06
  • Thanks for the your interest in my question. Yes, I am essentially looking for the midpoint, maybe equidistant, between several points. – Casey C Jan 26 '17 at 16:26
1

Using PyQGIS, you may run the following code from the Python Console. It starts from a set of points and returns what you was looking for, i.e. deleting the points from the output of the Extract nodes tool which lie on the edges of the output from the Voronoi polygons tool.

It's a bit long, but theoretically simple (you only need to keep active the layer with your starting points, and then run it):

from qgis.core import *
import processing

layer = iface.activeLayer()
# Run 'Voronoi polygons' algrithm from Processing
voronoi = processing.runalg("qgis:voronoipolygons",layer,0,None)
vor = processing.getObject(voronoi['OUTPUT'])

# Run 'Extract nodes' algorithm from Processing
extract = processing.runalg("qgis:extractnodes",vor,None)
extr = processing.getObject(extract['OUTPUT'])
prov = extr.dataProvider()

all_points = {}
index = QgsSpatialIndex() # Spatial index
for ft in extr.getFeatures():
    index.insertFeature(ft)
    all_points[ft.id()] = ft

ext = extr.extent()
xmin = ext.xMinimum()
xmax = ext.xMaximum()
ymin = ext.yMinimum()
ymax = ext.yMaximum()

pt1 = QgsPoint(xmin,ymin)
pt2 = QgsPoint(xmax,ymin)
pt3= QgsPoint(xmax,ymax)
pt4 = QgsPoint(xmin,ymax)

selection = []
lines = [QgsGeometry.fromPolyline([pt1,pt2]), QgsGeometry.fromPolyline([pt2,pt3]), QgsGeometry.fromPolyline([pt3,pt4]), QgsGeometry.fromPolyline([pt1,pt4])]
lineFeat = QgsFeature()
for line in lines:
    lineFeat.setGeometry(line)
    idsList = index.intersects(lineFeat.geometry().boundingBox())
    for id in idsList:
        if id not in selection:
            selection.append(id)
prov.deleteFeatures(selection)

# Add the layer to the Layers panel
QgsMapLayerRegistry.instance().addMapLayer(extr)

Just an example. Starting from these sample points:

enter image description here

I obtain this (I also reported the Voronoi vector for a better understanding of the results, but it's not an output of the code):

enter image description here

  • 1
    Thanks for the suggestion. I'm pretty familiar with QGIS as well and am interested in giving this a shot. – Casey C Jan 25 '17 at 19:03

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.