[R-sig-Geo] Issue reading GRASS rasters with rgdal

Roger Bivand Roger.Bivand at nhh.no
Tue Oct 29 20:27:24 CET 2013


Please do not post HTML, do follow the posting guide and instructions.

On Tue, 29 Oct 2013, Joshua Perlman wrote:

> Hello,
>
> I am attempting to read rasters from GRASS format into R directly through
> rgdal (without running GRASS).  The GDAL GRASS plugin is installed and
> apparently working as evidenced by a call to gdalinfo with one of the GRASS
> rasters.
>
> However, when I run these lines in R:
>
> library(rgdal)
> R = readGDAL("/path/cellhd/raster")
>
> R tells me:
>
> /path/cellhd/raster has GDAL driver GRASS
> and has 23457 rows and 35104 columns

Really? You'll have around 800 million cells, if numeric needing over 6GB, 
and probably copied multiple times internally. Use GRASS to manipulate 
data of this kind, or use the facilities in rgdal to read parts of the 
data in tiles. It is very unlikely that any statistical method is 
appropriate for raster data of this kind, unless you are predicting from a 
fitted model, which can be done in tiles. Since you have not included any 
affiliation or motivation, how should anyone know what your problem is? In 
general avoid non-informative subscribed addresses, at least an 
institutional address gives some insight into why you need to know.

The plugin also has no write functionality, so it isn't easy to see what 
the point is. The error may also show that the plugin doesn't actually 
work.

> Error in x[, , i] <- .Call("RGDAL_GetRasterData", raster,
> as.integer(c(offset,  :
>  number of items to replace is not a multiple of replacement length
>
> Any ideas what my causing this error and how to fix it?
>

If you had provided your verbatim command, the output of traceback() and 
the output of sessionInfo(), as well as the startup messages shown when 
loading rgdal, we might be a little the wiser. Can you reproduce the error 
with any other data set? The error is flagged in getRasterData() called in 
readGDAL(), and indicates that the number of values in the band is likely 
not the product of the numbers of rows and columns.

Hope this clarifies,

Roger

> Thanks,
>
> Josh
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list