Closed manomuthus closed 3 years ago
Please see #27 and #31, and try to install from source from github, or from the link to a Windows binary package https://github.com/rsbivand/rgrass7/files/6285516/rgrass7_0.2-6.zip built some time ago. Please report back. Note that you should set the projection immediately after initialising GRASS, as the location you create should have the same projection as the files being added. If you can confirm tha this removes your problem, I'll submit to CRAN soon.
I unistalled previous veriosn and reinstalled rgrass7
(0.2-6) from your link. But I still get the following error.
Error in sp::CRS(getLocationProj()) :
PROJ4 argument-value pairs must begin with +: PROJCS["unknown",
GEOGCS["wgs84",
DATUM["WGS_1984",
SPHEROID["WGS_1984",6378137,298.257223563]],
PRIMEM["Greenwich",0,
AUTHORITY["EPSG","8901"]],
UNIT["degree",0.0174532925199433,
AUTHORITY["EPSG","9122"]]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",87],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
UNIT["metre",1,
AUTHORITY["EPSG","9001"]],
AXIS["Easting",EAST],
AXIS["Northing",NORTH]]
I set the projection immediatly after initialising GRASS using execGRASS("g.proj", flags = "c", proj4 = "+proj=utm +zone=45 +datum=WGS84 +units=m +no_defs")
. The proj4
string is derived using crs(rast)
. I hope I am doing everything right.
I'll re-try on Windows (I'm in Linux now), the binary package is some months old. Please also add all the code you used to apply the projection (immediately after instantiating the GRASS session), it may be your use of "PERMANENT"
, but without the code it is hard to say.
Thank you. The complete code is provided in the initial comment.
Windows, R 4.1.1, GRASS 7.8.5, CRAN sp and rgrass7, no g.proj
:
> library(raster)
Loading required package: sp
> load("rast.rda")
> library(rgrass7)
Loading required package: XML
GRASS GIS interface loaded with GRASS version: (GRASS not running)
> initGRASS(gisBase="C:/Program Files/GRASS GIS 7.8", mapset = "PERMANENT", override=TRUE)
gisdbase C:/Users/RB/AppData/Local/Temp/RtmpOUxb7k
location file225037446716
mapset PERMANENT
rows 1
columns 1
north 1
south 0
west 0
east 1
nsres 1
ewres 1
projection:
XY location (unprojected)
> rast_sgdf <- as(rast, "SpatialGridDataFrame")
> use_sp()
> writeRAST(rast_sgdf, vname="rast_grass", flags = "overwrite")
100%
> rg <- readRAST("rast_grass")
Error in sp::CRS(getLocationProj()) : NA
> packageVersion("sp")
[1] '1.4.5'
> packageVersion("rgrass7")
[1] '0.2.5'
>
Old updated rgrass7, no g.proj
:
> install.packages("rgrass7_0.2-6.zip")
Installing package into 'C:/Users/RB/Documents/R/win-library/4.1'
(as 'lib' is unspecified)
inferring 'repos = NULL' from 'pkgs'
package 'rgrass7' successfully unpacked and MD5 sums checked
> library(raster)
Loading required package: sp
> library(rgrass7)
Loading required package: XML
GRASS GIS interface loaded with GRASS version: (GRASS not running)
> packageVersion("sp")
[1] '1.4.5'
> packageVersion("rgrass7")
[1] '0.2.6'
> load("rast.rda")
> initGRASS(gisBase="C:/Program Files/GRASS GIS 7.8", mapset = "PERMANENT", override=TRUE)
gisdbase C:/Users/RB/AppData/Local/Temp/Rtmp0EUcCj
location file1c05a116da1
mapset PERMANENT
rows 1
columns 1
north 1
south 0
west 0
east 1
nsres 1
ewres 1
> rast_sgdf <- as(rast, "SpatialGridDataFrame")
> use_sp()
> writeRAST(rast_sgdf, vname="rast_grass", flags = "overwrite")
100%
> rg <- readRAST("rast_grass")
Error in sp::CRS(getLocationProj()) : NA
Setting g.proj
with old update rgrass7 shows a further problem:
> library(raster)
Loading required package: sp
> library(rgrass7)
Loading required package: XML
GRASS GIS interface loaded with GRASS version: (GRASS not running)
> packageVersion("sp")
[1] '1.4.5'
> packageVersion("rgrass7")
[1] '0.2.6'
> load("rast.rda")
> initGRASS(gisBase="C:/Program Files/GRASS GIS 7.8", mapset = "PERMANENT", override=TRUE)
gisdbase C:/Users/RB/AppData/Local/Temp/Rtmpwx11mg
location file18546c4872e2
mapset PERMANENT
rows 1
columns 1
north 1
south 0
west 0
east 1
nsres 1
ewres 1
> execGRASS("g.proj", flags = "c", proj4 = "+proj=utm +zone=45 +datum=WGS84 +units=m +no_defs")
Default region was updated to the new projection, but if you have multiple
mapsets `g.region -d` should be run in each to update the region from the
default
Projection information updated
> getLocationProj()
ERROR 1: PROJ: proj_as_wkt: SQLite error on SELECT name, ellipsoid_auth_name, ellipsoid_code, prime_meridian_auth_name, prime_meridian_code, area_of_use_auth_name, area_of_use_code, publication_date, deprecated FROM geodetic_datum WHERE auth_name = ? AND code = ?: no such column: area_of_use_auth_name
[1] ""
> Sys.getenv("PROJ_LIB")
[1] "C:/Users/RB/Documents/R/win-library/4.1/rgdal/proj"
> rgdal::rgdal_extSoftVersion()
GDAL GDAL_with_GEOS PROJ sp EPSG
"3.2.1" "TRUE" "7.2.1" "1.4-5" "v10.008"
This is not the same problem, but is because rgdal on load (used by sp::CRS()
) on Windows sets PROJ_LIB
, leading g.proj
to fail in looking up the WKT2 version as it is not the same EPSG version (and proj.db
was re-organized between EPSG 9 and 10):
> packageVersion("rgdal")
[1] '1.5.27'
> library(RSQLite)
> db <- dbConnect(SQLite(), dbname=file.path("C:/Program Files/GRASS GIS 7.8/share/proj", "proj.db"))
> (metadata <- dbReadTable(db, "metadata"))
key value
1 EPSG.VERSION v9.8.6
2 EPSG.DATE 2020-01-22
3 ESRI.VERSION ArcMap 10.8.0
4 ESRI.DATE 2019-12-01
5 IGNF.SOURCE https://geodesie.ign.fr/contenu/fichiers/IGNF.v3.1.0.xml
6 IGNF.VERSION 3.1.0
7 IGNF.DATE 2019-05-24
> dbDisconnect(db)
Knowing this, a further work-around has been added to getLocationProj()
, and a new Windows binary created: (rgrass7_0.2-6.zip. With this (and correcting an omission of correctly setting the GRASS region) and rast.rda
rast.rda.zip:
> install.packages("rgrass7_0.2-6.zip")
Installing package into 'C:/Users/RB/Documents/R/win-library/4.1'
(as 'lib' is unspecified)
inferring 'repos = NULL' from 'pkgs'
package 'rgrass7' successfully unpacked and MD5 sums checked
> library(rgrass7)
Loading required package: XML
GRASS GIS interface loaded with GRASS version: (GRASS not running)
> library(raster)
Loading required package: sp
> load("rast.rda")
> initGRASS(gisBase="C:/Program Files/GRASS GIS 7.8", mapset = "PERMANENT", override=TRUE)
gisdbase C:/Users/RB/AppData/Local/Temp/RtmpUzAsbn
location file2f0444971c68
mapset PERMANENT
rows 1
columns 1
north 1
south 0
west 0
east 1
nsres 1
ewres 1
> execGRASS("g.proj", flags = "c", proj4 = "+proj=utm +zone=45 +datum=WGS84 +units=m +no_defs")
Default region was updated to the new projection, but if you have multiple
mapsets `g.region -d` should be run in each to update the region from the
default
Projection information updated
> getLocationProj()
ERROR 1: PROJ: proj_as_wkt: SQLite error on SELECT name, ellipsoid_auth_name, ellipsoid_code, prime_meridian_auth_name, prime_meridian_code, area_of_use_auth_name, area_of_use_code, publication_date, deprecated FROM geodetic_datum WHERE auth_name = ? AND code = ?: no such column: area_of_use_auth_name
[1] "+proj=utm +no_defs +zone=45 +a=6378137 +rf=298.257223563 +towgs84=0.000,0.000,0.000 +type=crs +to_meter=1"
> rast_sgdf <- as(rast, "SpatialGridDataFrame")
> use_sp()
> writeRAST(rast_sgdf, vname="rast_grass", flags = "overwrite")
100%
> rg <- readRAST("rast_grass")
ERROR 1: PROJ: proj_as_wkt: SQLite error on SELECT name, ellipsoid_auth_name, ellipsoid_code, prime_meridian_auth_name, prime_meridian_code, area_of_use_auth_name, area_of_use_code, publication_date, deprecated FROM geodetic_datum WHERE auth_name = ? AND code = ?: no such column: area_of_use_auth_name
Creating BIL support files...
Exporting raster as floating values (bytes=8)
100%
Warning message:
In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
Discarded datum unknown in Proj4 definition
> summary(rg)
Object of class SpatialGridDataFrame
Coordinates:
min max
[1,] 0 1
[2,] 0 1
Is projected: TRUE
proj4string :
[+proj=utm +zone=45 +ellps=WGS84 +units=m +no_defs]
Grid attributes:
cellcentre.offset cellsize cells.dim
1 0.5 1 1
2 0.5 1 1
Data attributes:
rast_grass
Min. : NA
1st Qu.: NA
Median : NA
Mean :NaN
3rd Qu.: NA
Max. : NA
NA's :1
> rast
class : RasterLayer
dimensions : 20, 40, 800 (nrow, ncol, ncell)
resolution : 10, 10 (x, y)
extent : 333004, 333404, 3060402, 3060602 (xmin, xmax, ymin, ymax)
crs : +proj=utm +zone=45 +datum=WGS84 +units=m +no_defs
source : memory
names : nakkhu_hosp_10m
values : 1207.154, 1223.907 (min, max)
> summary(rast_sgdf)
Object of class SpatialGridDataFrame
Coordinates:
min max
s1 333004 333404
s2 3060402 3060602
Is projected: TRUE
proj4string :
[+proj=utm +zone=45 +datum=WGS84 +units=m +no_defs]
Grid attributes:
cellcentre.offset cellsize cells.dim
s1 333009 10 40
s2 3060407 10 20
Data attributes:
nakkhu_hosp_10m
Min. :1207
1st Qu.:1209
Median :1210
Mean :1211
3rd Qu.:1213
Max. :1224
NA's :594
Warning message:
In wkt(obj) : CRS object has no comment
> execGRASS("r.info", map="rast_grass")
+----------------------------------------------------------------------------+
| Map: rast_grass Date: Wed Sep 29 10:25:32 2021 |
| Mapset: PERMANENT Login of Creator: RB |
| Location: file2f0444971c68 |
| DataBase: C:/Users/RB/AppData/Local/Temp/RtmpUzAsbn |
| Title: |
| Timestamp: none |
|----------------------------------------------------------------------------|
| |
| Type of Map: raster Number of Categories: 0 |
| Data Type: DCELL |
| Rows: 20 |
| Columns: 40 |
| Total Cells: 800 |
| Projection: UTM (zone 45) |
| N: 3060602.4038 S: 3060402.4038 Res: 10 |
| E: 333403.9801 W: 333003.9801 Res: 10 |
| Range of data: min = 1207.15441894531 max = 1223.90710449219 |
| |
| Data Description: |
| generated by RINBIN~1 |
| |
| Comments: |
| RINBIN~1 --overwrite -d input="C:/Users/RB/AppData/Local/Temp/RtmpUz\ |
| Asbn/file2f0444971c68/PERMANENT/.tmp/unknown/X916" output="rast_gras\ |
| s" bytes=8 header=0 bands=1 order="native" north=3060602.4038 south=\ |
| 3060402.4038 east=333403.9801 west=333003.9801 rows=20 cols=40 anull\ |
| =1206 |
| |
+----------------------------------------------------------------------------+
> execGRASS("r.stats", flags="A", input="rast_grass")
100%
*
> execGRASS("g.region", flags="p")
projection: 1 (UTM)
zone: 45
datum: wgs84
ellipsoid: wgs84
north: 1
south: 0
west: 0
east: 1
nsres: 1
ewres: 1
rows: 1
cols: 1
cells: 1
> execGRASS("g.region", raster="rast_grass")
> execGRASS("g.region", flags="p")
projection: 1 (UTM)
zone: 45
datum: wgs84
ellipsoid: wgs84
north: 3060602.4038
south: 3060402.4038
west: 333003.9801
east: 333403.9801
nsres: 10
ewres: 10
rows: 20
cols: 40
cells: 800
> rg <- readRAST("rast_grass")
ERROR 1: PROJ: proj_as_wkt: SQLite error on SELECT name, ellipsoid_auth_name, ellipsoid_code, prime_meridian_auth_name, prime_meridian_code, area_of_use_auth_name, area_of_use_code, publication_date, deprecated FROM geodetic_datum WHERE auth_name = ? AND code = ?: no such column: area_of_use_auth_name
Creating BIL support files...
Exporting raster as floating values (bytes=8)
100%
Warning message:
In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
Discarded datum unknown in Proj4 definition
> summary(rg)
Object of class SpatialGridDataFrame
Coordinates:
min max
[1,] 333004 333404
[2,] 3060402 3060602
Is projected: TRUE
proj4string :
[+proj=utm +zone=45 +ellps=WGS84 +units=m +no_defs]
Grid attributes:
cellcentre.offset cellsize cells.dim
1 333009 10 40
2 3060407 10 20
Data attributes:
rast_grass
Min. :1207
1st Qu.:1209
Median :1210
Mean :1211
3rd Qu.:1213
Max. :1224
NA's :594
In summary, the further problem beyond those resolved in April, was that recent CRAN rgdal binaries bundle a more recent and incompatible version of proj.db
than GRASS Windows stand-alone 7.8.5. The error message comes from PROJ called by g.proj
and is not captured by stderr
, so will be shown when a version mismatch is present.
library(raster)
load("rast.rda")
rast
rast_sgdf <- as(rast, "SpatialGridDataFrame")
td <- tempdir()
SG <- as(rast_sgdf, "SpatialGrid") #set region on initiation
library(rgrass7)
initGRASS(gisBase="C:/Program Files/GRASS GIS 7.8", home=td, SG=SG, mapset = "PERMANENT", override=TRUE)
execGRASS("g.proj", flags = "c", proj4 = slot(crs(rast), "projargs"))
writeRAST(rast_sgdf, vname="rast_grass", flags = "overwrite")
execGRASS("g.region", raster="rast_grass")
rg <- readRAST("rast_grass")
(rrg <- as(rg, "RasterLayer"))
all.equal(rast, rrg)
Many thanks. It works now with rgdal 1.5-27.
source 0.2-6 released on CRAN, macOS and Windows binaries to follow.
I have just started using
rgrass7
and getting error messages when I try to usereadRAST
. Please see belowtrying to read rast_grass
I read somewhere that setting the projection using proj4 will solve this issue, so tried the following
but now I get the following error message
What am I doing wrong?
data