Skip to content

Commit

Permalink
[processing] nodes -> vertices algorithm renaming
Browse files Browse the repository at this point in the history
- "Extract nodes" renamed to "Extract vertices"
- "Extract specific nodes" renamed to "Extract specific vertices"
  • Loading branch information
nirvn committed Jan 29, 2018
1 parent a420d04 commit e0c12d5
Show file tree
Hide file tree
Showing 24 changed files with 667 additions and 669 deletions.
13 changes: 4 additions & 9 deletions python/plugins/processing/algs/help/qgis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,12 @@ qgis:extractbyexpression: >

For more information about expressions see the <a href ="{qgisdocs}/user_manual/working_with_vector/expression.html">user manual</a>

qgis:extractnodes: >
This algorithm takes a line or polygon layer and generates a point layer with points representing the nodes in the input lines or polygons. The attributes associated to each point are the same ones associated to the line or polygon that the point belongs to.
qgis:extractspecificvertices: >
This algorithm takes a line or polygon layer and generates a point layer with points representing specific vertices in the input lines or polygons. For instance, this algorithm can be used to extract the first or last vertices in the geometry. The attributes associated to each point are the same ones associated to the line or polygon that the point belongs to.

Additional fields are added to the nodes indicating the node index (beginning at 0), distance along original geometry and bisector angle of node for original geometry.
The vertex indices parameter accepts a comma separated string specifying the indices of the vertices to extract. The first vertex corresponds to an index of 0, the second vertex has an index of 1, etc. Negative indices can be used to find vertices at the end of the geometry, e.g., an index of -1 corresponds to the last vertex, -2 corresponds to the second last vertex, etc.

qgis:extractspecificnodes: >
This algorithm takes a line or polygon layer and generates a point layer with points representing specific nodes in the input lines or polygons. For instance, this algorithm can be used to extract the first or last nodes in the geometry. The attributes associated to each point are the same ones associated to the line or polygon that the point belongs to.

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, 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.
Additional fields are added to the points indicating the specific vertex position (e.g., 0, -1, etc), the original vertex index, the vertex’s part and its index within the part (as well as its ring for polygons), distance along the original geometry and bisector angle of vertex 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.
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/DensifyGeometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DensifyGeometries(QgisFeatureBasedAlgorithm):
VERTICES = 'VERTICES'

def tags(self):
return self.tr('add,vertices,points').split(',')
return self.tr('add,vertex,vertices,points,nodes').split(',')

def group(self):
return self.tr('Vector geometry')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class DensifyGeometriesInterval(QgisFeatureBasedAlgorithm):

INTERVAL = 'INTERVAL'

def tags(self):
return self.tr('add,vertex,vertices,points,nodes').split(',')

def group(self):
return self.tr('Vector geometry')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

"""
***************************************************************************
ExtractSpecificNodes.py
ExtractSpecificVertices.py
--------------------
Date : October 2016
Copyright : (C) 2016 by Nyall Dawson
Expand Down Expand Up @@ -42,10 +42,10 @@
from qgis.PyQt.QtCore import QVariant


class ExtractSpecificNodes(QgisAlgorithm):
class ExtractSpecificVertices(QgisAlgorithm):
INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
NODES = 'NODES'
VERTICES = 'VERTICES'

def group(self):
return self.tr('Vector geometry')
Expand All @@ -59,29 +59,29 @@ def __init__(self):
def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterFeatureSource(self.INPUT,
self.tr('Input layer'), [QgsProcessing.TypeVectorAnyGeometry]))
self.addParameter(QgsProcessingParameterString(self.NODES,
self.tr('Node indices'), defaultValue='0'))
self.addParameter(QgsProcessingParameterString(self.VERTICES,
self.tr('Vertex indices'), defaultValue='0'))

self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Nodes'), QgsProcessing.TypeVectorPoint))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Vertices'), QgsProcessing.TypeVectorPoint))

def name(self):
return 'extractspecificnodes'
return 'extractspecificvertices'

def displayName(self):
return self.tr('Extract specific nodes')
return self.tr('Extract specific vertices')

def tags(self):
return self.tr('points,vertex,vertices').split(',')
return self.tr('points,vertex,nodes').split(',')

def processAlgorithm(self, parameters, context, feedback):
source = self.parameterAsSource(parameters, self.INPUT, context)
fields = source.fields()
fields.append(QgsField('node_pos', QVariant.Int))
fields.append(QgsField('node_index', QVariant.Int))
fields.append(QgsField('node_part', QVariant.Int))
fields.append(QgsField('vertex_pos', QVariant.Int))
fields.append(QgsField('vertex_index', QVariant.Int))
fields.append(QgsField('vertex_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('vertex_part_ring', QVariant.Int))
fields.append(QgsField('vertex_part_index', QVariant.Int))
fields.append(QgsField('distance', QVariant.Double))
fields.append(QgsField('angle', QVariant.Double))

Expand All @@ -94,14 +94,14 @@ def processAlgorithm(self, parameters, context, feedback):
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context,
fields, wkb_type, source.sourceCrs())

node_indices_string = self.parameterAsString(parameters, self.NODES, context)
vertex_indices_string = self.parameterAsString(parameters, self.VERTICES, context)
indices = []
for node in node_indices_string.split(','):
for vertex in vertex_indices_string.split(','):
try:
indices.append(int(node))
indices.append(int(vertex))
except:
raise QgsProcessingException(
self.tr('\'{}\' is not a valid node index').format(node))
self.tr('\'{}\' is not a valid vertex index').format(vertex))

features = source.getFeatures()
total = 100.0 / source.featureCount() if source.featureCount() else 0
Expand All @@ -114,26 +114,26 @@ def processAlgorithm(self, parameters, context, feedback):
if not input_geometry:
sink.addFeature(f, QgsFeatureSink.FastInsert)
else:
total_nodes = input_geometry.constGet().nCoordinates()
total_vertices = input_geometry.constGet().nCoordinates()

for node in indices:
if node < 0:
node_index = total_nodes + node
for vertex in indices:
if vertex < 0:
vertex_index = total_vertices + vertex
else:
node_index = node
vertex_index = vertex

if node_index < 0 or node_index >= total_nodes:
if vertex_index < 0 or vertex_index >= total_vertices:
continue

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

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

output_feature = QgsFeature()
attrs = f.attributes()
attrs.append(node)
attrs.append(node_index)
attrs.append(vertex)
attrs.append(vertex_index)
attrs.append(vertex_id.part)
if QgsWkbTypes.geometryType(source.wkbType()) == QgsWkbTypes.PolygonGeometry:
attrs.append(vertex_id.ring)
Expand All @@ -142,7 +142,7 @@ def processAlgorithm(self, parameters, context, feedback):
attrs.append(angle)
output_feature.setAttributes(attrs)

point = input_geometry.vertexAt(node_index)
point = input_geometry.vertexAt(vertex_index)
output_feature.setGeometry(QgsGeometry(point))

sink.addFeature(output_feature, QgsFeatureSink.FastInsert)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/qgis/QgisAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
from .ExportGeometryInfo import ExportGeometryInfo
from .ExtendLines import ExtendLines
from .ExtentFromLayer import ExtentFromLayer
from .ExtractSpecificNodes import ExtractSpecificNodes
from .ExtractSpecificVertices import ExtractSpecificVertices
from .FieldPyculator import FieldsPyculator
from .FieldsCalculator import FieldsCalculator
from .FieldsMapper import FieldsMapper
Expand Down Expand Up @@ -183,7 +183,7 @@ def getAlgs(self):
ExportGeometryInfo(),
ExtendLines(),
ExtentFromLayer(),
ExtractSpecificNodes(),
ExtractSpecificVertices(),
FieldsCalculator(),
FieldsMapper(),
FieldsPyculator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
<ExtentYMax>5.00000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>node_index</Name>
<ElementPath>node_index</ElementPath>
<Name>vertex_index</Name>
<ElementPath>vertex_index</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>node_part</Name>
<ElementPath>node_part</ElementPath>
<Name>vertex_part</Name>
<ElementPath>vertex_part</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>node_part_index</Name>
<ElementPath>node_part_index</ElementPath>
<Name>vertex_part_index</Name>
<ElementPath>vertex_part_index</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
Expand Down

0 comments on commit e0c12d5

Please sign in to comment.