[gdal-dev] ogr2ogr SQL command

Even Rouault even.rouault at spatialys.com
Fri Jun 29 05:34:09 PDT 2018


On vendredi 29 juin 2018 12:12:06 CEST Rousseau Lambert2, Louis-Philippe (EC) 
wrote:
> Hi,
> 
> 
> I was trying to dissolve some buffers based on a attribute in a shapefile
> and faced something weird.
> 
> 
> I do the dissolve with ogr2ogr command line:
> 
> ogr2ogr coverage_dissolve.shp coverage.shp -dialect sqlite -sql "SELECT
> ST_Union(geometry), type FROM coverage GROUP BY type"
> 
> 
> This works fine with GDAL 1.10.0, but when I try to do the same thing with
> GDAL 2.2.2, nothing happens...
> 
> 
> Is there a another way of doing SQL commands in gdal 2.2.2 or am I missing
> something else?

Works fine for me with 2.2.4 and later with the following trivial dataset:

Given test.csv:
id,type,WKT
1,"x","POLYGON((0 0,0 1,1 1,1 0))"
2,"x","POLYGON((0 0,1 0,1 1,1 0))"

$ ogr2ogr coverage.shp test.csv
$ ogr2ogr coverage_dissolve.shp coverage.shp -dialect sqlite \
  -sql "SELECT ST_Union(geometry), type FROM coverage GROUP BY type"
$ ogrinfo coverage_dissolve.shp -al -q
[...]
OGRFeature(coverage_dissolve):0
  type (String) = x
  POLYGON ((0 0,0 1,1 1,1 0,0 0))

Perhaps there was also a change in Spatialite and GEOS versions when upgrading 
from GDAL 1.10 to 2.2.2 ? Are all your geometries valid ?

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list