Skip to content
Permalink
Browse files
[processing] handle NULL values in the Singleparts to multiparts (fix #…
  • Loading branch information
alexbruy committed Apr 30, 2017
1 parent 3f66914 commit a944f7c4c1010767abb811200686e327040c2d32
@@ -30,7 +30,7 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils
from qgis.core import QgsFeature, QgsGeometry, QgsWkbTypes, QgsProcessingUtils, NULL

from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.parameters import ParameterVector
@@ -88,6 +88,13 @@ def processAlgorithm(self, context, feedback):
for current, feature in enumerate(features):
atMap = feature.attributes()
idVar = atMap[index]
if idVar in [None, NULL]:
outFeat.setAttributes(atMap)
outFeat.setGeometry(feature.geometry())
writer.addFeature(outFeat)
feedback.setProgress(int(current * total))
continue

key = str(idVar).strip()
if key not in collection_geom:
collection_geom[key] = []
@@ -6,50 +6,49 @@
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>0.2101967462686566</gml:X><gml:Y>-5.482323358208955</gml:Y></gml:coord>
<gml:coord><gml:X>8.962880985074626</gml:X><gml:Y>7.163993643533122</gml:Y></gml:coord>
<gml:coord><gml:X>0.210196746268657</gml:X><gml:Y>-5.48232335820895</gml:Y></gml:coord>
<gml:coord><gml:X>8.96288098507463</gml:X><gml:Y>7.16399364353312</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:single_part_poly fid="single_part_poly.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.80194134384858,7.16399364353312 0.672499728706625,4.76932376340694 5.20295625867508,4.2839177066246 5.26276665671642,6.74081294029851 0.80194134384858,7.16399364353312</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.80194134384858,7.16399364353312 5.26276665671642,6.74081294029851 5.20295625867508,4.2839177066246 0.672499728706625,4.76932376340694 0.80194134384858,7.16399364353312</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>1</ogr:id>
</ogr:single_part_poly>
</gml:featureMember>
<gml:featureMember>
<ogr:single_part_poly fid="single_part_poly.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.30900588059701,4.21452798507463 6.00278952238806,2.60689210447761 8.4525203880597,1.81583317910448 8.96288098507463,4.26556404477612 8.24837614925373,7.04702929850746 6.30900588059701,4.21452798507463</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.30900588059701,4.21452798507463 8.24837614925373,7.04702929850746 8.96288098507463,4.26556404477612 8.4525203880597,1.81583317910448 6.00278952238806,2.60689210447761 6.30900588059701,4.21452798507463</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>1</ogr:id>
</ogr:single_part_poly>
</gml:featureMember>
<gml:featureMember>
<ogr:single_part_poly fid="single_part_poly.2">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3.96134713432836,1.68824302985075 3.93582910447761,-1.14425828358209 8.27389417910448,-1.50151070149254 8.120786,0.64200380597015 3.96134713432836,1.68824302985075</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>1</ogr:id>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3.96134713432836,1.68824302985075 8.120786,0.64200380597015 8.27389417910448,-1.50151070149254 3.93582910447761,-1.14425828358209 3.96134713432836,1.68824302985075</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
</ogr:single_part_poly>
</gml:featureMember>
<gml:featureMember>
<ogr:single_part_poly fid="single_part_poly.3">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.69024247761194,3.0406986119403 1.9454227761194,1.48409879104478 3.47650456716418,2.47930195522388 3.45098653731343,3.52554117910448 1.69024247761194,3.0406986119403</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.69024247761194,3.0406986119403 3.45098653731343,3.52554117910448 3.47650456716418,2.47930195522388 1.9454227761194,1.48409879104478 1.69024247761194,3.0406986119403</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>2</ogr:id>
</ogr:single_part_poly>
</gml:featureMember>
<gml:featureMember>
<ogr:single_part_poly fid="single_part_poly.4">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.46058020895522,-2.93052037313433 2.40474731343284,-5.48232335820895 6.02830755223881,-4.35953004477612 6.411078,-2.57326795522388 1.46058020895522,-2.93052037313433</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.46058020895522,-2.93052037313433 6.411078,-2.57326795522388 6.02830755223881,-4.35953004477612 2.40474731343284,-5.48232335820895 1.46058020895522,-2.93052037313433</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>2</ogr:id>
</ogr:single_part_poly>
</gml:featureMember>
<gml:featureMember>
<ogr:single_part_poly fid="single_part_poly.5">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.592967194029851,-0.17457314925373 1.58817035820896,-2.06290735820895 2.37922928358209,-1.3739205522388 2.63440958208955,0.284751388059703 0.592967194029851,-0.17457314925373</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.592967194029851,-0.17457314925373 2.63440958208955,0.284751388059703 2.37922928358209,-1.3739205522388 1.58817035820896,-2.06290735820895 0.592967194029851,-0.17457314925373</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>3</ogr:id>
</ogr:single_part_poly>
</gml:featureMember>
<gml:featureMember>
<ogr:single_part_poly fid="single_part_poly.6">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.210196746268657,2.19860362686567 0.439859014925373,1.05029228358209 1.15436385074627,1.02477425373134 0.720557343283582,4.0359017761194 0.210196746268657,2.19860362686567</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.210196746268657,2.19860362686567 0.720557343283582,4.0359017761194 1.15436385074627,1.02477425373134 0.439859014925373,1.05029228358209 0.210196746268657,2.19860362686567</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id>4</ogr:id>
</ogr:single_part_poly>
</gml:featureMember>
@@ -12,27 +12,32 @@
</gml:boundedBy>

<gml:featureMember>
<ogr:single_to_multi fid="single_part_poly.6">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.210196746268657,2.19860362686567 0.439859014925373,1.05029228358209 1.15436385074627,1.02477425373134 0.720557343283582,4.0359017761194 0.210196746268657,2.19860362686567</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:id>4</ogr:id>
</ogr:single_to_multi>
</gml:featureMember>
<gml:featureMember>
<ogr:single_to_multi fid="single_part_poly.0">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.80194134384858,7.16399364353312 0.672499728706625,4.76932376340694 5.20295625867508,4.2839177066246 5.26276665671642,6.74081294029851 0.80194134384858,7.16399364353312</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.30900588059701,4.21452798507463 6.00278952238806,2.60689210447761 8.4525203880597,1.81583317910448 8.96288098507463,4.26556404477612 8.24837614925373,7.04702929850746 6.30900588059701,4.21452798507463</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3.96134713432836,1.68824302985075 3.93582910447761,-1.14425828358209 8.27389417910448,-1.50151070149254 8.120786,0.64200380597015 3.96134713432836,1.68824302985075</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:id>1</ogr:id>
<ogr:single_to_multi fid="single_part_poly.2">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3.96134713432836,1.68824302985075 8.120786,0.64200380597015 8.27389417910448,-1.50151070149254 3.93582910447761,-1.14425828358209 3.96134713432836,1.68824302985075</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
</ogr:single_to_multi>
</gml:featureMember>
<gml:featureMember>
<ogr:single_to_multi fid="single_part_poly.3">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.69024247761194,3.0406986119403 1.9454227761194,1.48409879104478 3.47650456716418,2.47930195522388 3.45098653731343,3.52554117910448 1.69024247761194,3.0406986119403</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.46058020895522,-2.93052037313433 2.40474731343284,-5.48232335820895 6.02830755223881,-4.35953004477612 6.411078,-2.57326795522388 1.46058020895522,-2.93052037313433</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.69024247761194,3.0406986119403 3.45098653731343,3.52554117910448 3.47650456716418,2.47930195522388 1.9454227761194,1.48409879104478 1.69024247761194,3.0406986119403</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1.46058020895522,-2.93052037313433 6.411078,-2.57326795522388 6.02830755223881,-4.35953004477612 2.40474731343284,-5.48232335820895 1.46058020895522,-2.93052037313433</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:id>2</ogr:id>
</ogr:single_to_multi>
</gml:featureMember>
<gml:featureMember>
<ogr:single_to_multi fid="single_part_poly.5">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.592967194029851,-0.17457314925373 1.58817035820896,-2.06290735820895 2.37922928358209,-1.3739205522388 2.63440958208955,0.284751388059703 0.592967194029851,-0.17457314925373</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.592967194029851,-0.17457314925373 2.63440958208955,0.284751388059703 2.37922928358209,-1.3739205522388 1.58817035820896,-2.06290735820895 0.592967194029851,-0.17457314925373</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:id>3</ogr:id>
</ogr:single_to_multi>
</gml:featureMember>
<gml:featureMember>
<ogr:single_to_multi fid="single_part_poly.6">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.210196746268657,2.19860362686567 0.720557343283582,4.0359017761194 1.15436385074627,1.02477425373134 0.439859014925373,1.05029228358209 0.210196746268657,2.19860362686567</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:id>4</ogr:id>
</ogr:single_to_multi>
</gml:featureMember>
<gml:featureMember>
<ogr:single_to_multi fid="single_part_poly.0">
<ogr:geometryProperty><gml:MultiPolygon srsName="EPSG:4326"><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.80194134384858,7.16399364353312 5.26276665671642,6.74081294029851 5.20295625867508,4.2839177066246 0.672499728706625,4.76932376340694 0.80194134384858,7.16399364353312</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember><gml:polygonMember><gml:Polygon><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6.30900588059701,4.21452798507463 8.24837614925373,7.04702929850746 8.96288098507463,4.26556404477612 8.4525203880597,1.81583317910448 6.00278952238806,2.60689210447761 6.30900588059701,4.21452798507463</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></gml:polygonMember></gml:MultiPolygon></ogr:geometryProperty>
<ogr:id>1</ogr:id>
</ogr:single_to_multi>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -2250,7 +2250,7 @@ tests:
type: vector

- algorithm: qgis:singlepartstomultipart
name: single part to multipart
name: single part to multipart (with NULL values)
params:
FIELD: id
INPUT:
@@ -2554,4 +2554,4 @@ tests:
results:
OUTPUT_LAYER:
name: expected/selected_points.gml
type: vector
type: vector

2 comments on commit a944f7c

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids replied Apr 30, 2017

it seems this make ProcessingQgisAlgorithmsTest fail.

@alexbruy

This comment has been minimized.

Copy link
Contributor Author

@alexbruy alexbruy replied Apr 30, 2017

It passes locally, I'm looking what is wrong. Feel free to revert it if necessary

Please sign in to comment.