Search code examples
rr-sprgdal

Rdgal don't working well to save a shapefile


I'm trying to save a shapefile format with detection rates using the "rgdal" packages, but the following error occurs:

Error in showSRID(uprojargs, format = "PROJ", multiline = "NO") : 
  Can't parse PROJ.4-style parameter string
+proj=longlat +ellps=WGS84+datum=WGS84+no_def

How to fix?

Reproductive example

library(rgdal)
library(sp)
library(camtrapR)

Long<-c(-53.59390711, -53.58148303)
Lat<-c(-4.633924739, -4.6340598)
df1<-data.frame(Long,Lat)
df1$Station<-NA
df1[df1$Long=="-53.59390711",]$Station<-"w"
df1[df1$Long=="-53.58148303",]$Station<-"z"

Station<-c("w","w","w","w","w","w","w","w","w","w","z","z","z","z","z","z","z","z","z","z")
Species<-c("a","a","a","b","b","b","c","c","c","c","a","b","b","b","b","b","c","c","c","c")
df2<-data.frame(Station, Species)


detectionMaps(CTtable=df1,recordTable=df2,Xcol="Long",Ycol="Lat",stationCol="Station",speciesCol="Species",speciesToShow="a",richnessPlot=FALSE,speciesPlots=FALSE,
writeShapefile=TRUE,shapefileDirectory=tempdir(),shapefileName="sp_a", shapefileProjection="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_def")

#The shapefile should be created in this directory: C:\Users\...\AppData\Local\Temp\
          

Solution

  • This is an issue connected to the change from PROJ4 to PROJ6 in rgdal/sp. For you the issue is a bit deeper because the camtrapR package is not yet updated to deal with PROJ6.You can read more about the transition to PROJ6 here.

    Without going too deep into it the solution for you would be to downgrade to an older version of sp and rgdal.

    For sp (< 1.4-2) and rgdal (< 1.5-8).

    EDIT: Since you can define the PROJ String yourself you can also first try: "+init=epsg:4326". This might still work.