Skip to content

Commit c445828

Browse files
author
Maximilian Krambach
committed
changed check for validity from isGeosValid() to validateGeometry() in dissolve.py
1 parent 53d40e8 commit c445828

14 files changed

+541
-3
lines changed

python/plugins/processing/algs/qgis/Dissolve.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
from qgis.core import QgsFeature, QgsGeometry
3333

34+
from processing.core.ProcessingLog import ProcessingLog
3435
from processing.core.GeoAlgorithm import GeoAlgorithm
3536
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
3637
from processing.core.parameters import ParameterVector
@@ -86,15 +87,31 @@ def processAlgorithm(self, progress):
8687
if first:
8788
attrs = inFeat.attributes()
8889
tmpInGeom = QgsGeometry(inFeat.geometry())
89-
if tmpInGeom.isGeosEmpty() or not tmpInGeom.isGeosValid():
90+
if tmpInGeom.isGeosEmpty():
91+
continue
92+
errors = tmpInGeom.validateGeometry()
93+
if len(errors) != 0:
94+
for error in errors:
95+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
96+
self.tr('ValidateGeometry() error: One or '
97+
'more input features have invalid '
98+
'geometry: ') + error.what())
9099
continue
91100
outFeat.setGeometry(tmpInGeom)
92101
first = False
93102
else:
94103
tmpInGeom = QgsGeometry(inFeat.geometry())
95-
if tmpInGeom.isGeosEmpty() or not tmpInGeom.isGeosValid():
104+
if tmpInGeom.isGeosEmpty():
96105
continue
97106
tmpOutGeom = QgsGeometry(outFeat.geometry())
107+
errors = tmpInGeom.validateGeometry()
108+
if len(errors) != 0:
109+
for error in errors:
110+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
111+
self.tr('ValidateGeometry() error: One or '
112+
'more input features have invalid '
113+
'geometry: ') + error.what())
114+
continue
98115
try:
99116
tmpOutGeom = QgsGeometry(tmpOutGeom.combine(tmpInGeom))
100117
outFeat.setGeometry(tmpOutGeom)
@@ -119,8 +136,15 @@ def processAlgorithm(self, progress):
119136
attrs = inFeat.attributes()
120137
tempItem = attrs[fieldIdx]
121138
tmpInGeom = QgsGeometry(inFeat.geometry())
122-
if tmpInGeom.isGeosEmpty() or not tmpInGeom.isGeosValid():
139+
if tmpInGeom.isGeosEmpty():
123140
continue
141+
errors = tmpInGeom.validateGeometry()
142+
if len(errors) != 0:
143+
for error in errors:
144+
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
145+
self.tr('ValidateGeometry() error: One or '
146+
'more input features have invalid '
147+
'geometry: ') + error.what())
124148

125149
if attrDict[unicode(tempItem).strip()] is None:
126150
# keep attributes of first feature
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>PolygonDissolveTest</Name>
4+
<ElementPath>PolygonDissolveTest</ElementPath>
5+
<SRSName>EPSG:3003</SRSName>
6+
<DatasetSpecificInfo>
7+
<FeatureCount>5</FeatureCount>
8+
<ExtentXMin>1754260.45566</ExtentXMin>
9+
<ExtentXMax>1757508.42502</ExtentXMax>
10+
<ExtentYMin>5078929.55554</ExtentYMin>
11+
<ExtentYMax>5080666.09361</ExtentYMax>
12+
</DatasetSpecificInfo>
13+
</GMLFeatureClass>
14+
</GMLFeatureClassList>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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>1754260.455664067</gml:X><gml:Y>5078929.555537455</gml:Y></gml:coord>
10+
<gml:coord><gml:X>1757508.425015694</gml:X><gml:Y>5080666.093606642</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.0">
16+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3003"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1754299.045398937771097,5080010.068113837391138 1754260.45566406683065,5078929.555537454783916 1755411.716087712906301,5078993.87176223937422 1755450.305822583613917,5080010.068113837391138 1754299.045398937771097,5080010.068113837391138</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>1754684.942747645778582,5079585.581030257977545 1754665.647880210541189,5079263.999906335026026 1755135.156321138609201,5079263.999906335026026 1755141.587943617254496,5079643.465632564388216 1754684.942747645778582,5079585.581030257977545</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1755450.305822583613917,5080010.068113837391138 1756402.185949397273362,5080010.068113837391138 1756389.322704440215603,5080640.36711672693491 1755456.737445062259212,5080640.36711672693491 1755450.305822583613917,5080010.068113837391138</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
17+
</ogr:PolygonDissolveTest>
18+
</gml:featureMember>
19+
<gml:featureMember>
20+
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.1">
21+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:3003"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1755450.305822583613917,5080010.068113837391138 1755411.716087712906301,5078993.87176223937422 1756337.869724612450227,5078974.576894803903997 1756402.185949397273362,5080010.068113837391138 1755958.403998382855207,5079984.341623923741281 1755778.318568985676393,5079727.076724784448743 1756164.215917693683878,5079637.034010086208582 1755849.066416248911992,5079958.615134009160101 1755450.305822583613917,5080010.068113837391138</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>1755887.656151119619608,5079373.33748846873641 1755868.361283684149384,5079109.640966851264238 1756074.173202995210886,5079103.209344373084605 1756080.60482547362335,5079309.021263684146106 1755887.656151119619608,5079373.33748846873641</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></ogr:geometryProperty>
22+
</ogr:PolygonDissolveTest>
23+
</gml:featureMember>
24+
<gml:featureMember>
25+
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.2">
26+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:3003"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1756337.869724612450227,5078974.576894803903997 1756402.185949397273362,5080010.068113837391138 1757399.087433559820056,5080003.636491358280182 1757289.749851425876841,5078981.008517282083631 1756337.869724612450227,5078974.576894803903997</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
27+
</ogr:PolygonDissolveTest>
28+
</gml:featureMember>
29+
<gml:featureMember>
30+
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.3">
31+
<ogr:geometryProperty><gml:Polygon srsName="EPSG:3003"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1755450.305822583613917,5080010.068113837391138 1755456.737445062259212,5080640.36711672693491 1754318.34026637300849,5080666.093606641516089 1754299.045398937771097,5080010.068113837391138 1755450.305822583613917,5080010.068113837391138</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>1754774.985462344484404,5080447.418442373163998 1754762.122217387426645,5080260.90139049757272 1754935.776024306192994,5080254.469768019393086 1754942.207646784605458,5080402.397085024043918 1754774.985462344484404,5080447.418442373163998</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></ogr:geometryProperty>
32+
</ogr:PolygonDissolveTest>
33+
</gml:featureMember>
34+
<gml:featureMember>
35+
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.4">
36+
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:3003"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1756402.185949397273362,5080010.068113837391138 1756389.322704440215603,5080640.36711672693491 1757341.202831253642216,5080633.935494248755276 1757399.087433559820056,5080003.636491358280182 1756402.185949397273362,5080010.068113837391138</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1757476.266903301468119,5080350.944105195812881 1757193.275514248991385,5080344.512482717633247 1757173.980646813521162,5080106.542451013810933 1757508.425015693763271,5080125.837318449281156 1757476.266903301468119,5080350.944105195812881</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
37+
</ogr:PolygonDissolveTest>
38+
</gml:featureMember>
39+
</ogr:FeatureCollection>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<GMLFeatureClassList>
2+
<GMLFeatureClass>
3+
<Name>innerRingTouchesOuterRing</Name>
4+
<ElementPath>innerRingTouchesOuterRing</ElementPath>
5+
<!--MULTIPOLYGON-->
6+
<GeometryType>6</GeometryType>
7+
<SRSName>EPSG:3003</SRSName>
8+
<DatasetSpecificInfo>
9+
<FeatureCount>19</FeatureCount>
10+
<ExtentXMin>1754447.79750</ExtentXMin>
11+
<ExtentXMax>1757996.40354</ExtentXMax>
12+
<ExtentYMin>5078658.22018</ExtentYMin>
13+
<ExtentYMax>5080667.30082</ExtentYMax>
14+
</DatasetSpecificInfo>
15+
<PropertyDefn>
16+
<Name>DN</Name>
17+
<ElementPath>DN</ElementPath>
18+
<Type>Integer</Type>
19+
</PropertyDefn>
20+
<PropertyDefn>
21+
<Name>AREA</Name>
22+
<ElementPath>AREA</ElementPath>
23+
<Type>Real</Type>
24+
</PropertyDefn>
25+
<PropertyDefn>
26+
<Name>PERIMETER</Name>
27+
<ElementPath>PERIMETER</ElementPath>
28+
<Type>Real</Type>
29+
</PropertyDefn>
30+
<PropertyDefn>
31+
<Name>area2</Name>
32+
<ElementPath>area2</ElementPath>
33+
<Type>Real</Type>
34+
</PropertyDefn>
35+
</GMLFeatureClass>
36+
</GMLFeatureClassList>

0 commit comments

Comments
 (0)