[R-sig-Geo] C API for sp classes?
Edzer J. Pebesma
e.pebesma at geo.uu.nl
Tue Mar 7 16:45:29 CET 2006
Wouter, if you want to use the .C interface, you need to pass
the maps as simple vectors. I would pass one with the map
values, and one with the topology. Below is some example
code how to get them. An R function should be used to do
the coercion to double arrays, and wrap the .C call.
Please note that a SpatialGridDataFrame can actually hold
more than one attribute (map).
--
Edzer
For getting the values:
> library(sp)
> data(meuse.grid)
> gridded(meuse.grid)=~x+y
> fullgrid(meuse.grid)=T
> meuse.grid at data@att[[1]] # first attribute
[1] NA NA NA NA NA NA NA NA NA NA ...
>
Getting the topology:
> meuse.grid at grid
x y
cellcentre.offset 178460 329620
cellsize 40 40
cells.dim 78 104
> class(meuse.grid at grid)
[1] "GridTopology"
attr(,"package")
[1] "sp"
> unlist(gridtopology(meuse.grid))
Error in unlist(gridtopology(meuse.grid)) :
couldn't find function "gridtopology"
> unlist(gridparameters(meuse.grid))
cellcentre.offset1 cellcentre.offset2 cellsize1 cellsize2
178460 329620 40 40
cells.dim1 cells.dim2
78 104
> as.double(unlist(gridparameters(meuse.grid)))
[1] 178460 329620 40 40 78 104
>
Wouter Buytaert wrote:
>Hi,
>
>I want to write some R functions for calculating hydrological
>catchment characteristics from a DEM (topographic index, overland flow
>delay function etc.).
>
>Looks like using a DEM with SpatialGridDataFrame class as an input is a
>good idea.
>
>Then what is the best way to extract the data matrix from this class to
>pass it on to a .C() function which does the actual calculations?
>
>cheers,
>
>wouter
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo at stat.math.ethz.ch
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
More information about the R-sig-Geo
mailing list