# Creating new feature point at minimum distance between numerous points using QGIS?

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:

Here I've created a some Thiessen Polygons:

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

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 Jan 25, 2017 at 16:15
• @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, 2017 at 18:32
• What is "minimum distance" you refer to? Is it the midpoint between adjacent Points? Jan 25, 2017 at 19:06
• Thanks for the your interest in my question. Yes, I am essentially looking for the midpoint, maybe equidistant, between several points. Jan 26, 2017 at 16:26

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