Perhaps you can try this in GRASS.
The GUI is perhaps less intuitive than QGIS, and you need extra steps to import (v.in.ogr), perform processing, and export (v.out.ogr) the shapefile. But once you're past the initial hurdle it is a great supplement to QGIS, since it lets you come at tougher problems with an alternative approach.
For a once-only processing effort, you won't need to get into scripting the commands either.
use v.in.ogr for each shapefile to import them to the GRASS environment:
http://grass.osgeo.org/grass64/manuals/v.in.ogr.html
Most of your clipping and intersections can be done through the v.overlay command with 'and' operator:
http://grass.osgeo.org/grass64/manuals/v.overlay.html
To explore those commands through the GUI:
File -> Import Vector Layer -> common import formats [v.in.ogr]
Vector -> Overlay Vector Maps [v.overlay]
Figuring out how to run those steps shouldn't take too long, and will give you a good idea whether GRASS is an useful approach for your dataset.
v.overlay should be able to handle everything else in your processing up to the 'field calculator' - I'm not sure what GRASS has to offer for this step. In the worst case you could export your product back to shapefile using v.out.ogr, then do the field-calculator step in QGIS.
You can convert all your data into multipolygons with ogr2ogr by defining "new layer type" with -nlt MULTIPOLYGON
. However, I am not sure if the result is exactly what you believe when multipolygon has only one part.
This is a triangle as polygon
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 95.0, 216.0 ], [ 241.0, 253.0 ], [ 175.0, 138.0 ], [ 95.0, 216.0 ] ] ] } }
]
}
This is the same triangle as multipolygon
{
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 95.0, 216.0 ], [ 241.0, 253.0 ], [ 175.0, 138.0 ], [ 95.0, 216.0 ] ] ] ] } }
]
}
EDIT
However, if the aim is to combine all the separate features, both polygons and multipolygons into one feature which is of type multipolygon, you must build an union. If your mixture of polygons and multipolygons is in file "mix.shp" the command to use is:
ogr2ogr -f geojson union.json mix.shp -dialect sqlite -sql "select st_union(geometry) from mix"
The result "union.json " contains one multipolygon as can be seen from the ogr2ogr report:
Layer name: OGRGeoJSON
Geometry: Multi Polygon
Feature Count: 1
...
OGRFeature(OGRGeoJSON):0
MULTIPOLYGON (((125 229,185 289,252 234,208 169,125 229)),...
Best Answer
You are right that dumping the multipolygons to polygons makes the index more efficient, for the reason you mention.
So if the size of the dataset makes performance an issue you should:
Something like: