initGRASS issue with version 0.2.8
Closed this issue · 7 comments
Hello,
I am using rgrass7
to setup throwaway GRASS locations.
GRASS version : 7.8.6 (UbuntuGIS stable PPA)
R version : 3.6.3
Ubuntu 20.04.4
With rgrass7
0.2.6 I am routinely using :
gisbase = "/usr/lib/grass78/"
rgrass7::initGRASS(gisbase,home=tempdir(),mapset="PERMANENT",override = TRUE)
and then calls to g.proj
and g.region
to set the location properties (through execGRASS
).
I know I could use the SG option to set everything at once, but in the past I had a few issues with some rasters when moving back and forth between GRASS and R (slight changes in the resolution) so I prefer to define the location properties this way.
Now with rgrass7
0.2.8 :
rgrass7::initGRASS(gisbase,home=tempdir(),mapset="PERMANENT",override = TRUE)
returns the following error :
Error in execGRASS("g.proj", flags = c("w"), intern = TRUE, ignore.stderr = ignore.stderr) :
The command:
g.proj -w
produced an error (1) during execution:
ATTENTION: fichier <PROJ_INFO> introuvable pour le secteur
<file3f47d24ad6933>
ATTENTION: fichier <PROJ_UNITS> introuvable pour le secteur
<file3f47d24ad6933>
ERREUR : Fichiers de projection manquant
Due to the non-existing projection information at this stage in the location (which was not an issue with 0.2.6).
I tried to use the SG option but I also get an error in this case (rgrass7
0.2.8), where it seems to expect a latlon system whereas the input terra
SpatRaster
(dem
) is UTM31N.
dem0 <- as(raster(dem), "SpatialGrid")
rgrass7::initGRASS(gisbase,SG=dem0,home=tempdir(),mapset="PERMANENT",override = TRUE)
Error in execGRASS("g.region", save = "input", flags = "overwrite") :
The command:
g.region --overwrite save=input
produced an error (1) during execution:
ERREUR : Lattitude Nord illégale : 4.91676e+06
Where 4.91676e+06 is the ymax (northing) of dem
, and obviously not a latitude.
> dem
class : SpatRaster
dimensions : 1596, 1654, 1 (nrow, ncol, nlyr)
resolution : 30, 30 (x, y)
extent : 539757.5, 589377.5, 4868879, 4916759 (xmin, xmax, ymin, ymax)
coord. ref. : WGS 84 / UTM zone 31N (EPSG:32631)
source : memory
name : srtm_cevennes_utm
min value : 85
max value : 1672
Would you have any idea about what could cause this change of behavior ?
Best regards,
Vincent
Please clarify what terra dem
is? Is it the internal representation of terra/inst/ex/elev.tif
?
For the first part of your issue, please test:
remotes::install_github("rsbivand/rgrass", ref="init_no_SG_53")
in your setting. Note that although I've tested this with GRASS 7.8.6, it is expected that issues are not retrospective; your R and GRASS versions are well behind current. This fix also works for GRASS 8.0.1 which had the same error with rgrass7 0.2-8; I use R 4.1.3.
Hi Roger,
(1) dem is SpatRaster (SRTM DEM I use for testing), no it is not terra/inst/ex/elev.tif
.
> dem
class : SpatRaster
dimensions : 1596, 1654, 1 (nrow, ncol, nlyr)
resolution : 30, 30 (x, y)
extent : 539757.5, 589377.5, 4868879, 4916759 (xmin, xmax, ymin, ymax)
coord. ref. : WGS 84 / UTM zone 31N (EPSG:32631)
source : memory
name : srtm_cevennes_utm
min value : 85
max value : 1672
(2) I've tested with the version you sent, and it seems to be working now.
Thanks a lot,
Vincent
Thanks!
What happens using dem
as SG=
as a SpatRaster
object, in addition to trying as a SpatialGridDataFrame
? If this still fails, please make the object available for further debugging.
Passing dem
as a SpatRaster
works.
Passing dem
as either a SpatialGrid
or SpatialGridDataFrame
leads to the following error (Error : illegal North latitude):
Error in execGRASS("g.region", save = "input", flags = "overwrite", ignore.stderr = ignore.stderr) :
The command:
g.region --overwrite save=input
produced an error (1) during execution:
ERREUR : Lattitude Nord illégale : 4.91676e+06
I put dem
as a tiff here if needed :
https://filesender.renater.fr/?s=download&token=d360f37f-de36-44c3-858d-923347a96ee6
Thanks, very useful, a simple logic error in 0.2-8. I'll merge this branch into main shortly.
rgrass7 1.2-9 on CRAN!
I can confirm everything works on my side.
Thanks Roger,
Vincent