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?

1 Answer 1


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
  • It seems that this will call the ogr2ogr in the command mode, though i wonder if it is possible to make it by python script? Since I have to do something for the extracted features.
    – giser
    May 2, 2014 at 9:02
  • You can use python to interface with the GDAL libraries; see for example: trac.osgeo.org/gdal/wiki/GdalOgrInPython
    – nmtoken
    May 2, 2014 at 9:27
  • In fact, I have used the gdal for python binding to read the features from the shapefile, but I do not find any method like getFeature(bbox or something else through the api here:cosmicproject.org/OGR/ogr_classes.html#Layer
    – giser
    May 3, 2014 at 5:01

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.