[GRASS-dev] C rotine- parsing all image into a variable

Glynn Clements glynn at gclements.plus.com
Wed Oct 20 17:42:55 EDT 2010


António Rocha wrote:

> Thanks for the feedback. My problem is not a segmentation issue but a 
> memory-allocation issue. I need to understand how in GRASS (C functions) 
> I can allocate all pixels of a group images to an matrix (array of 
> array) instead of just row-by-row (or column-by-column).

If you want the data interleaved by cell, you'll need to read a row
from each map then interleave the values yourself, e.g.

	DCELL *row_buf = G_malloc(ncols * nbands * sizeof(DCELL));

	for (row = 0; row < nrows; row++) {
	    for (band = 0; band < nbands; band++) {
	        G_get_d_raster_row(fds[band], bufs[band], row);
	        for (col = 0; col < ncols; col++)
	            row_buf[col * nbands + band] = bufs[band][col];
	...

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


More information about the grass-dev mailing list