Skip to content
Permalink
Browse files

[processing] write start and end points to output attribute table

  • Loading branch information
alexbruy committed Dec 13, 2016
1 parent aa3c7cc commit 16c92dd1e8cef6ff12c86d463280850b7525b0b3
Showing with 9 additions and 1 deletion.
  1. +9 −1 python/plugins/processing/algs/qgis/ShortestPathPointToPoint.py
@@ -160,16 +160,21 @@ def processAlgorithm(self, progress):
defaultSpeed = self.getParameterValue(self.DEFAULT_SPEED)
tolerance = self.getParameterValue(self.TOLERANCE)

fields = QgsFields()
fields.append(QgsField('start', QVariant.String, '', 254, 0))
fields.append(QgsField('end', QVariant.String, '', 254, 0))

writer = self.getOutputFromName(
self.OUTPUT_LAYER).getVectorWriter(
layer.fields().toList(),
fields.toList(),
QgsWkbTypes.LineString,
layer.crs())

tmp = startPoint.split(',')
startPoint = QgsPoint(float(tmp[0]), float(tmp[1]))
tmp = endPoint.split(',')
endPoint = QgsPoint(float(tmp[0]), float(tmp[1]))

directionField = -1
if directionFieldName is not None:
directionField = layer.fields().lookupField(directionFieldName)
@@ -227,6 +232,9 @@ def processAlgorithm(self, progress):
progress.setInfo(self.tr('Writting results...'))
geom = QgsGeometry.fromPolyline(route)
feat = QgsFeature()
feat.setFields(fields)
feat['start'] = startPoint.toString()
feat['end'] = endPoint.toString()
feat.setGeometry(geom)
writer.addFeature(feat)
del writer

0 comments on commit 16c92dd

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