[GIS] How to get feature for a given bbox from shapefile by ogr

ogrshapefile

I have some features point,line,polygon with shapefile format, now I want to get features for a given boundbox, is it possible to remove the features out of the bbox?

And for a polygon, I think it is necessary to close it.

I wonder if this is possible?

Best Answer

You should be able to use the ogr2ogr utility to extract the features you want from your shapefile, using a bounding box.

Something like:

ogr2ogr -clipdst [xmin ymin xmax ymax] output.shp input.shp

and also by specifying a polygon instead of a bounding box like:

ogr2ogr -clipsrclayer cliplayer.shp output.shp input.shp