I'm looking for a means to take a rather large shapefile and split it out into separate, smaller shapefiles based on number of features. So for example, if I have a file with 1 million features, subset it out into smaller files of 100k features each.

I know how to grid a shapefile and subset into smaller files, but I don't want to grid it as I want to preserve the original feature geometry (e.g. gridding polygons will ruin the geometry).

Does anyone know how this can be done with QGIS?

3 Answers 3


Is there a field in the attribute table you can use to group the smaller sets by? If so, you can use ogr2ogr's -sql switch to specify a query that will pull just those records and export them to their own shapefile.

Boston GIS's site has a nice ogr2ogr cheatsheet if you need an example to work from


That said, with a million records I would stuff that sucker into a PostGIS database. It would almost certainly be faster to work with, especially if those features are complex.


If you just want to sample X number of features from a vector file:

  • QGIS has a function in the vector menu "Research tools" called Random selection within subjects. Open this tool and calculate a subset containing any number or percentage of X features within your vector layer.

If you want to totally separate your polygon into equal parts:

  • The way to go would be to create a separate attribute field with an index and attach it to your vectors attribute table. I would create the column with a R or a python-script. Afterwards execute the Dissolve-Tool from your vector menu and choose your newly created column.

Of course there might be an easier solution if you use PostGIS.


If you don't have postgis available and don't need multi-user access then load the shapefile into a spatialite db, the speed is amazing and even that many records would be a breeze.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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