inlabru-org / inlabru

inlabru
https://inlabru-org.github.io/inlabru/
76 stars 21 forks source link

INLA::inla.CRS("globe") within int.slines() within ipoints() returning NA #79

Closed ghost closed 3 years ago

ghost commented 3 years ago

Have been tiding up some old bits of code and found that the ipoints() function is not working as before for SpatialLines.

Traced the problem into the int.slines() function within ipoints(), where INLA::inla.CRS("globe") is called.

inla.CRS("globe") is returning "NA", which seems to lead to the error message "Error in if (is.projected(obj)) { : missing value where TRUE/FALSE needed".

Replacing INLA::inla.CRS("globe") with INLA::inla.CRS("lambert_globe") lets the function proceed. However do the following lines also need to be changed in this case?

 mp3d <- SpatialPoints((coordinates(sp3d) + coordinates(ep3d)) / 2,
                                     proj4string = geocentric.crs)

ips <- coordinates(spTransform(mp3d, crs))
w <- spDists(coordinates(spTransform(sp3d, CRSobj = longlat.crs))[, 1:2, drop = FALSE],
             coordinates(spTransform(ep3d, CRSobj = longlat.crs))[, 1:2, drop = FALSE],
             diagonal = TRUE, longlat = TRUE)

Package versions: INLA_20.08.04
inlabru_2.1.13.999

Cheers,

H

finnlindgren commented 3 years ago

This is an issue with the PROJ4/PROJ6 transition in rgdal and sp; the apparent "NA" is just the proj4string being NA, but it has valid WKT information that is what is actually used (see cat(sp::wkt(INLA::inla.CRS("globe")))). Unfortunately, a bug was introduced in a recent rgdal version where it relied on sp::is.projected() which hadn't been updated to handle this kind of CRS object. This has now been fixed in Roger Bivand's sp repository; try installing it with remotes::install_github("https://github.com/rsbivand/sp/tree/master") I don't know when that will make it onto CRAN; I assume in the next update of rgdal and sp.

lambert_globe is a flat projection, and globe is the actual globe, so that replacement doesn't work.

finnlindgren commented 3 years ago

The problem was introduced sometime between rgdal 1.5-12 and 1.5-16, with sp 1.4-2.

ghost commented 3 years ago

Perfect cheers, updating to remotes::install_github("https://github.com/rsbivand/sp/tree/master") has worked.

finnlindgren commented 3 years ago

I believe this has been fixed with the latest sp release, 1.4-4.