Given a .shp that covers the globe, how could QGIS be used to segment that into 90 .shp files, each file containing lines/points/polygons/multipolygons that are between the first and second then second and third then third and fourth, etc?

Issue is a series of gigantic source files with global coverage that have no common attributes that would allow them to be conventionally partitioned. Since the source files have a relatively even distribution (not over the Pacific ocean of course), cutting them up into smaller files will make them cleaner to process.

I was hoping there was a hidden command in ogr2ogr that would do this, but I don't see one.

1 Answer 1


You can use the -spat option of ogr2ogr and a loop to do this. On a linux box I'd do something like:

for x in `seq -180 10 170`; do
     ogr2ogr -spat $x -90 $x2 90 -spat_srs epsg:4326 outfile_$x.json infile.shp
  • Experimenting with this, good idea! What does "Warning 1: cannot determine layer SRS for myshape" mean? I am confused about the -spat_srs switch. This works but I think I am introducing errors: ogr2ogr -progress -overwrite -lco RFC7946=YES -f GeoJSON -s_srs "EPSG: 3857" -t_srs crs:84 -spat -180 -90 -170 90 piece1.json piecesall.shp
    – Snowy
    Commented Aug 19, 2020 at 21:56
  • 2
    That means your shapefile lacks a prj file - use -a_srs to set the projection for the input file. -spat_srs defines the projection of the spat coordinates
    – Ian Turton
    Commented Aug 20, 2020 at 7:15

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.