[gdal-dev] Clipping shapefiles

Craig Leat craig.leat at gmail.com
Thu Sep 4 05:09:43 EDT 2008


Hi Matthew

Matthew Huck wrote:
>  Hi,  I've got a reasonably large shapefile that I wish to break down
> into areas that match the topographic maps in NZMG. I've got a python
> script that creates a shapefile with each topomap as a polygon in it
> (and I can create a shapefile per topo map too if required). What I
> can't work out how to do is to clip my master shapefile by the smaller
> shapefiles. I've seen ideas of copying across the features if they
> intersect with the clipping box, but the data is contour lines so I
> want to "cut" the contour lines at the boundry of the clipping boxes.
> Any ideas on the best way to do it, I can get MapWindow to do it
> (sometimes, but it crashes frequently).

I use GRASS for this sort of task. The basic steps are:

1. Import shape files using v.in.ogr
2. Set the region extents (a bounding box for the area of interest)
using g.region
3. Make a vector to be used as a cutter - v.in.region
4. Select within the region box and cut on the boundary using v.overlay

It's quite easy to roll these steps into a script and is definitely
the way to go if you have to do this many times.

Craig

gdal/ogr devs, an ogr2tiles.py would be quite nice.


More information about the gdal-dev mailing list