Skip to content

Commit 32f6034

Browse files
alexbruynyalldawson
authored andcommitted
[processing][needs-docs] force multipart output from GDAL-based dissolve
algorithm (fix #20025)
1 parent 7482f7a commit 32f6034

File tree

9 files changed

+97
-15
lines changed

9 files changed

+97
-15
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
142142
arguments = []
143143
arguments.append(output)
144144
arguments.append(ogrLayer)
145+
arguments.append('-nlt PROMOTE_TO_MULTI')
145146
arguments.append('-dialect')
146147
arguments.append('sqlite')
147148
arguments.append('-sql')

python/plugins/processing/tests/GdalAlgorithmsTest.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def testDissolve(self):
693693
['ogr2ogr',
694694
outdir + '/check.shp ' +
695695
source + ' ' +
696-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry FROM \'polys2\'" ' +
696+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry FROM \'polys2\'" ' +
697697
'-f "ESRI Shapefile"'])
698698

699699
self.assertEqual(
@@ -703,7 +703,7 @@ def testDissolve(self):
703703
['ogr2ogr',
704704
outdir + '/check.shp ' +
705705
source + ' ' +
706-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
706+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
707707
'GROUP BY my_field" -f "ESRI Shapefile"'])
708708

709709
self.assertEqual(
@@ -713,7 +713,7 @@ def testDissolve(self):
713713
['ogr2ogr',
714714
outdir + '/check.shp ' +
715715
'"' + source_with_space + '" ' +
716-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'filename_with_spaces\' ' +
716+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'filename_with_spaces\' ' +
717717
'GROUP BY my_field" -f "ESRI Shapefile"'])
718718

719719
self.assertEqual(
@@ -724,7 +724,7 @@ def testDissolve(self):
724724
['ogr2ogr',
725725
outdir + '/check.shp ' +
726726
source + ' ' +
727-
'-dialect sqlite -sql "SELECT ST_Union(the_geom) AS the_geom, my_field FROM \'polys2\' ' +
727+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(the_geom) AS the_geom, my_field FROM \'polys2\' ' +
728728
'GROUP BY my_field" -f "ESRI Shapefile"'])
729729

730730
self.assertEqual(
@@ -735,7 +735,7 @@ def testDissolve(self):
735735
['ogr2ogr',
736736
outdir + '/check.shp ' +
737737
source + ' ' +
738-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
738+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
739739
'GROUP BY my_field" -f "ESRI Shapefile"'])
740740

741741
self.assertEqual(
@@ -745,7 +745,7 @@ def testDissolve(self):
745745
['ogr2ogr',
746746
outdir + '/check.shp ' +
747747
source + ' ' +
748-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry FROM \'polys2\'" ' +
748+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry FROM \'polys2\'" ' +
749749
'-f "ESRI Shapefile"'])
750750

751751
self.assertEqual(
@@ -756,7 +756,7 @@ def testDissolve(self):
756756
['ogr2ogr',
757757
outdir + '/check.shp ' +
758758
source + ' ' +
759-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
759+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
760760
'GROUP BY my_field" -explodecollections -f "ESRI Shapefile"'])
761761

762762
self.assertEqual(
@@ -767,7 +767,7 @@ def testDissolve(self):
767767
['ogr2ogr',
768768
outdir + '/check.shp ' +
769769
source + ' ' +
770-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field, COUNT(geometry) AS count FROM \'polys2\' ' +
770+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field, COUNT(geometry) AS count FROM \'polys2\' ' +
771771
'GROUP BY my_field" -f "ESRI Shapefile"'])
772772

773773
self.assertEqual(
@@ -779,7 +779,7 @@ def testDissolve(self):
779779
['ogr2ogr',
780780
outdir + '/check.shp ' +
781781
source + ' ' +
782-
'-dialect sqlite -sql "SELECT ST_Union(the_geom) AS the_geom, my_field, COUNT(the_geom) AS count FROM \'polys2\' ' +
782+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(the_geom) AS the_geom, my_field, COUNT(the_geom) AS count FROM \'polys2\' ' +
783783
'GROUP BY my_field" -f "ESRI Shapefile"'])
784784

785785
self.assertEqual(
@@ -790,7 +790,7 @@ def testDissolve(self):
790790
['ogr2ogr',
791791
outdir + '/check.shp ' +
792792
source + ' ' +
793-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field, SUM(ST_Area(geometry)) AS area, ' +
793+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field, SUM(ST_Area(geometry)) AS area, ' +
794794
'ST_Perimeter(ST_Union(geometry)) AS perimeter FROM \'polys2\' ' +
795795
'GROUP BY my_field" -f "ESRI Shapefile"'])
796796

@@ -803,7 +803,7 @@ def testDissolve(self):
803803
['ogr2ogr',
804804
outdir + '/check.shp ' +
805805
source + ' ' +
806-
'-dialect sqlite -sql "SELECT ST_Union(the_geom) AS the_geom, my_field, SUM(ST_Area(the_geom)) AS area, ' +
806+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(the_geom) AS the_geom, my_field, SUM(ST_Area(the_geom)) AS area, ' +
807807
'ST_Perimeter(ST_Union(the_geom)) AS perimeter FROM \'polys2\' ' +
808808
'GROUP BY my_field" -f "ESRI Shapefile"'])
809809

@@ -816,7 +816,7 @@ def testDissolve(self):
816816
['ogr2ogr',
817817
outdir + '/check.shp ' +
818818
source + ' ' +
819-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field, ' +
819+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field, ' +
820820
'SUM(my_val) AS sum, MIN(my_val) AS min, MAX(my_val) AS max, AVG(my_val) AS avg FROM \'polys2\' ' +
821821
'GROUP BY my_field" -f "ESRI Shapefile"'])
822822

@@ -829,7 +829,7 @@ def testDissolve(self):
829829
['ogr2ogr',
830830
outdir + '/check.shp ' +
831831
source + ' ' +
832-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
832+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
833833
'GROUP BY my_field" -f "ESRI Shapefile"'])
834834
self.assertEqual(
835835
alg.getConsoleCommands({'INPUT': source,
@@ -839,7 +839,7 @@ def testDissolve(self):
839839
['ogr2ogr',
840840
outdir + '/check.shp ' +
841841
source + ' ' +
842-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
842+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
843843
'GROUP BY my_field" -f "ESRI Shapefile"'])
844844

845845
self.assertEqual(
@@ -850,7 +850,7 @@ def testDissolve(self):
850850
['ogr2ogr',
851851
outdir + '/check.shp ' +
852852
source + ' ' +
853-
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
853+
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
854854
'GROUP BY my_field" "my opts" -f "ESRI Shapefile"'])
855855

856856
def testGdal2Tiles(self):
644 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
268 Bytes
Binary file not shown.
148 Bytes
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ogr:FeatureCollection
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://ogr.maptools.org/ dissolved_points.xsd"
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>15.92604758387077</gml:X><gml:Y>40.937862466921</gml:Y></gml:coord>
10+
<gml:coord><gml:X>16.09626941744634</gml:X><gml:Y>41.062137533079</gml:Y></gml:coord>
11+
</gml:Box>
12+
</gml:boundedBy>
13+
14+
<gml:featureMember>
15+
<ogr:SELECT fid="SELECT.0">
16+
<ogr:geometry><gml:MultiPoint srsName="EPSG:4326"><gml:pointMember><gml:Point><gml:coordinates>16,41</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>16.040258120023,40.9553659973658</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>16.0888304170073,41.062137533079</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometry>
17+
<ogr:TestField>AAA</ogr:TestField>
18+
</ogr:SELECT>
19+
</gml:featureMember>
20+
<gml:featureMember>
21+
<ogr:SELECT fid="SELECT.1">
22+
<ogr:geometry><gml:MultiPoint srsName="EPSG:4326"><gml:pointMember><gml:Point><gml:coordinates>15.9448638790989,41.0175035304448</gml:coordinates></gml:Point></gml:pointMember><gml:pointMember><gml:Point><gml:coordinates>16.0962694174463,40.9531780560602</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometry>
23+
<ogr:TestField>BBB</ogr:TestField>
24+
</ogr:SELECT>
25+
</gml:featureMember>
26+
<gml:featureMember>
27+
<ogr:SELECT fid="SELECT.2">
28+
<ogr:geometry><gml:MultiPoint srsName="EPSG:4326"><gml:pointMember><gml:Point><gml:coordinates>15.9260475838708,40.937862466921</gml:coordinates></gml:Point></gml:pointMember></gml:MultiPoint></ogr:geometry>
29+
<ogr:TestField>CCC</ogr:TestField>
30+
</ogr:SELECT>
31+
</gml:featureMember>
32+
</ogr:FeatureCollection>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
3+
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
4+
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
5+
<xs:complexType name="FeatureCollectionType">
6+
<xs:complexContent>
7+
<xs:extension base="gml:AbstractFeatureCollectionType">
8+
<xs:attribute name="lockId" type="xs:string" use="optional"/>
9+
<xs:attribute name="scope" type="xs:string" use="optional"/>
10+
</xs:extension>
11+
</xs:complexContent>
12+
</xs:complexType>
13+
<xs:element name="SELECT" type="ogr:SELECT_Type" substitutionGroup="gml:_Feature"/>
14+
<xs:complexType name="SELECT_Type">
15+
<xs:complexContent>
16+
<xs:extension base="gml:AbstractFeatureType">
17+
<xs:sequence>
18+
<xs:element name="geometry" type="gml:GeometryPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
19+
<xs:element name="TestField" nillable="true" minOccurs="0" maxOccurs="1">
20+
<xs:simpleType>
21+
<xs:restriction base="xs:string">
22+
</xs:restriction>
23+
</xs:simpleType>
24+
</xs:element>
25+
</xs:sequence>
26+
</xs:extension>
27+
</xs:complexContent>
28+
</xs:complexType>
29+
</xs:schema>

python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,22 @@ tests:
694694
OUTPUT:
695695
name: expected/gdal/points_along_lines.gml
696696
type: vector
697+
698+
- algorithm: gdal:dissolve
699+
name: Dissolve points (multipoint output)
700+
params:
701+
COMPUTE_AREA: false
702+
COMPUTE_STATISTICS: false
703+
COUNT_FEATURES: false
704+
EXPLODE_COLLECTIONS: false
705+
FIELD: TestField
706+
GEOMETRY: geometry
707+
INPUT:
708+
name: custom/dissolve_points.shp
709+
type: vector
710+
KEEP_ATTRIBUTES: false
711+
OPTIONS: ''
712+
results:
713+
OUTPUT:
714+
name: expected/gdal/dissolved_points.gml
715+
type: vector

0 commit comments

Comments
 (0)