rr-spr-maptools

Problems with order of attributes of CRS 4326 in R


I load a shape file using R maptools package

Subcat<-readShapeSpatial("Contour500/Catchments500.shp",proj4string = CRS('+init=epsg:4326'))

class(Subcat)
[1] "SpatialPolygonsDataFrame"
attr(,"package")
[1] "sp"

Then I load another shape file

load("Temperature/WCAdj.RData")
class(WcT$Geoloc)
[1] "SpatialPoints"
attr(,"package")
[1] "sp"

I want to use the over function from sp package

over(WcT$Geoloc,Subcat)

But when I run it I get the next error

Error: identicalCRS(x, y) is not TRUE

This is strange as I used the same CRS for both files CRS('+init=epsg:4326'). I double checked and found a slight difference in the order of the attributes of the CRS

proj4string(Subcat)
[1] "+init=epsg:4326 +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"

proj4string(WcT$Geoloc)
[1] "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

The only difference is the order of the Attributes (+ellps, +no_defs and +datum), but all values are the same. I solved this by loading again Subcat using

Subcat<-readShapeSpatial("Contour500/Catchments500.shp",proj4string = CRS("+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))

However I wanted to know if there is another solution as I want to avoid the same error in the future and wanted to know where this error comes from. I checked the details of the CRS definition in (https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/OverviewCoordinateReferenceSystems.pdf ) and in the SP package documentation https://cran.r-project.org/web/packages/sp/sp.pdf , but they do not give too many details regarding the order of the attributes.

Has anyone had the same issue?

Does anyone know how to avoid this?

Just in case

sessionInfo()
R version 3.3.3 (2017-03-06)

other attached packages:
[1] rgeos_0.3-2     maptools_0.8-27 rgdal_0.8-11    sp_1.0-14 

Thanks in advance!


Solution

  • The solution is simpler than i thought, just update all packages. After writing to the author he said that sometimes, when R is updated, old versions of packages may experience this type of problems, thus they require to be updated as well.