[GRASS-user] reading a column/vector of a raster image

Glynn Clements glynn at gclements.plus.com
Tue Dec 1 05:11:54 EST 2009


Peng Du wrote:

> I am dealing with a satellite image which has N bands, each band of size 
> row x col. Is there any way to read one column of a certain band or all 
> the bands of a certain point?  I only found G_get_raster_row which works 
> for row.

You can use G_set_window() (Rast_set_window() in 7.0) to control which
samples are returned for each row. E.g. for column "n":

	struct Cell_head cellhd;

	...

	G_get_set_window(&cellhd);
	cellhd.west += cellhd.ew_res * n;
	cellhd.east = cellhd.west + cellhd.ew_res;
	G_set_window(&cellhd);

Then, each call to G_get_raster_row() etc will store a single value in
the buffer.

However, reducing the number of columns won't have any noticeable
effect upon speed, as the library reads and decompresses entire rows. 
If you want to process maps in column-major order, you should create a
transposed copy in a temporary file or in memory.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list