En la consola de Python:
1) crear una clase de capa de memoria (clase completa (sin atributos) en 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) funciones de álgebra vectorial (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) cosenos de dirección
def dircos(point):
cosa = point.x() / mag(point)
cosb = point.y()/ mag(point)
return cosa,cosb
4) línea de proceso o segmentos de línea
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
polilínea, punto equidistante con Shapely o PyQGIS2, con cosenos de dirección
Luego solo ajusta el intervalo