[gdal-dev] GDAL Python Development: Area Selection
Even Rouault
even.rouault at mines-paris.org
Wed May 27 15:35:43 EDT 2009
Pooven,
You're doing things the right way. GDAL doesn't provide any high-level
function to extract a region from a bounding box expressed in projected
coordinates. You have to compute the pixel coordinates of the corner of the
bounding box yourself by using the inverse of the geotransform matrix
returned by the GetGeoTransform() method of the dataset.
gt = ds.GetGeoTransform()
x_pixel = (x_projected - gt[0]) / gt[1]
y_pixel = (y_projected - gt[3]) / gt[5]
(provided that your raster doesn't has any rotation or shearing, that is to
say that gt[2] = gt[4] = 0)
Best regards,
Even
Le Wednesday 27 May 2009 12:06:10 Poovendran Moodley, vous avez écrit :
> Hi there,
>
> I want to select only a region of a raster file; that is, suppose I know
> the coordinates that form a bounding box around a region, I want to select
> just that region and write it to another file.
>
> I'm rather new to GDAL and thus far I'm only aware of one way to do this;
>
> since I'm using Python:
> > scanline = band.ReadRaster( 0, 0, band.XSize, 1, band.XSize, 1,
> > GDT_Float32
> > <http://www.gdal.org/gdal_8h.html#22e22ce0a55036a96f652765793fb7a4f5cbd2f
> >96abffd9ac061fc0dced5cbba> )
> >
> > I believe that I can specify the window of raster data to read using the
>
> 3rd till 6th input parameters of the above method (with reasonable size
> reads untill the entire regions I'm interested in is read).
>
> Is there some other way this was suppose to be done? The method above will
> require me to convert my coordinates into rows and columns (I think) which
> is fine... but leaves room for error so I'd like to only rely on GDAL
> routines. Can someone please advise? It could very well be that I'm totally
> mistaken... I hope this isn't such a bad question...
>
> Kind regards
> Pooven
More information about the gdal-dev
mailing list