파이썬 콘솔에서 :
1) 및 메모리 계층 클래스 (클래스 속성없이 완전한 () 생성 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) 벡터 대수 함수 ( 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) 방향 코사인
def dircos(point):
cosa = point.x() / mag(point)
cosb = point.y()/ mag(point)
return cosa,cosb
4) 프로세스 라인 또는 라인 세그먼트
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
결과
폴리 라인, 셰이 프리 또는 PyQGIS2와 등거리, 방향 코사인
그런 다음 간격을 조정하십시오.