Reputation: 21
I wrote the following code to create a map with the Eurostat package. The (whole) code works and I get a quite nice map, but I always receive the following message:
"old-style crs object detected; please recreate object with a recent sf::st_crs()" - what can I do to update my code correctly?
Thank you!
europe <- eurostat_geodata_60_2016
# basic map
ggplot(europe) + geom_sf() +
coord_sf(crs = 3035)
Upvotes: 2
Views: 1428
Reputation: 94317
The object europe_geodata_60_2016
which you copied to europe
was created using an old version of sf
package that stores coordinate systems differently to what current versions do. Ultimately the raw form of the CRS of that spatial data frame is stored in an attribute of the geometry column and is this:
> str(attr(eurostat_geodata_60_2016$geometry,"crs"))
List of 2
$ epsg : int 4326
$ proj4string: chr "+proj=longlat +datum=WGS84 +no_defs"
- attr(*, "class")= chr "crs"
Storing the CRS as a proj4string
is not the best way to do it, which is why this was deprecated. You can reset this easily enough, given that you can see here that the EPSG code is 4326. So you can do:
> europe = eurostat_geodata_60_2016
> st_crs(europe) = 4326
old-style crs object detected; please recreate object with a recent sf::st_crs()
> str(attr(europe$geometry,"crs"))
List of 2
$ input: chr "EPSG:4326"
$ wkt : chr "GEOGCRS[\"WGS 84\",\n DATUM[\"World Geodetic System 1984\",\n ELLIPSOID[\"WGS 84\",6378137,298.257223"| __truncated__
- attr(*, "class")= chr "crs"
and you can see the modern way of storing the CRS, as roughly the input you gave to it (with "EPSG:" added for clarity) and the wkt
string which is the authoritative CRS description.
You can also do it this way, which looks like a null-operation but serves to reassign the CRS by interpreting the old deprecated form:
> europe = eurostat_geodata_60_2016
> st_crs(europe) = st_crs(europe)
old-style crs object detected; please recreate object with a recent sf::st_crs()
old-style crs object detected; please recreate object with a recent sf::st_crs()
The warning messages are a bit unnecessary here since you are doing exactly what it suggests you do! But the CRS are frequently checked and this warning appears whatever you may be doing with a deprecated CRS! But from this point onwards you shouldn't see that warning message for this data frame.
Upvotes: 4