Skip to content
Permalink
Browse files

[processing] added Chainage algorithm as script

  • Loading branch information
volaya committed Apr 24, 2014
1 parent 1610d63 commit 8436027f83049c6b16cbe913b4b63ad7dd066ce2
Showing with 46 additions and 0 deletions.
  1. +46 −0 python/plugins/processing/script/scripts/Chainage.py
@@ -0,0 +1,46 @@
##[Example scripts]=group
##lines=vector
##distance=number 1
##startpoint=number 0
##endpoint=number 0
##output=output vector

from qgis.core import *
from PyQt4.QtCore import *
from processing.core.VectorWriter import VectorWriter


def create_points(feat):
geom = feat.geometry()
length = geom.length()
currentdistance = 0

if endpoint > 0:
length = endpoint

out = QgsFeature()

while startpoint + currentdistance <= length:
point = geom.interpolate(startpoint + currentdistance)
currentdistance = currentdistance + distance
out.setGeometry(point)
attrs = feat.attributes()
attrs.append(currentdistance)
out.setAttributes(attrs)
writer.addFeature(out)


layer = processing.getObject(lines)
fields = layer.dataProvider().fields()
fields.append(QgsField('Distance', QVariant.Double))
writer = VectorWriter(output, None, fields, QGis.WKBPoint,
layer.crs())

feats = processing.features(layer)
nFeat = len(feats)
for i, feat in enumerate(feats):
progress.setPercentage(int(100 * i / nFeat))
create_points(feat)

del writer

0 comments on commit 8436027

Please sign in to comment.
You can’t perform that action at this time.