Skip to content

Commit

Permalink
[processing] Fix multipart to singlepart handling of null geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 2, 2016
1 parent ccfd4c3 commit 0455b66
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 8 deletions.
18 changes: 10 additions & 8 deletions python/plugins/processing/algs/qgis/MultipartToSingleparts.py
Expand Up @@ -63,20 +63,22 @@ def processAlgorithm(self, progress):
writer = self.getOutputFromName(self.OUTPUT).getVectorWriter(
layer.pendingFields().toList(), geomType, layer.crs())

outFeat = QgsFeature()
inGeom = QgsGeometry()

features = vector.features(layer)
total = 100.0 / len(features)
for current, f in enumerate(features):
inGeom = f.geometry()
outFeat = QgsFeature()
attrs = f.attributes()

geometries = self.extractAsSingle(inGeom)
outFeat.setAttributes(attrs)

for g in geometries:
outFeat.setGeometry(g)
inGeom = f.constGeometry()
if inGeom:
geometries = self.extractAsSingle(inGeom)

for g in geometries:
outFeat.setGeometry(g)
writer.addFeature(outFeat)
else:
#input feature with null geometry
writer.addFeature(outFeat)

progress.setPercentage(int(current * total))
Expand Down
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ multi_to_single.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-1</gml:X><gml:Y>-1</gml:Y></gml:coord>
<gml:coord><gml:X>5.58042226487524</gml:X><gml:Y>4.119769673704415</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:multi_to_single fid="lines.1">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>-1,-1 1,-1</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:multi_to_single>
</gml:featureMember>
<gml:featureMember>
<ogr:multi_to_single fid="lines.2">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>3,1 5,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:multi_to_single>
</gml:featureMember>
<gml:featureMember>
<ogr:multi_to_single fid="lines.2">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>5.024184261036468,2.414779270633399 5,1</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:multi_to_single>
</gml:featureMember>
<gml:featureMember>
<ogr:multi_to_single fid="lines.3">
</ogr:multi_to_single>
</gml:featureMember>
<gml:featureMember>
<ogr:multi_to_single fid="lines.4">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>2,0 2,2 3,2 3,3</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:multi_to_single>
</gml:featureMember>
<gml:featureMember>
<ogr:multi_to_single fid="lines.4">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>2.944337811900192,4.04721689059501 5.459500959692898,4.119769673704415</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:multi_to_single>
</gml:featureMember>
<gml:featureMember>
<ogr:multi_to_single fid="lines.4">
<ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>3,3 5.58042226487524,2.946833013435702</gml:coordinates></gml:LineString></ogr:geometryProperty>
</ogr:multi_to_single>
</gml:featureMember>
</ogr:FeatureCollection>
10 changes: 10 additions & 0 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Expand Up @@ -416,4 +416,14 @@ tests:
name: expected/merge_lines.gml
type: vector

- algorithm: qgis:multiparttosingleparts
name: Multiparts to singleparts
params:
INPUT:
name: multilines.gml
type: vector
results:
OUTPUT:
name: expected/multi_to_single.gml
type: vector

0 comments on commit 0455b66

Please sign in to comment.