[gdal-dev] Using RasterIO in Python to crop images

Jose Gomez-Dans jgomezdans at gmail.com
Wed Jan 20 07:49:28 EST 2010


Hi,

2010/1/19 Roger André <randre at gmail.com>

> Assuming that I have an 8bit, paletted image named "foo.png", if I wanted
> to extract a 50 x 50 pixel tile that had it's origin at pixel coords (0,0),
> I would do something like this:
>
> in_ds = gdal.Open('foo.png')
> band = dataset.GetRasterBand(1)
> tile_data = band.ReadRaster( 0, 0, 50, 50, 2500, 1, GDT_Byte )
>
> and then I would imagine I have to create the output dataset and write
> tile_data to it.
>

Couldn't you just use

tile_data = band.ReadAsArray()[0:51, 0:51]

or even simpler (if it's an RGBA PNG)
g  = gdal.Open("foo.png")
T = g.ReadAsArray () [:, 0:50, 0:50 ]
T.shape is now (4, 50, 50)

?

J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20100120/377f0961/attachment.html


More information about the gdal-dev mailing list