5

I have a series of polygons that are the output of another GIS program - I need to merge the polygons into a single polygon. I have tried a couple of different methods with no luck. I have tried to use the "Dissolve" tool, using the Dissolve all - however this led to an essentially empty output (most probably because there isn't a common attribute between all the polygons). I have tried to use the calculator in the attribute table (there are around 350 000 polygons) to add a dummy column but it doesn't show in the Dissolve tool.

I am finding the merge tool does the job - to a point, but ultimately is extremely time consuming. Is there a way to merge all polygons in a layer without too many steps? Ultimately I just need the geographic area, the values/names etc are entirely irrelevant for what I'm currently doing. I have tried to select all within the attribute table by using the "invert selection" option (a recommendation on another site) but this doesn't appear to do anything. I have also read about a SelectPlus plugin, but no luck finding this one either.

Any suggestions greatly appreciated.

EDIT: Sorry it's a single file that I'm wanting to merge the polygons in (want the outline of all of them together, there are no gaps).

EDIT2: and while it's very slow, I've now found how to select all the polygons at once (using the radius selection option), which at least seems to be working if I do in stages.

  • You don't explain if large output is one file or many – Brad Nesom Dec 9 '13 at 4:55
3

Using QGIS, apart from the Vector -> Geprocessing Tools - Dissolve Menu entry, you can also use Processing (formerly named Sextante), which offers dissolving by GRASS and SAGA.

1

I've done this with GDAL's ogr2ogr and using sql from SQLITE/Spatialite - the examples below will dissolve all features into a single feature. There are ways to modify the sql to include specific fields in the output or dissolve based on a specific field because Spatialite's ST_Union() is an aggregate function which makes it pretty flexible.

Running(the spatialite 3.x way):
ogr2ogr -dialect SQLITE -sql "SELECT ST_UnaryUnion(ST_Collect(geometry)) FROM input" output.shp input.shp
...on a polygon with +23,000 features, it took 4mins.

On ~350,000 features, it could take ~60mins in comparison.

Check out What is the Efficient Way to Dissolve Polygons using Spatialite 3.0, the same topic but from Spaitialite User List and Creating Points on a Surface Using OGR.

Running (the recommended way):
ogr2ogr -dialect SQLITE -sql "SELECT ST_Union(geometry) FROM input" output.shp input.shp
...only took 3min59sec on the same +23,000 feat poly I have. Not noticeable at this scale, but maybe made a minute difference with ~350,000 features.


I'm not sure if these plugins or a combo of plugins would allow you to arbitrarily execute this on a vector layer in QGIS -> save result to memory -> save memory layer to shp on disk! Then it would be a QGIS solution =) The first 3 are sql options, maybe only one of those would be needed...

0

One approach would be to consider PostGIS instead of QGIS. 350,000 polygons is a large number of polygons and probably too big to be comfortably handled by most desktop GIS programs.

  • Thanks for the suggestion, I'll see how often I need to do this and if it'll be often I'll look into PostGIS – Esme_ Dec 9 '13 at 5:03
0

You could use ogr2ogr. The following is from the documentation:

A merge of two shapefiles 'file1.shp' and 'file2.shp' into a new file 'file_merged.shp' is performed like this:

% ogr2ogr file_merged.shp file1.shp % ogr2ogr -update -append file_merged.shp file2.shp -nln file_merged

The second command is opening file_merged.shp in update mode, and trying to find existing layers and append the features being copied.

The -nln option sets the name of the layer to be copied to.

End of Quote

You could run this is in a loop so that every Shape is going to be appended.

  • Thanks for the suggestions Torsten - unfortunately though I have a single shape file containing multiple polygons. – Esme_ Dec 9 '13 at 22:33

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.