[gdal-dev] How to access a part of an image

Andreas Theofilu andreas at theosys.at
Mon Jun 16 12:35:02 EDT 2008


Hi to all,

I have here a PNG image of a map where I know the geo coordinates of the upper 
left corner and the lower right corner. Of course I know the pixels in X and 
Y dimensions.

Now I want to display only a part of that image. I know the upper left corner 
in geo coordinates and also the lower right corner of the rectangular I want 
to show. I also know the pixel dimensions of the window on the screen, where 
I want to display the map. The size in pixels of the window on the screen 
does not correspond to the pixels of the image.

I'm able to open the image with GDAL, but I don't know how I should tell GDAL 
about the geo dimensions of the image (tried it with SetGeoTransform())? And 
how can I tell GDAL about the rectangular I wand to load from the image?

I tried to compute this myself and could successfull calculate the X and Y 
offset in pixels, where to start loading the image. I then give this to 
RasterIO() and was able to read only a part of the image, but with wrong 
dimensions of course, because GDAL didn't knew the wanted pixels in X and Y 
directions.

Is there another way to do that?

-- 
Andreas Theofilu
TheoSys - Software Systems and Solutions
http://www.theosys.at
Tel.: +43 676 / 786 53 89


More information about the gdal-dev mailing list