Site menu:

Cyclocross For Roadies: How and Why to Get Started - Buy Now!

Site search


Dissolve Shapefiles using OGR

Quite often, I’ll run across a large or complex shapefile that causes issues (crashing, very poor performance, etc) in QGIS or other desktop GIS.

However, sometimes you have to find a way to deal with these files, and not spend a lot of time worrying about them. Often, the best way is to head back to the mysterious black box that is the command line, and use the ultra-stable suite of tools available there. My favourite for spatial work is GDAL/OGR

I was recently struggling to do a simple dissolve on a large and complex shapefile. I didn’t want to bring it into a database, but QGIS would crash trying to dissolve the shapefile. Of course, OGR had no problem with the file!

Here’s how to turn this (nine features with three different attributes):

Input to dissolve - 3 attributes

Input to dissolve – 3 attributes

Into this (three attributes, three multi-part features!):

Dissolved shapes

Dissolved shapes

Simply use this command (substituting your file names and field names as appropriate) into ogr, and you’re all set!

ogr2ogr outputfile.shp inputfile.shp -dialect sqlite -sql “SELECT dissolvefield,ST_Union(geometry) as geometry FROM inputfile GROUP BY dissolvefield”



Comment from Marcelo
Time March 17, 2015 at 12:46 am

Thanks for the easy way. You need to add single quotes to the input file source inside the sql statement … FROM ‘input file’ …

Comment from Ivan Gonzalez
Time April 21, 2016 at 9:15 pm

Works perfect. Thanks a lot!!

Write a comment

Bookshelf 2.0 developed by

Read previous post:
Recording Power from CycleOps 300 Pro Indoor Bikes

I recently started an indoor cycling program at a studio that uses the CycleOps 300 Pro Indoor Cycles. These bikes...