isciences / exactextractr

R package for fast and accurate raster zonal statistics
https://isciences.gitlab.io/exactextractr/
281 stars 26 forks source link

Ambiguous warning when CRS of raster layer and sf object mismatch #101

Closed MDanialSyed closed 1 year ago

MDanialSyed commented 1 year ago

Hi,

I recently encountered a warning message when attempting to extract a raster with CRS WGS84 to an sf object with CRS EPSG:3035. The exact_extract() function completes the extraction, but produces the following warning:

Warning message: In .local(x, y, ...) : Polygons transformed to raster CRS (EPSG:NA)

However, the relevant line in the source code indicates that the polygons are actually transformed to the raster CRS (WGS:84 in this case) not 'EPSG:NA' due to the CRS mismatch with the sf object. Therefore, this warning seems ambiguous.

The reason for this maybe the call to sf::st_crs(x)$epsg in this code: warning("Polygons transformed to raster CRS (EPSG:", sf::st_crs(x)$epsg, ")

Since we are calling an object ($epsg) that doesn't exist? At least for the case when the raster is in WGS:84. Perhaps the relevant code can be modified to account for this corner case?

dbaston commented 1 year ago

Would you suggest simply leaving the message at "Polygons transformed to raster CRS" if the epsg attribute is not populated?

MDanialSyed commented 1 year ago

Yes, I would recommend this tweak! I might even go further and say "Polygons transformed to raster CRS due to mismatch between polygon CRS and raster CRS", or something to that effect... I think this might be helpful for some users to pin down the reason behind this warning message.

Thanks for creating this very useful package.