[GRASS-dev] How to read a raster cell value?
Glynn Clements
glynn at gclements.plus.com
Wed Jun 25 12:25:19 EDT 2008
Colin Nielsen wrote:
> I hope this is an easy question:
> I took this chunk of r.drain which reads single int CELL values given
> a row and col:
>
>
> CELL direction;
> CELL *dir;
>
> dir = G_allocate_c_raster_buf();
> next_row = list->row;
> next_col = list->col;
> ...
> lseek(fd, (off_t) list->row * ncol * sizeof(CELL), SEEK_SET);
> read(fd, dir, ncol * sizeof(CELL));
> direction = *(dir + list->col);
> G_message(_("row:%i, col:%i, direction:%i"), next_row, next_col, direction);
>
>
> And tried to replicate it for use with a double DCELL like this:
>
> int row, col, next_row, next_col;
> DCELL direction;
> DCELL *dir_buf;
> dir_buf = G_allocate_d_raster_buf();
>
> next_row = list->row;
> next_col = list->col;
> lseek(dir_fd, (off_t) list->row * ncol * sizeof(DCELL), SEEK_SET);
> read(dir_fd, dir_buf, ncol * sizeof(DCELL));
> direction = *(dir_buf + list->col);
> G_message(_("row:%i, col:%i, direction:%lf"), next_row, next_col, direction);
>
>
> Somehow the top int section functions properly, while my modified
> section for doubles does not (ie. it returns the wrong "direction"
> value). I suspect it has something to do with the offset in lseek, but
> I can't figure it out.
Does the file actually contain doubles? If it doesn't, trying to read
doubles from the file isn't going to work.
> Does it matter that the row and col are int, while the value is
> double?
No.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list