7

I have a script which contains several r objects which are CRSs that I use for transforming spatial objects. After updating R and many packages, there is a warning which wasn't there before.

LCC <- CRS("+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs")

Warning message:
In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
  Discarded datum Unknown based on GRS80 ellipsoid in CRS definition

I understand that this is due to a change in how spatial information is stored... PROJ4 to PROJ6 upgrade and "Discarded datum" warnings

..but beyond that, I don't understand what this error means or if I need to do anything in response.

Any thoughts?

1 Answer 1

9

Your proj4 string lacks a +datum parameter, and PROJ is warning you.

To remove the warning, add a +datum parameter with the correct datum that the data was defined as.

This is likely to be WGS84 or NAD83, which are very similar, or unlikely to be NAD27 which is old but does give different results from the others.

I replicate your error:

LCC <- CRS("+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs")
## Warning message:
## In showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj) :
##  Discarded datum Unknown based on GRS80 ellipsoid in CRS definition

and I can construct three other CRS objects with the three datums and these don't generate the error (if you can't see the difference in these strings, check its not scrolled off the right of your screen...)

LCC84 <- CRS("+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=WGS84 +units=m +no_defs")
LCC83 <- CRS("+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs")
LCC27 <- CRS("+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD27 +units=m +no_defs")

As a test (and there's probably better ways of doing this) I'll generate some lat-long points in EPSG:4326 and see where they end up when transformed with these CRS.

> pts = data.frame(x=1:20, y=1:20, z=LETTERS[1:20])
> coordinates(pts) = ~x+y
> proj4string(pts)="+init=epsg:4326"

now transform those points using the four different CRS, and get the x-y points as a matrix:

> xydef = coordinates(spTransform(pts, LCC))
> xy84 = coordinates(spTransform(pts, LCC84))
> xy83 = coordinates(spTransform(pts, LCC83))
> xy27 = coordinates(spTransform(pts, LCC27))

The default datum appears to be NAD83, based on this:

> all(xydef == xy83)
[1] TRUE

The difference between this and the WGS84 datum is small - these are metres:

> xydef - xy84
               x             y
1  -1.375843e-04 -0.0001334306
2  -1.300666e-04 -0.0001359694
3  -1.227129e-04 -0.0001382660
4  -1.155287e-04 -0.0001403205
5  -1.085084e-04 -0.0001421534
6  -1.016594e-04 -0.0001437627

but the NAD27 datum is very different, a few hundred metres:

> xydef - xy27
            x        y
1  191.783605 187.6420
2  176.501677 191.4228
3  161.595454 194.7053
4  147.070099 197.5092
5  132.930356 199.8542
6  119.180556 201.7600
7  105.824604 203.2458
8   92.865987 204.3309

So the answer is: 1. add the +datum= to your projection strings, 2. use the correct datum (probably NAD83 or WGS84, either won't matter much, alternates like NAD27 unlikely, check the source), 3. use the sf package and write your projections as WKT (its the default) instead of proj strings.

2
  • This more or less answers my question. But as you suggested at the end of your answer, I've learned in my research that it would be preferable to write the projection as WKT instead. Do you have any suggestions on how to do this? This is what I'm trying to figure out now. Commented Jan 22, 2021 at 19:49
  • 2
    You can use sp::wkt(LCC) to convert to WKT. You'll still get errors with unspecified datums though! Using sf and saving to GeoPackage will store the WKT in preference to the Proj string.
    – Spacedman
    Commented Jan 22, 2021 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.