How to correctly compare the CRS of 'sf' and 'raster' objects?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

How to correctly compare the CRS of 'sf' and 'raster' objects?

Mauricio Zambrano-Bigiarini-3
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--------

# 1) Getting the character corresponding to lat/lon CRS string <- 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) <-

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

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

------- 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

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
mailto : [hidden email]
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.

R-sig-Geo mailing list
[hidden email]