[GIS] How to convert Shapefile to TopoJSON with grouping neighbor shapes by some criteria

javascriptogr2ogrshapefiletopojson

I have a shapefile with countries, which I convert to GeoJSON using ogr2ogr and then converting that json to another TopoJSON, using topojson command-line tool.

Everything works like charm, but now I want to learn to concatenate/merge/join/cluster (just don't know what is the most appropriate term in GIS context) different neighbor shapes to a bigger ones – say, all African countries to one big Africa shape. Let's assume that all Hdata needed (like continent name) is present in the original shapefile.

So, what is the simplest way to merge neighbour shapes while converting shapefile to topojson format?

Sorry if this question is about something trivial, it's just that this is a new topic to me, though I'm very glad I should deal with such issues.

Best Answer

You can dissolve the neighbour shapes uniting their geometries grouped by country name while converting the shapefile to json with GDAL >= 1.10 with SQLite and SpatiaLite support:

ogr2ogr -f GeoJSON -dialect SQLite -sql "SELECT cont_name, ST_Union(geometry) FROM African_Countries GROUP BY cont_name" Africa.json African_Countries.shp