[Gdal-dev] custom reclass/remap using gdal_translate
Gregory, Matthew
matt.gregory at oregonstate.edu
Wed Feb 28 20:05:04 EST 2007
Frank Warmerdam wrote:
> Matthew Gregory wrote:
> > 1) Is there a standard algorithm for determining the min/max of a
> > window within an image. I assume that you could get there by
> > iterating over the tiles that make up that window, but I didn't know
> > if there was a more elegant way that I was overlooking.
>
> Matthew,
>
> One approach to this would be to create a virtual file for
> that subwindow and then compute the min/max on that.
>
> eg.
> gdal_translate -of VRT -srcwin 100 200 500 400 in.tif out.vrt
> gdalinfo -stats out.vrt
Forgive yet another newbie question, but I'd like to calculate the
statistics of the subwindow at run time, so I've taken the following
approach:
1) Construct the VRT XML (e.g. as in gdal_vrtmerge.py) which allows for
the subwindow specification.
2) Re-open the VRT file using gdal.Open() and calculate the pertinent
statistics, e.g.
vrt_ds = gdal.Open(out_file)
vrtBand = vrt_ds.GetRasterBand(1)
(vrtMin, vrtMax) = vrtBand.ComputeRasterMinMax()
vrtNoData = vrt_ds.GetRasterBand(1).GetNoDataValue()
(Note: I realize this approach is no different than running the
gdal_translate utility as Frank has suggested and then doing step #2.)
What I'm wondering is if there is a easier way of getting the
subwindow's statistics without going through the process of creating the
intermediate VRT file. Is there some way of doing this through using
VRTDriver.Create()? Sorry to be so dense ...
thanks, matt
Matt Gregory
Faculty Research Assistant
Department of Forest Science
Oregon State University
Phone : (541) 758-7778
Email : matt.gregory at oregonstate.edu
More information about the Gdal-dev
mailing list