[GRASS-dev] C function which returns raster and additional info?

Markus Metz markus.metz.giswork at googlemail.com
Wed Oct 19 04:24:24 EDT 2011


On Wed, Oct 19, 2011 at 10:03 AM, Rainer M Krug <r.m.krug at gmail.com> wrote:
>
>
> On Wed, Oct 19, 2011 at 8:36 AM, Markus Neteler <neteler at osgeo.org> wrote:
>>
>> On Tue, Oct 18, 2011 at 10:26 AM, Rainer M Krug <r.m.krug at gmail.com>
>> wrote:
>> > If this mail has made it already to the lst, I apologise - I just could
>> > not
>> > find it anywhere.
>> >
>> >
>> > Hi
>> >
>> > I am thinking about the possibility of loading raster directly from
>> > GRASS
>> > into R, to avoid the overhang of saving to disk and loading again or
>> > having
>> > gdal in between GRASS and R.
>> >
>> > As R (using the sp package) holds the raster in memory, I was thinking
>> > about
>> > reading the data from GRASS by using a C function, returning the cell
>> > values
>> > and additional info (at least the one provided in  esri ACSII file, i.e.
>> > NCOLS, NROWS, XLLCORNER, YLLCORNER, CELLSIZE, NODATA_VALUE) plus
>> > geo-referencing info, so that, back in R, this data can be assembled to
>> > become a spatial object (SpatialGridDataFrame, as defined in the package
>> > sp).
>>
>> An option may be to
>> - open the raster map,
>
> What do you mean by "open the raster map)?
>
>>
>> - set computational region to the map
>
> Good idea - but it would also be an option to use the active region, to
> enable the reading of certain selected regions.
>
>>
>> - read G_get_window()
>>
>>
>> http://grass.osgeo.org/programming6/get__window_8c.html#ada28852284056440f08c032e64a80765
>
> Thanks - that's great.
> That enables me to get the header date to construct a raster with the same
> info in R as a SpatialGrisDataFrame.
>
> Now I would need a function, which reads the cell values and returns it -
> either the complete raster, or the by column / row, and then I could
> assemble it - any ideas?
>
In the grass source tree, see doc/raster/r.example/main.c (or any
raster C module) about how to fetch cell values.

See also

http://grass.osgeo.org/programming6/gisrasterlib.html

for an introduction to C functions for raster processing.

Is it possible that Roger Bivand tried that approach in an earlier
version of spgrass, maybe for GRASS 5? If yes, he must have abandoned
that approach for good reason.

Markus M


More information about the grass-dev mailing list