Skip to content

Commit

Permalink
changed check for validity from isGeosValid() to validateGeometry() i…
Browse files Browse the repository at this point in the history
…n dissolve.py
  • Loading branch information
Maximilian Krambach committed Mar 21, 2016
1 parent 53d40e8 commit c445828
Show file tree
Hide file tree
Showing 14 changed files with 541 additions and 3 deletions.
30 changes: 27 additions & 3 deletions python/plugins/processing/algs/qgis/Dissolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from qgis.core import QgsFeature, QgsGeometry

from processing.core.ProcessingLog import ProcessingLog
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
Expand Down Expand Up @@ -86,15 +87,31 @@ def processAlgorithm(self, progress):
if first:
attrs = inFeat.attributes()
tmpInGeom = QgsGeometry(inFeat.geometry())
if tmpInGeom.isGeosEmpty() or not tmpInGeom.isGeosValid():
if tmpInGeom.isGeosEmpty():
continue
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry() error: One or '
'more input features have invalid '
'geometry: ') + error.what())
continue
outFeat.setGeometry(tmpInGeom)
first = False
else:
tmpInGeom = QgsGeometry(inFeat.geometry())
if tmpInGeom.isGeosEmpty() or not tmpInGeom.isGeosValid():
if tmpInGeom.isGeosEmpty():
continue
tmpOutGeom = QgsGeometry(outFeat.geometry())
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry() error: One or '
'more input features have invalid '
'geometry: ') + error.what())
continue
try:
tmpOutGeom = QgsGeometry(tmpOutGeom.combine(tmpInGeom))
outFeat.setGeometry(tmpOutGeom)
Expand All @@ -119,8 +136,15 @@ def processAlgorithm(self, progress):
attrs = inFeat.attributes()
tempItem = attrs[fieldIdx]
tmpInGeom = QgsGeometry(inFeat.geometry())
if tmpInGeom.isGeosEmpty() or not tmpInGeom.isGeosValid():
if tmpInGeom.isGeosEmpty():
continue
errors = tmpInGeom.validateGeometry()
if len(errors) != 0:
for error in errors:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
self.tr('ValidateGeometry() error: One or '
'more input features have invalid '
'geometry: ') + error.what())

if attrDict[unicode(tempItem).strip()] is None:
# keep attributes of first feature
Expand Down
14 changes: 14 additions & 0 deletions python/plugins/processing/tests/testdata/PolygonDissolveTest.gfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>PolygonDissolveTest</Name>
<ElementPath>PolygonDissolveTest</ElementPath>
<SRSName>EPSG:3003</SRSName>
<DatasetSpecificInfo>
<FeatureCount>5</FeatureCount>
<ExtentXMin>1754260.45566</ExtentXMin>
<ExtentXMax>1757508.42502</ExtentXMax>
<ExtentYMin>5078929.55554</ExtentYMin>
<ExtentYMax>5080666.09361</ExtentYMax>
</DatasetSpecificInfo>
</GMLFeatureClass>
</GMLFeatureClassList>
39 changes: 39 additions & 0 deletions python/plugins/processing/tests/testdata/PolygonDissolveTest.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>1754260.455664067</gml:X><gml:Y>5078929.555537455</gml:Y></gml:coord>
<gml:coord><gml:X>1757508.425015694</gml:X><gml:Y>5080666.093606642</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.0">
<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>
</ogr:PolygonDissolveTest>
</gml:featureMember>
<gml:featureMember>
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.1">
<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>
</ogr:PolygonDissolveTest>
</gml:featureMember>
<gml:featureMember>
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.2">
<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>
</ogr:PolygonDissolveTest>
</gml:featureMember>
<gml:featureMember>
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.3">
<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>
</ogr:PolygonDissolveTest>
</gml:featureMember>
<gml:featureMember>
<ogr:PolygonDissolveTest fid="PolygonDissolveTest.4">
<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>
</ogr:PolygonDissolveTest>
</gml:featureMember>
</ogr:FeatureCollection>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>innerRingTouchesOuterRing</Name>
<ElementPath>innerRingTouchesOuterRing</ElementPath>
<!--MULTIPOLYGON-->
<GeometryType>6</GeometryType>
<SRSName>EPSG:3003</SRSName>
<DatasetSpecificInfo>
<FeatureCount>19</FeatureCount>
<ExtentXMin>1754447.79750</ExtentXMin>
<ExtentXMax>1757996.40354</ExtentXMax>
<ExtentYMin>5078658.22018</ExtentYMin>
<ExtentYMax>5080667.30082</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>DN</Name>
<ElementPath>DN</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>AREA</Name>
<ElementPath>AREA</ElementPath>
<Type>Real</Type>
</PropertyDefn>
<PropertyDefn>
<Name>PERIMETER</Name>
<ElementPath>PERIMETER</ElementPath>
<Type>Real</Type>
</PropertyDefn>
<PropertyDefn>
<Name>area2</Name>
<ElementPath>area2</ElementPath>
<Type>Real</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
Loading

0 comments on commit c445828

Please sign in to comment.