Skip to content

Commit e9423dc

Browse files
committedAug 11, 2016
[processing] Rework centroid algorithm to handle non-polygon layers
The existing polygoncentroids algorithm has been deprecated (and hidden from the toolbox), and a new, generic centroids algorithm added which works with lines and multipoints
1 parent d0faca1 commit e9423dc

18 files changed

+595
-23
lines changed
 

‎python/plugins/processing/algs/help/qgis.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ qgis:buildvirtualvector: >
4444

4545
The output virtual layer will not be open in the current project.
4646

47+
qgis:centroids: >
48+
This algorithm creates a new point layer, with points representing the centroid of the geometries in an input layer.
49+
50+
The attributes associated to each point in the output layer are the same ones associated to the original features.
51+
4752
qgis:checkvalidity:
4853
This algorithm performs a validity check on the geometries of a vector layer.
4954

@@ -306,6 +311,8 @@ qgis:polygoncentroids: >
306311

307312
The attributes associated to each point in the output layer are the same ones associated to the original polygon.
308313

314+
NOTE: This algorithm is deprecated and the generic "centroids" algorithm (which works for line and multi geometry layers) should be used instead.
315+
309316

310317
qgis:polygonfromlayerextent: >
311318
This algorithm takes a vector layer and generate a new one with the minimum bounding box (rectangle with N-S orientation) that covers all the input features.

‎python/plugins/processing/algs/qgis/Centroids.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
from qgis.PyQt.QtGui import QIcon
3131

32-
from qgis.core import Qgis, QgsGeometry, QgsFeature, QgsWkbTypes
32+
from qgis.core import QgsWkbTypes
3333

3434
from processing.core.GeoAlgorithm import GeoAlgorithm
35-
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
35+
from processing.core.ProcessingLog import ProcessingLog
3636
from processing.core.parameters import ParameterVector
3737
from processing.core.outputs import OutputVector
3838
from processing.tools import dataobjects, vector
@@ -49,11 +49,11 @@ def getIcon(self):
4949
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'centroids.png'))
5050

5151
def defineCharacteristics(self):
52-
self.name, self.i18n_name = self.trAlgorithm('Polygon centroids')
52+
self.name, self.i18n_name = self.trAlgorithm('Centroids')
5353
self.group, self.i18n_group = self.trAlgorithm('Vector geometry tools')
5454

5555
self.addParameter(ParameterVector(self.INPUT_LAYER,
56-
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_POLYGON]))
56+
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_ANY]))
5757

5858
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Centroids')))
5959

@@ -67,25 +67,18 @@ def processAlgorithm(self, progress):
6767
QgsWkbTypes.Point,
6868
layer.crs())
6969

70-
outFeat = QgsFeature()
71-
7270
features = vector.features(layer)
7371
total = 100.0 / len(features)
74-
for current, feat in enumerate(features):
75-
inGeom = feat.geometry()
76-
attrs = feat.attributes()
77-
78-
if inGeom.isEmpty():
79-
outGeom = QgsGeometry(None)
80-
else:
81-
outGeom = QgsGeometry(inGeom.centroid())
82-
if not outGeom:
83-
raise GeoAlgorithmExecutionException(
84-
self.tr('Error calculating centroid'))
85-
86-
outFeat.setGeometry(outGeom)
87-
outFeat.setAttributes(attrs)
88-
writer.addFeature(outFeat)
72+
for current, input_feature in enumerate(features):
73+
output_feature = input_feature
74+
if input_feature.geometry():
75+
output_geometry = input_feature.geometry().centroid()
76+
if not output_geometry:
77+
ProcessingLog.addToLog(ProcessingLog.LOG_WARNING,
78+
'Error calculating centroid for feature {}'.format(input_feature.id()))
79+
output_feature.setGeometry(output_geometry)
80+
81+
writer.addFeature(output_feature)
8982
progress.setPercentage(int(current * total))
9083

9184
del writer
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
PolygonCentroids.py
6+
---------------------
7+
Date : August 2012
8+
Copyright : (C) 2012 by Victor Olaya
9+
Email : volayaf at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Victor Olaya'
21+
__date__ = 'August 2012'
22+
__copyright__ = '(C) 2012, Victor Olaya'
23+
24+
# This will get replaced with a git SHA1 when you do a git archive323
25+
26+
__revision__ = '$Format:%H$'
27+
28+
import os
29+
30+
from qgis.PyQt.QtGui import QIcon
31+
32+
from qgis.core import Qgis, QgsGeometry, QgsFeature, QgsWkbTypes
33+
34+
from processing.core.GeoAlgorithm import GeoAlgorithm
35+
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
36+
from processing.core.parameters import ParameterVector
37+
from processing.core.outputs import OutputVector
38+
from processing.tools import dataobjects, vector
39+
40+
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
41+
42+
43+
class PolygonCentroids(GeoAlgorithm):
44+
45+
INPUT_LAYER = 'INPUT_LAYER'
46+
OUTPUT_LAYER = 'OUTPUT_LAYER'
47+
48+
def __init__(self):
49+
GeoAlgorithm.__init__(self)
50+
# this algorithm is deprecated - use Centroids instead
51+
self.showInToolbox = False
52+
53+
def getIcon(self):
54+
return QIcon(os.path.join(pluginPath, 'images', 'ftools', 'centroids.png'))
55+
56+
def defineCharacteristics(self):
57+
self.name, self.i18n_name = self.trAlgorithm('Polygon centroids')
58+
self.group, self.i18n_group = self.trAlgorithm('Vector geometry tools')
59+
60+
self.addParameter(ParameterVector(self.INPUT_LAYER,
61+
self.tr('Input layer'), [ParameterVector.VECTOR_TYPE_POLYGON]))
62+
63+
self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Centroids')))
64+
65+
def processAlgorithm(self, progress):
66+
layer = dataobjects.getObjectFromUri(
67+
self.getParameterValue(self.INPUT_LAYER))
68+
69+
writer = self.getOutputFromName(
70+
self.OUTPUT_LAYER).getVectorWriter(
71+
layer.fields(),
72+
QgsWkbTypes.Point,
73+
layer.crs())
74+
75+
outFeat = QgsFeature()
76+
77+
features = vector.features(layer)
78+
total = 100.0 / len(features)
79+
for current, feat in enumerate(features):
80+
inGeom = feat.geometry()
81+
attrs = feat.attributes()
82+
83+
if inGeom.isEmpty():
84+
outGeom = QgsGeometry(None)
85+
else:
86+
outGeom = QgsGeometry(inGeom.centroid())
87+
if not outGeom:
88+
raise GeoAlgorithmExecutionException(
89+
self.tr('Error calculating centroid'))
90+
91+
outFeat.setGeometry(outGeom)
92+
outFeat.setAttributes(attrs)
93+
writer.addFeature(outFeat)
94+
progress.setPercentage(int(current * total))
95+
96+
del writer

‎python/plugins/processing/algs/qgis/QGISAlgorithmProvider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
from .Boundary import Boundary
152152
from .PointOnSurface import PointOnSurface
153153
from .OffsetLine import OffsetLine
154+
from .PolygonCentroids import PolygonCentroids
154155

155156
pluginPath = os.path.normpath(os.path.join(
156157
os.path.split(os.path.dirname(__file__))[0], os.pardir))
@@ -204,7 +205,7 @@ def __init__(self):
204205
RectanglesOvalsDiamondsVariable(),
205206
RectanglesOvalsDiamondsFixed(), MergeLines(),
206207
BoundingBox(), Boundary(), PointOnSurface(),
207-
OffsetLine()
208+
OffsetLine(), PolygonCentroids()
208209
]
209210

210211
if hasMatplotlib:

‎python/plugins/processing/gui/menus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
geometryToolsMenu = vectorMenu + "/" + Processing.tr('G&eometry Tools')
5353
defaultMenuEntries.update({'qgis:checkvalidity': geometryToolsMenu,
5454
'qgis:exportaddgeometrycolumns': geometryToolsMenu,
55-
'qgis:polygoncentroids': geometryToolsMenu,
55+
'qgis:centroids': geometryToolsMenu,
5656
'qgis:delaunaytriangulation': geometryToolsMenu,
5757
'qgis:voronoipolygons': geometryToolsMenu,
5858
'qgis:simplifygeometries': geometryToolsMenu,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>centroid_lines</Name>
4+
<ElementPath>centroid_lines</ElementPath>
5+
<GeometryType>1</GeometryType>
6+
<SRSName>EPSG:4326</SRSName>
7+
<DatasetSpecificInfo>
8+
<FeatureCount>7</FeatureCount>
9+
<ExtentXMin>0.00000</ExtentXMin>
10+
<ExtentXMax>8.75520</ExtentXMax>
11+
<ExtentYMin>-3.00000</ExtentYMin>
12+
<ExtentYMax>2.90165</ExtentYMax>
13+
</DatasetSpecificInfo>
14+
</GMLFeatureClass>
15+
</GMLFeatureClassList>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation=""
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0</gml:X><gml:Y>-3</gml:Y></gml:coord>
10+
<gml:coord><gml:X>8.755203820042828</gml:X><gml:Y>2.901650429449553</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:centroid_lines fid="lines.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8.755203820042828,2.901650429449553</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
</ogr:centroid_lines>
18+
</gml:featureMember>
19+
<gml:featureMember>
20+
<ogr:centroid_lines fid="lines.1">
21+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
22+
</ogr:centroid_lines>
23+
</gml:featureMember>
24+
<gml:featureMember>
25+
<ogr:centroid_lines fid="lines.2">
26+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.375,1.625</gml:coordinates></gml:Point></ogr:geometryProperty>
27+
</ogr:centroid_lines>
28+
</gml:featureMember>
29+
<gml:featureMember>
30+
<ogr:centroid_lines fid="lines.3">
31+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geometryProperty>
32+
</ogr:centroid_lines>
33+
</gml:featureMember>
34+
<gml:featureMember>
35+
<ogr:centroid_lines fid="lines.4">
36+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8.5,-3.0</gml:coordinates></gml:Point></ogr:geometryProperty>
37+
</ogr:centroid_lines>
38+
</gml:featureMember>
39+
<gml:featureMember>
40+
<ogr:centroid_lines fid="lines.5">
41+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
42+
</ogr:centroid_lines>
43+
</gml:featureMember>
44+
<gml:featureMember>
45+
<ogr:centroid_lines fid="lines.6">
46+
</ogr:centroid_lines>
47+
</gml:featureMember>
48+
</ogr:FeatureCollection>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>centroid_multilines</Name>
4+
<ElementPath>centroid_multilines</ElementPath>
5+
<GeometryType>1</GeometryType>
6+
<SRSName>EPSG:4326</SRSName>
7+
<DatasetSpecificInfo>
8+
<FeatureCount>4</FeatureCount>
9+
<ExtentXMin>0.00000</ExtentXMin>
10+
<ExtentXMax>4.41936</ExtentXMax>
11+
<ExtentYMin>-1.00000</ExtentYMin>
12+
<ExtentYMax>2.68756</ExtentYMax>
13+
</DatasetSpecificInfo>
14+
</GMLFeatureClass>
15+
</GMLFeatureClassList>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation=""
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0</gml:X><gml:Y>-1</gml:Y></gml:coord>
10+
<gml:coord><gml:X>4.41935638121706</gml:X><gml:Y>2.687560818469874</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:centroid_multilines fid="lines.1">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
</ogr:centroid_multilines>
18+
</gml:featureMember>
19+
<gml:featureMember>
20+
<ogr:centroid_multilines fid="lines.2">
21+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.41935638121706,1.293104104489945</gml:coordinates></gml:Point></ogr:geometryProperty>
22+
</ogr:centroid_multilines>
23+
</gml:featureMember>
24+
<gml:featureMember>
25+
<ogr:centroid_multilines fid="lines.3">
26+
</ogr:centroid_multilines>
27+
</gml:featureMember>
28+
<gml:featureMember>
29+
<ogr:centroid_multilines fid="lines.4">
30+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.423678244400056,2.687560818469874</gml:coordinates></gml:Point></ogr:geometryProperty>
31+
</ogr:centroid_multilines>
32+
</gml:featureMember>
33+
</ogr:FeatureCollection>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>centroid_multipoint</Name>
4+
<ElementPath>centroid_multipoint</ElementPath>
5+
<SRSName>EPSG:4326</SRSName>
6+
<DatasetSpecificInfo>
7+
<FeatureCount>5</FeatureCount>
8+
<ExtentXMin>2.00000</ExtentXMin>
9+
<ExtentXMax>4.50000</ExtentXMax>
10+
<ExtentYMin>-3.00000</ExtentYMin>
11+
<ExtentYMax>2.00000</ExtentYMax>
12+
</DatasetSpecificInfo>
13+
<PropertyDefn>
14+
<Name>d</Name>
15+
<ElementPath>d</ElementPath>
16+
<Type>Integer</Type>
17+
</PropertyDefn>
18+
</GMLFeatureClass>
19+
</GMLFeatureClassList>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation=""
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>2</gml:X><gml:Y>-3</gml:Y></gml:coord>
10+
<gml:coord><gml:X>4.5</gml:X><gml:Y>2</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:centroid_multipoint fid="points.9">
16+
<ogr:d>5</ogr:d>
17+
</ogr:centroid_multipoint>
18+
</gml:featureMember>
19+
<gml:featureMember>
20+
<ogr:centroid_multipoint fid="points.0">
21+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
22+
<ogr:d>1</ogr:d>
23+
</ogr:centroid_multipoint>
24+
</gml:featureMember>
25+
<gml:featureMember>
26+
<ogr:centroid_multipoint fid="points.3">
27+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.5,1.5</gml:coordinates></gml:Point></ogr:geometryProperty>
28+
<ogr:d>2</ogr:d>
29+
</ogr:centroid_multipoint>
30+
</gml:featureMember>
31+
<gml:featureMember>
32+
<ogr:centroid_multipoint fid="points.5">
33+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,-3</gml:coordinates></gml:Point></ogr:geometryProperty>
34+
<ogr:d>3</ogr:d>
35+
</ogr:centroid_multipoint>
36+
</gml:featureMember>
37+
<gml:featureMember>
38+
<ogr:centroid_multipoint fid="points.7">
39+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.5,-1.0</gml:coordinates></gml:Point></ogr:geometryProperty>
40+
<ogr:d>4</ogr:d>
41+
</ogr:centroid_multipoint>
42+
</gml:featureMember>
43+
</ogr:FeatureCollection>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>centroid_multipolys</Name>
4+
<ElementPath>centroid_multipolys</ElementPath>
5+
<GeometryType>1</GeometryType>
6+
<SRSName>EPSG:4326</SRSName>
7+
<DatasetSpecificInfo>
8+
<FeatureCount>4</FeatureCount>
9+
<ExtentXMin>0.50000</ExtentXMin>
10+
<ExtentXMax>7.68889</ExtentXMax>
11+
<ExtentYMin>0.50000</ExtentYMin>
12+
<ExtentYMax>2.91111</ExtentYMax>
13+
</DatasetSpecificInfo>
14+
<PropertyDefn>
15+
<Name>Bname</Name>
16+
<ElementPath>Bname</ElementPath>
17+
<Type>String</Type>
18+
<Width>4</Width>
19+
</PropertyDefn>
20+
<PropertyDefn>
21+
<Name>Bintval</Name>
22+
<ElementPath>Bintval</ElementPath>
23+
<Type>Integer</Type>
24+
</PropertyDefn>
25+
<PropertyDefn>
26+
<Name>Bfloatval</Name>
27+
<ElementPath>Bfloatval</ElementPath>
28+
<Type>Real</Type>
29+
</PropertyDefn>
30+
</GMLFeatureClass>
31+
</GMLFeatureClassList>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation=""
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0.5</gml:X><gml:Y>0.5</gml:Y></gml:coord>
10+
<gml:coord><gml:X>7.688888888888888</gml:X><gml:Y>2.911111111111111</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:centroid_multipolys fid="multipolys.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3.166666666666667,1.833333333333333</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
<ogr:Bname>Test</ogr:Bname>
18+
<ogr:Bintval>1</ogr:Bintval>
19+
<ogr:Bfloatval>0.123</ogr:Bfloatval>
20+
</ogr:centroid_multipolys>
21+
</gml:featureMember>
22+
<gml:featureMember>
23+
<ogr:centroid_multipolys fid="multipolys.1">
24+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7.688888888888888,2.911111111111111</gml:coordinates></gml:Point></ogr:geometryProperty>
25+
</ogr:centroid_multipolys>
26+
</gml:featureMember>
27+
<gml:featureMember>
28+
<ogr:centroid_multipolys fid="multipolys.2">
29+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.5,0.5</gml:coordinates></gml:Point></ogr:geometryProperty>
30+
<ogr:Bname>Test</ogr:Bname>
31+
<ogr:Bintval>2</ogr:Bintval>
32+
<ogr:Bfloatval>-0.123</ogr:Bfloatval>
33+
</ogr:centroid_multipolys>
34+
</gml:featureMember>
35+
<gml:featureMember>
36+
<ogr:centroid_multipolys fid="multipolys.3">
37+
<ogr:Bname>Test</ogr:Bname>
38+
<ogr:Bintval>3</ogr:Bintval>
39+
<ogr:Bfloatval>0</ogr:Bfloatval>
40+
</ogr:centroid_multipolys>
41+
</gml:featureMember>
42+
</ogr:FeatureCollection>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>centroid_points</Name>
4+
<ElementPath>centroid_points</ElementPath>
5+
<GeometryType>1</GeometryType>
6+
<SRSName>EPSG:4326</SRSName>
7+
<DatasetSpecificInfo>
8+
<FeatureCount>9</FeatureCount>
9+
<ExtentXMin>0.00000</ExtentXMin>
10+
<ExtentXMax>8.00000</ExtentXMax>
11+
<ExtentYMin>-5.00000</ExtentYMin>
12+
<ExtentYMax>3.00000</ExtentYMax>
13+
</DatasetSpecificInfo>
14+
</GMLFeatureClass>
15+
</GMLFeatureClassList>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation=""
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0</gml:X><gml:Y>-5</gml:Y></gml:coord>
10+
<gml:coord><gml:X>8</gml:X><gml:Y>3</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:centroid_points fid="points.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1,1</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
</ogr:centroid_points>
18+
</gml:featureMember>
19+
<gml:featureMember>
20+
<ogr:centroid_points fid="points.1">
21+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>3,3</gml:coordinates></gml:Point></ogr:geometryProperty>
22+
</ogr:centroid_points>
23+
</gml:featureMember>
24+
<gml:featureMember>
25+
<ogr:centroid_points fid="points.2">
26+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2,2</gml:coordinates></gml:Point></ogr:geometryProperty>
27+
</ogr:centroid_points>
28+
</gml:featureMember>
29+
<gml:featureMember>
30+
<ogr:centroid_points fid="points.3">
31+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5,2</gml:coordinates></gml:Point></ogr:geometryProperty>
32+
</ogr:centroid_points>
33+
</gml:featureMember>
34+
<gml:featureMember>
35+
<ogr:centroid_points fid="points.4">
36+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4,1</gml:coordinates></gml:Point></ogr:geometryProperty>
37+
</ogr:centroid_points>
38+
</gml:featureMember>
39+
<gml:featureMember>
40+
<ogr:centroid_points fid="points.5">
41+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-5</gml:coordinates></gml:Point></ogr:geometryProperty>
42+
</ogr:centroid_points>
43+
</gml:featureMember>
44+
<gml:featureMember>
45+
<ogr:centroid_points fid="points.6">
46+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
47+
</ogr:centroid_points>
48+
</gml:featureMember>
49+
<gml:featureMember>
50+
<ogr:centroid_points fid="points.7">
51+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
52+
</ogr:centroid_points>
53+
</gml:featureMember>
54+
<gml:featureMember>
55+
<ogr:centroid_points fid="points.8">
56+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
57+
</ogr:centroid_points>
58+
</gml:featureMember>
59+
</ogr:FeatureCollection>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>centroid_polys</Name>
4+
<ElementPath>centroid_polys</ElementPath>
5+
<GeometryType>1</GeometryType>
6+
<SRSName>EPSG:4326</SRSName>
7+
<DatasetSpecificInfo>
8+
<FeatureCount>6</FeatureCount>
9+
<ExtentXMin>0.65385</ExtentXMin>
10+
<ExtentXMax>8.00000</ExtentXMax>
11+
<ExtentYMin>-1.00000</ExtentYMin>
12+
<ExtentYMax>5.50000</ExtentYMax>
13+
</DatasetSpecificInfo>
14+
<PropertyDefn>
15+
<Name>name</Name>
16+
<ElementPath>name</ElementPath>
17+
<Type>String</Type>
18+
<Width>5</Width>
19+
</PropertyDefn>
20+
<PropertyDefn>
21+
<Name>intval</Name>
22+
<ElementPath>intval</ElementPath>
23+
<Type>Integer</Type>
24+
</PropertyDefn>
25+
<PropertyDefn>
26+
<Name>floatval</Name>
27+
<ElementPath>floatval</ElementPath>
28+
<Type>Real</Type>
29+
</PropertyDefn>
30+
</GMLFeatureClass>
31+
</GMLFeatureClassList>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation=""
5+
xmlns:ogr="http://ogr.maptools.org/"
6+
xmlns:gml="http://www.opengis.net/gml">
7+
<gml:boundedBy>
8+
<gml:Box>
9+
<gml:coord><gml:X>0.6538461538461539</gml:X><gml:Y>-1</gml:Y></gml:coord>
10+
<gml:coord><gml:X>8</gml:X><gml:Y>5.5</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:centroid_polys fid="polys.0">
16+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.653846153846154,1.115384615384615</gml:coordinates></gml:Point></ogr:geometryProperty>
17+
<ogr:name>aaaaa</ogr:name>
18+
<ogr:intval>33</ogr:intval>
19+
<ogr:floatval>44.123456</ogr:floatval>
20+
</ogr:centroid_polys>
21+
</gml:featureMember>
22+
<gml:featureMember>
23+
<ogr:centroid_polys fid="polys.1">
24+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.0,4.333333333333333</gml:coordinates></gml:Point></ogr:geometryProperty>
25+
<ogr:name>Aaaaa</ogr:name>
26+
<ogr:intval>-33</ogr:intval>
27+
<ogr:floatval>0</ogr:floatval>
28+
</ogr:centroid_polys>
29+
</gml:featureMember>
30+
<gml:featureMember>
31+
<ogr:centroid_polys fid="polys.2">
32+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.5,5.5</gml:coordinates></gml:Point></ogr:geometryProperty>
33+
<ogr:name>bbaaa</ogr:name>
34+
<ogr:floatval>0.123</ogr:floatval>
35+
</ogr:centroid_polys>
36+
</gml:featureMember>
37+
<gml:featureMember>
38+
<ogr:centroid_polys fid="polys.3">
39+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>8,-1</gml:coordinates></gml:Point></ogr:geometryProperty>
40+
<ogr:name>ASDF</ogr:name>
41+
<ogr:intval>0</ogr:intval>
42+
</ogr:centroid_polys>
43+
</gml:featureMember>
44+
<gml:featureMember>
45+
<ogr:centroid_polys fid="polys.4">
46+
<ogr:intval>120</ogr:intval>
47+
<ogr:floatval>-100291.43213</ogr:floatval>
48+
</ogr:centroid_polys>
49+
</gml:featureMember>
50+
<gml:featureMember>
51+
<ogr:centroid_polys fid="polys.5">
52+
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.080459770114943,-0.218390804597701</gml:coordinates></gml:Point></ogr:geometryProperty>
53+
<ogr:name>elim</ogr:name>
54+
<ogr:intval>2</ogr:intval>
55+
<ogr:floatval>3.33</ogr:floatval>
56+
</ogr:centroid_polys>
57+
</gml:featureMember>
58+
</ogr:FeatureCollection>

‎python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,3 +743,69 @@ tests:
743743
name: expected/buffer_lines_square.gml
744744
type: vector
745745

746+
- algorithm: qgis:centroids
747+
name: Test (qgis:centroids)
748+
params:
749+
INPUT_LAYER:
750+
name: lines.gml
751+
type: vector
752+
results:
753+
OUTPUT_LAYER:
754+
name: expected/centroid_lines.gml
755+
type: vector
756+
757+
- algorithm: qgis:centroids
758+
name: Test (qgis:centroids)
759+
params:
760+
INPUT_LAYER:
761+
name: multilines.gml
762+
type: vector
763+
results:
764+
OUTPUT_LAYER:
765+
name: expected/centroid_multilines.gml
766+
type: vector
767+
768+
- algorithm: qgis:centroids
769+
name: Test (qgis:centroids)
770+
params:
771+
INPUT_LAYER:
772+
name: multipoints.gml
773+
type: vector
774+
results:
775+
OUTPUT_LAYER:
776+
name: expected/centroid_multipoint.gml
777+
type: vector
778+
779+
- algorithm: qgis:centroids
780+
name: Test (qgis:centroids)
781+
params:
782+
INPUT_LAYER:
783+
name: multipolys.gml
784+
type: vector
785+
results:
786+
OUTPUT_LAYER:
787+
name: expected/centroid_multipolys.gml
788+
type: vector
789+
790+
- algorithm: qgis:centroids
791+
name: Test (qgis:centroids)
792+
params:
793+
INPUT_LAYER:
794+
name: points.gml
795+
type: vector
796+
results:
797+
OUTPUT_LAYER:
798+
name: expected/centroid_points.gml
799+
type: vector
800+
801+
- algorithm: qgis:centroids
802+
name: Test (qgis:centroids)
803+
params:
804+
INPUT_LAYER:
805+
name: polys.gml
806+
type: vector
807+
results:
808+
OUTPUT_LAYER:
809+
name: expected/centroid_polys.gml
810+
type: vector
811+

0 commit comments

Comments
 (0)
Please sign in to comment.