No console do Python:
1) crie uma classe de camada de memória (classe completa (sem atributos) em crea_mem_layer.py )
class Create_vlayer(object):
'''creation of a virtual layer'''
def __init__(self,nom,type):
self.type=type
self.name = nom
self.layer = QgsVectorLayer(self.type, self.name , "memory")
self.pr =self.layer.dataProvider()
def create_point(self,geometry):
# add point to the layer
self.seg = QgsFeature()
self.seg.setGeometry(QgsGeometry.fromPoint(geometry))
self.pr.addFeatures([self.seg])
self.layer.updateExtents()
@property
def display_layer(self):
#end of layer and display layer
QgsMapLayerRegistry.instance().addMapLayers([self.couche])
2) funções de álgebra vetorial (de algèbre_vect_PyQGIS.py )
import math
def mag(point):
# magnitude of a vector
return math.sqrt(point.x()**2 + point.y()**2)
def diff(point2, point1):
# substraction betwen two vector
return QgsPoint(point2.x()-point1.x(), point2.y() - point1.y())
def length(point1,point2):
# with PyQGIS: sqrDist
return math.sqrt(point1.sqrDist(point2))
3) direção cossenos
def dircos(point):
cosa = point.x() / mag(point)
cosb = point.y()/ mag(point)
return cosa,cosb
4) linha de processo ou segmentos de linha
def pairs(list):
# list pairs iteration
for i in range(1, len(list)):
yield list[i-1], list[i]
layer = qgis.utils.iface.activeLayer()
# interval between points
interval = 5 m
# create virtual layer
gen_pt = Create_vlayer("mid5", "Point")
for elem in layer():
line = elem.geometry()
for seg_start, seg_end in pairs(line.asPolyline()):
line_start = QgsPoint(seg_start)
line_end = QgsPoint(seg_end)
# mid point = vector coordinates [x2-x1,y2-y1]
pointm =diff(line_end, line_start)
# direction cosines of the segment
cosa,cosb = dircos(pointm)
# length of the segment
lg = length(line_end, line_start)
# generate and add points to the virtual layer
for i in range(interval,lg,interval):
gen_pt.create_point(QgsPoint(line_start.x() + (i * cosa), line_start.y() + (i*cosb)))
# display layer
gen_pt.display_layer
Resultados
polilinha, ponto equidistante com Shapely ou PyQGIS2, com cossenos de direção
Então apenas ajuste o intervalo