Clipping Large Shapefiles using OGR
My puzzle this morning was to clip a very large shapefile. I tried all of my usual methods (QGIS, Kosmo, etc.) and was having no success (crashing, hanging, taking forever, etc.) so I thought I would try out my old standby, OGR.
I had never used OGR to clip a file based on a polygon before, but had used it to clip to extents. The idea is the same, except that you specify the clip polygon layer rather than the extents in the -clipsrc option. I headed to the ever-useful man page for ogr2ogr, and came up with the following, which worked perfectly!
ogr2ogr -clipsrc clipping_polygon.shp output.shp input.shp
It’s just that easy, and best of all it just works when all other methods fail!
Posted: March 31st, 2011 under GIS.