[R-sig-Geo] How to correctly compare the CRS of 'sf' and 'raster' objects?

Mauricio Zambrano-Bigiarini m@ur|c|o@z@mbr@no @end|ng |rom u|ronter@@c|
Sat May 2 20:14:14 CEST 2020


Dear mailing list,

I'm wondering what is the correct way of comparing the CRS of a
vectorial (simple feature) and a raster object.

Please look a the following reproducible example:

------- CODE START--------
library(sf)
library(raster)

# 1) Getting the character corresponding to lat/lon CRS string
latlon.crs <- st_crs(4326)$proj4string

# 2) Creating a simple feature point geometry and assigning lat/lon CRS
vec <- st_sfc(st_point(c(0,0)), st_point(c(1,1)))
st_crs(vec) <- 4326

# 3) Creating a simple feature point geometry and assigning lat/lon CRS
rast <- raster(nrows=108, ncols=21, xmn=0, xmx=10)
crs(rast) <- latlon.crs

# 4) Getting the CRS of the point and raster objects
vect.crs <- sf::st_crs(vec)$proj4string
rast.crs <- sf::st_crs(rast)$proj4string

# 5) Making the CRS comparison
are.equal <- vect.crs == rast.crs

------- CODE END--------


The previous comparison works fine in R 4.0.0 (raster_3.1-5 sp_1.4-1,
sf_0.9-2) with the following set of libraries:

GEOS 3.5.1, GDAL 2.2.2, PROJ 4.9.2

but the same line of code fails with the newer set of libraries:

GEOS 3.8.1, GDAL 3.0.4, PROJ 7.0.0


Is there any "correct" way of comparing the CRS of the previous
vectorial and raster object in 'sf', something similar to
sp::identicalCRS?

If so, what is the minimum required version of the GEOS, GDAL, and
PROJ libraries?


Thanks in advance for any help,


Mauricio Zambrano-Bigiarini, PhD

=====================================
Department of Civil Engineering
Faculty of Engineering and Sciences
Universidad de La Frontera, Temuco, Chile
http://hzambran.github.io/
=====================================
mailto : mauricio.zambrano using ufrontera.cl
work-phone : +56 45 259 2812
=====================================
"The world is changed by your example,
not your opinion". (Paulo Coelho)
=====================================
Linux user #454569 -- Linux Mint user

-- 
La información contenida en este correo electrónico y cualquier anexo o 
respuesta relacionada, puede contener datos e información confidencial y no 
puede ser usada o difundida por personas distintas a su(s) destinatario(s). 
Si usted no es el destinatario de esta comunicación, le informamos que 
cualquier divulgación, distribución o copia de esta información constituye 
un delito conforme a la ley chilena. Si lo ha recibido por error, por favor 
borre el mensaje y todos sus anexos y notifique al remitente.



More information about the R-sig-Geo mailing list