As explained here, the PROJ library has changed a lot and one should stop using proj.4 strings
. To me it is not clear, what I should do instead. This answer explains, how I could deal with the problem without any changes in one concrete use case, but to me it seems, this is more a hack than a good idea on a long term. (At the moment, this is the only thing, I can do. The only alternative is not to update important packages.)
Is there any advice for the following process:
For example, I download data (e.g. boundaries of cantons) as geojson-files from map.geo.admin.ch.
As we don't want to do the process each time, we import the data and save it as RData-file:
boundaries <- "my_boundaries.geojson"
data <- geojsonio::geojson_read(boundaries, what = "sp")
# Warnmeldung:
# In showSRID(uprojargs, format = "PROJ", multiline = "NO") :
# Discarded datum Unknown based on Bessel 1841 ellipsoid in CRS definition,
# but +towgs84= values preserved
data2 <- sp::spTransform(
data,
sp::CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
save(data2, "boundaries.RData")
When I analyse data according to polygons, I do the following:
boundaries <- load("boundaries.RData")
data_coords <- data.frame( # from some source mydata
lat = mydata$lat,
lng = mydata$lng, stringsAsFactors = FALSE)
spdf <- sp::SpatialPointsDataFrame(
coords = data_coords,
data = data_coords,
proj4string = raster::crs(boundaries))
df_in <- sp::over(spdf , boundaries , fn = NULL)
So my question is:
- What is the proper process for GIS-data after the major change in PROJ library?
- What does this mean in our concrete case above?
- I also found a nice example with plots, but it also uses proj4string. What should I do with this example?
(Unfortunately, I am not a GIS-expert)
Using CRS
throws an error, if used as suggested in the answer by Roger Bivand below:
data2 <- sp::spTransform(
data,
sp::CRS(SRS_string = "OGC:CRS84"))
# Fehler in h(simpleError(msg, call)) :
# Fehler bei der Auswertung des Argumentes 'CRSobj' bei der Methodenauswahl
# für Funktion 'spTransform': Fehlender Wert, wo TRUE/FALSE nötig ist
This is working well:
spdf <- sp::SpatialPointsDataFrame(
coords = data_coords,
data = data_coords)
slot(spdf, "proj4string") <- slot(boundaries, "proj4string")