添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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!

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid …

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.