Skip to content
Permalink
Browse files

[processing][needs-docs] force multipart output from GDAL-based dissolve

algorithm (fix #20025)
  • Loading branch information
alexbruy authored and nyalldawson committed Jan 24, 2019
1 parent 7482f7a commit 32f6034be708b305ed4e19b4f6ade1a8b409993b
@@ -142,6 +142,7 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append('-nlt PROMOTE_TO_MULTI')
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')
@@ -693,7 +693,7 @@ def testDissolve(self):
['ogr2ogr',
outdir + '/check.shp ' +
source + ' ' +
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry FROM \'polys2\'" ' +
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry FROM \'polys2\'" ' +
'-f "ESRI Shapefile"'])

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

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

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

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

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

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

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

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

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

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

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

@@ -829,7 +829,7 @@ def testDissolve(self):
['ogr2ogr',
outdir + '/check.shp ' +
source + ' ' +
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
'GROUP BY my_field" -f "ESRI Shapefile"'])
self.assertEqual(
alg.getConsoleCommands({'INPUT': source,
@@ -839,7 +839,7 @@ def testDissolve(self):
['ogr2ogr',
outdir + '/check.shp ' +
source + ' ' +
'-dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
'-nlt PROMOTE_TO_MULTI -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry, my_field FROM \'polys2\' ' +
'GROUP BY my_field" -f "ESRI Shapefile"'])

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

def testGdal2Tiles(self):
Binary file not shown.
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ dissolved_points.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>15.92604758387077</gml:X><gml:Y>40.937862466921</gml:Y></gml:coord>
<gml:coord><gml:X>16.09626941744634</gml:X><gml:Y>41.062137533079</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:SELECT fid="SELECT.0">
<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>
<ogr:TestField>AAA</ogr:TestField>
</ogr:SELECT>
</gml:featureMember>
<gml:featureMember>
<ogr:SELECT fid="SELECT.1">
<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>
<ogr:TestField>BBB</ogr:TestField>
</ogr:SELECT>
</gml:featureMember>
<gml:featureMember>
<ogr:SELECT fid="SELECT.2">
<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>
<ogr:TestField>CCC</ogr:TestField>
</ogr:SELECT>
</gml:featureMember>
</ogr:FeatureCollection>
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="SELECT" type="ogr:SELECT_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="SELECT_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometry" type="gml:GeometryPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="TestField" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
@@ -694,3 +694,22 @@ tests:
OUTPUT:
name: expected/gdal/points_along_lines.gml
type: vector

- algorithm: gdal:dissolve
name: Dissolve points (multipoint output)
params:
COMPUTE_AREA: false
COMPUTE_STATISTICS: false
COUNT_FEATURES: false
EXPLODE_COLLECTIONS: false
FIELD: TestField
GEOMETRY: geometry
INPUT:
name: custom/dissolve_points.shp
type: vector
KEEP_ATTRIBUTES: false
OPTIONS: ''
results:
OUTPUT:
name: expected/gdal/dissolved_points.gml
type: vector

0 comments on commit 32f6034

Please sign in to comment.
You can’t perform that action at this time.