[gdal-dev] find bounding box of a shapefile

Frank Warmerdam warmerdam at pobox.com
Sun May 11 22:44:37 EDT 2008


Xiaodong Zhang wrote:
> Hi,
> 
> In order to find the bounding box of polygons (defined in a shapefile), 
> I guess I need to find the minimum x and y coordinates and maximum x and 
> y coordinates and then to form the four corners. In case somebody has 
> already done this, would you like to share your thoughts or code?

Xiaodong,

If you are using OGR, you can just call GetExtent() on the OGRLayer
representing the shapefile.  In the case of the shapefile, the extents
are stored in the header so this is a virtually free operation.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the gdal-dev mailing list