How do I apply using this same concept, but simply merging all features into one?

ogr2ogr output.shp input.shp -dialect sqlite -sql 
"SELECT ST_Union(geometry), dissolve_field FROM input GROUP BY dissolve_field"
  • Remove the group by? – John Powell Jul 3 '15 at 8:50
  • I don't know... That's part of where I'm stuck. It doesn't seem to like a * as a wildcard. And ideas? – Steven Lutz Jul 3 '15 at 8:52
  • Where do you have a wildcard? SELECT ST_Union(geometry) FROM input I would think. – John Powell Jul 3 '15 at 8:54
  • I tried that too but I don't know what to put in place of input – Steven Lutz Jul 3 '15 at 8:55
  • It is the layer name. You can check the name with ogr2ogr but with shapefiles it is the base name of the shapefile: input.shp -> input, foo.shp -> foo. – user30184 Jul 3 '15 at 9:53

In order to merge all features into one, you should do:

ogr2ogr output.shp input.shp -dialect sqlite -sql "SELECT ST_Union(geometry) AS geometry FROM input"

where geometry is the special field used in order to represent the geometry of the features in SQLite SQL dialect and input in the SQL statement is the input layer name.

  • 3
    Thank you for posting this. I believe your solution is the same as what ended up working for me: >ogr2ogr -f "ESRI Shapefile" output.shp 32768.shp -dialect sqlite -sql "select ST_union(geometry) from '32768'" – Steven Lutz Jul 7 '15 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.