Skip to content
Permalink
Browse files

[processing] add vertex id details to extract nodes algorithms

  • Loading branch information
nirvn committed Nov 16, 2017
1 parent ee8ef42 commit 793fb6114b5ef9205f4a58f2355396ab20be9b41
@@ -186,7 +186,7 @@ qgis:extractspecificnodes: >

The node indices parameter accepts a comma separated string specifying the indices of the nodes to extract. The first node corresponds to an index of 0, the second node has an index of 1, etc. Negative indices can be used to find nodes at the end of the geometry, e.g., an index of -1 corresponds to the last node, -2 corresponds to the second last node, etc.

Additional fields are added to the nodes indicating the specific node position (e.g., 0, -1, etc), the original node index, distance along the original geometry and bisector angle of node for the original geometry.
Additional fields are added to the nodes indicating the specific node position (e.g., 0, -1, etc), the original node index, the node’s part and its index within the part (as well as its ring for polygons), distance along the original geometry and bisector angle of node for the original geometry.

qgis:fieldcalculator: >
This algorithm computes a new vector layer with the same features of the input layer, but with an additional attribute. The values of this new attribute are computed from each feature using a mathematical formula, based on the properties and attributes of the feature.
@@ -29,6 +29,7 @@
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm

from qgis.core import (QgsWkbTypes,
QgsVertexId,
QgsFeature,
QgsFeatureSink,
QgsGeometry,
@@ -74,9 +75,12 @@ def processAlgorithm(self, parameters, context, feedback):
fields = source.fields()
fields.append(QgsField('node_pos', QVariant.Int))
fields.append(QgsField('node_index', QVariant.Int))
fields.append(QgsField('node_part', QVariant.Int))
if QgsWkbTypes.geometryType(source.wkbType()) == QgsWkbTypes.PolygonGeometry:
fields.append(QgsField('node_part_ring', QVariant.Int))
fields.append(QgsField('node_part_index', QVariant.Int))
fields.append(QgsField('distance', QVariant.Double))
fields.append(QgsField('angle', QVariant.Double))
fields.append(QgsField('NUM_FIELD', QVariant.Int))

wkb_type = QgsWkbTypes.Point
if QgsWkbTypes.hasM(source.wkbType()):
@@ -118,13 +122,19 @@ def processAlgorithm(self, parameters, context, feedback):
if node_index < 0 or node_index >= total_nodes:
continue

(success, vertex_id) = input_geometry.vertexIdFromVertexNr(node_index)

distance = input_geometry.distanceToVertex(node_index)
angle = math.degrees(input_geometry.angleAtVertex(node_index))

output_feature = QgsFeature()
attrs = f.attributes()
attrs.append(node)
attrs.append(node_index)
attrs.append(vertex_id.part)
if QgsWkbTypes.geometryType(source.wkbType()) == QgsWkbTypes.PolygonGeometry:
attrs.append(vertex_id.ring)
attrs.append(vertex_id.vertex)
attrs.append(distance)
attrs.append(angle)
output_feature.setAttributes(attrs)
@@ -11,6 +11,21 @@
<ExtentYMin>-3.00000</ExtentYMin>
<ExtentYMax>5.00000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>node_index</Name>
<ElementPath>node_index</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>node_part</Name>
<ElementPath>node_part</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>node_part_index</Name>
<ElementPath>node_part_index</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>distance</Name>
<ElementPath>distance</ElementPath>
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xsi:schemaLocation="http://ogr.maptools.org/ extract_nodes_lines.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
@@ -15,132 +15,169 @@
<ogr:extract_nodes_lines fid="lines.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>6,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>0</ogr:node_index>
<ogr:distance>0</ogr:distance>
<ogr:angle>90</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>0</ogr:node_part_index>
<ogr:distance>0.00000000000000</ogr:distance>
<ogr:angle>90.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>9,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>1</ogr:node_index>
<ogr:distance>3</ogr:distance>
<ogr:angle>45</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>1</ogr:node_part_index>
<ogr:distance>3.00000000000000</ogr:distance>
<ogr:angle>45.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>9,3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>2</ogr:node_index>
<ogr:distance>4</ogr:distance>
<ogr:angle>22.5</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>2</ogr:node_part_index>
<ogr:distance>4.00000000000000</ogr:distance>
<ogr:angle>22.50000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>11,5</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>3</ogr:node_index>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>3</ogr:node_part_index>
<ogr:distance>6.82842712474619</ogr:distance>
<ogr:angle>45</ogr:angle>
<ogr:angle>45.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-1,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>0</ogr:node_index>
<ogr:distance>0</ogr:distance>
<ogr:angle>90</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>0</ogr:node_part_index>
<ogr:distance>0.00000000000000</ogr:distance>
<ogr:angle>90.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>1</ogr:node_index>
<ogr:distance>2</ogr:distance>
<ogr:angle>90</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>1</ogr:node_part_index>
<ogr:distance>2.00000000000000</ogr:distance>
<ogr:angle>90.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,0</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>0</ogr:node_index>
<ogr:distance>0</ogr:distance>
<ogr:angle>0</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>0</ogr:node_part_index>
<ogr:distance>0.00000000000000</ogr:distance>
<ogr:angle>0.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>1</ogr:node_index>
<ogr:distance>2</ogr:distance>
<ogr:angle>45</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>1</ogr:node_part_index>
<ogr:distance>2.00000000000000</ogr:distance>
<ogr:angle>45.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,2</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>2</ogr:node_index>
<ogr:distance>3</ogr:distance>
<ogr:angle>45</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>2</ogr:node_part_index>
<ogr:distance>3.00000000000000</ogr:distance>
<ogr:angle>45.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>3</ogr:node_index>
<ogr:distance>4</ogr:distance>
<ogr:angle>0</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>3</ogr:node_part_index>
<ogr:distance>4.00000000000000</ogr:distance>
<ogr:angle>0.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>0</ogr:node_index>
<ogr:distance>0</ogr:distance>
<ogr:angle>90</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>0</ogr:node_part_index>
<ogr:distance>0.00000000000000</ogr:distance>
<ogr:angle>90.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>1</ogr:node_index>
<ogr:distance>2</ogr:distance>
<ogr:angle>90</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>1</ogr:node_part_index>
<ogr:distance>2.00000000000000</ogr:distance>
<ogr:angle>90.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>0</ogr:node_index>
<ogr:distance>0</ogr:distance>
<ogr:angle>90</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>0</ogr:node_part_index>
<ogr:distance>0.00000000000000</ogr:distance>
<ogr:angle>90.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>10,-3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>1</ogr:node_index>
<ogr:distance>3</ogr:distance>
<ogr:angle>90</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>1</ogr:node_part_index>
<ogr:distance>3.00000000000000</ogr:distance>
<ogr:angle>90.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>6,-3</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>0</ogr:node_index>
<ogr:distance>0</ogr:distance>
<ogr:angle>45</ogr:angle>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>0</ogr:node_part_index>
<ogr:distance>0.00000000000000</ogr:distance>
<ogr:angle>45.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>10,1</gml:coordinates></gml:Point></ogr:geometryProperty>
<ogr:node_index>1</ogr:node_index>
<ogr:node_part>0</ogr:node_part>
<ogr:node_part_index>1</ogr:node_part_index>
<ogr:distance>5.65685424949238</ogr:distance>
<ogr:angle>45</ogr:angle>
<ogr:angle>45.00000000000000</ogr:angle>
</ogr:extract_nodes_lines>
</gml:featureMember>
<gml:featureMember>
<ogr:extract_nodes_lines fid="lines.6">
<ogr:node_index xsi:nil="true"/>
<ogr:node_part xsi:nil="true"/>
<ogr:node_part_index xsi:nil="true"/>
<ogr:distance xsi:nil="true"/>
<ogr:angle xsi:nil="true"/>
</ogr:extract_nodes_lines>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -11,6 +11,21 @@
<ExtentYMin>-1.00000</ExtentYMin>
<ExtentYMax>4.11977</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>node_index</Name>
<ElementPath>node_index</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>node_part</Name>
<ElementPath>node_part</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>node_part_index</Name>
<ElementPath>node_part_index</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>distance</Name>
<ElementPath>distance</ElementPath>

0 comments on commit 793fb61

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