I am trying to get a raster into GRASS from R and back out again using the rgrass7
package. Getting the raster in seems to be no problem. However, when I try to get it out with the readRAST
function it seems that the raster dimensions have been reduced to [1,1].
Am I missing a function argument? All the examples I have seen simply use the GRASS object name.
Is this a mapset issue? I didn't think so because it was my understanding that the philosophy of rgrass7
is to use temporary mapsets and layers.
See reproducible example:
library(raster)
#> Loading required package: sp
raster_image <- raster::raster(system.file("external/test.grd", package = "raster"))
raster_image <- as(raster_image, "SpatialGridDataFrame")
loc <- rgrass7::initGRASS("/usr/lib/grass70", home = tempdir(), override = TRUE)
rgrass7::writeRAST(raster_image, "raster_image", flags = c("overwrite"))
#> 0% 3% 6% 9% 12% 15% 18% 21% 24% 27% 30% 33% 36% 39% 42% 45% 48% 51% 54% 57% 60% 63% 66% 69% 72% 75% 78% 81% 84% 87% 90% 93% 96% 99% 100%
rgrass7::execGRASS("r.info", map = "raster_image")
#> +----------------------------------------------------------------------------+
#> | Map: raster_image Date: Wed Jan 18 08:36:35 2017 |
#> | Mapset: file17053b43fb4e Login of Creator: jose |
#> | Location: file170531b5b35a |
#> | DataBase: /tmp/Rtmpn8cS5A |
#> | Title: ( raster_image ) |
#> | Timestamp: none |
#> |----------------------------------------------------------------------------|
#> | |
#> | Type of Map: raster Number of Categories: 0 |
#> | Data Type: DCELL |
#> | Rows: 115 |
#> | Columns: 80 |
#> | Total Cells: 9200 |
#> | Projection: x,y |
#> | N: 334000 S: 329400 Res: 40 |
#> | E: 181600 W: 178400 Res: 40 |
#> | Range of data: min = 128.434005737305 max = 1805.78002929688 |
#> | |
#> | Data Description: |
#> | generated by r.in.bin |
#> | |
#> | Comments: |
#> | r.in.bin --overwrite -d input="/tmp/Rtmpn8cS5A/file170531b5b35a/file\ |
#> | 17053b43fb4e/.tmp/josecomp/X530" output="raster_image" bytes=8 heade\ |
#> | r=0 bands=1 order="native" north=334000 south=329400 east=181600 wes\ |
#> | t=178400 rows=115 cols=80 anull=127 |
#> | |
#> +----------------------------------------------------------------------------+
out_raster <- rgrass7::readRAST("raster_image")
#> Creating BIL support files...
#> Exporting raster as floating values (bytes=8)
#> 0% 100%
dim(raster_image)
#> [1] 9200 1
plot(raster_image)
dim(out_raster)
#> [1] 1 1
plot(out_raster)
#> Warning in min(x): no non-missing arguments to min; returning Inf
#> Warning in max(x): no non-missing arguments to max; returning -Inf
#> Error in seq.default(zlim[1], zlim[2], length.out = length(col) + 1): 'from' cannot be NA, NaN or infinite