[gdal-dev] basic raster math
Christopher Barker
Chris.Barker at noaa.gov
Fri Feb 15 12:44:31 EST 2008
Ari Jolma wrote:
>> numpy_array = band.ReadAsArray()
>
> Just to make sure, I guess this reads the whole thing into memory?
yes.
> I.e. don't try this with huge images.
well, you can TRY it ;-)
ReadAsArray() supports accessing a subset of the band as well, if you
want to work with monster images in chunks.
WolfgangZ wrote:
> 1. accessing the cell value of a (float) tiff. I know how to load the
> map into an array, but this seems to be overkill.
As above, ReadAsArray can load a subset of the band, presumable
including a single cell. You could use ReadRaster too, as there isn't
much point to using arrays for a single value.
> 2. can I get the surrounding cells or better directly (bilinear/cubic)
> interpolated data?
same as above! ReadAsArray will also re-scale for you.
My Question: can I control what re-scaling algorithm is used?
> 4. can I change the resolution of the input map directly in python (as
> replacement of gdal_translate -tr)?
I think you can use ReadAsArray/WriteAsArray to do this too.
Jose Luis Gomez Dans wrote:
> data = numpy.array(g.GetRasterBand(1).ReadAsArray().tolist())
> #The previous line converts the oldgen python Numeric array into a
> #spanking numpy array.
This is far less efficient than you need!
data = numpy.asarray(g.GetRasterBand(1).ReadAsArray())
should to it, and without any memory copying!
If that fails, then numpy.fromstring( array.tostring() )would be a lot
better than tolist()
> dst_ds.GetRasterBand(1).WriteArray( raster )
This is the key line -- thanks!
This really points out that we need some Recipe pages in the Wiki for
Python/GDAL -- anyone want to get that started?
While we're on the topic -- what are the plans for numpy vs. Numeric? It
looks like the current utilities and samples all allow either one -- I'd
like to see a switch to only-numpy at some point -- the sooner the
better. It's what's supported now, and it does have small but subtle and
useful differences.
Also -- are there any Python API docs out there that I haven't found? If
not, we could use them -- maybe doc strings and some auto-generation
tool, like pydoc or Doxygen. What is being used for the C/C++?
Robin Dunn (of wxPython) has done some nice work of auto-generating docs
strings as part of the SWIG process -- perhaps we could borrow that
approach.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the gdal-dev
mailing list