[gdal-dev] crop a raster file (.bsp/.kap) to create an image file (.png)

Frank Warmerdam warmerdam at pobox.com
Fri Jul 23 10:43:47 EDT 2010


jmsbc wrote:
> 
> Hello,
> 
> I have a set of raster files (.bsb and .kap) that I need to crop based on a
> set of coordinates (top left x,y and bottom right x,y) in order to obtain a
> .png file.
> 
> I've gone through the GDAL API tutorial, and it seems like I should be using
> CreateCopy to derive the destination file.  
> 
> However how do I crop the original raster file based on my specified lat/lon
> coordinates?

James,

gdal_translate has options to select a subwindow based on pixel/line
coordiantes (-srcwin) or coordinates in the projected coordinate system
of the file (-projwin).  It accomplishes this by creating an in memory
virtual file referencing a subwindow of the source file and using
CreateCopy on that virtual file.  This is a somewhat complicated technique
but you could review the gdal_translate code in gdal/apps to see how it is
accomplished.

However, I believe in some BSB files the cropping is not going to be a
rectangle in the coordinate system of the image - if the coordinate system
of the image is not rectangular relative to lat/long (for instance LCC).
If that is the case you would need a more complicated technique.

You will also need to transform the lat/long values to image coordinates
to construct the source window.  You might want to read the coordinate system
tutorial before trying to do that.

   http://www.gdal.org/ogr/osr_tutorial.html

Good luck,
-- 
---------------------------------------+--------------------------------------
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    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list