Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reproject tiled data? #40

Closed
khufkens opened this issue Apr 12, 2020 · 3 comments
Closed

How to reproject tiled data? #40

khufkens opened this issue Apr 12, 2020 · 3 comments
Labels

Comments

@khufkens
Copy link
Member

This example should remove all doubt on how to reproject tiled Daymet data. The example downloads a single tile around Cape Cod, a distinct geographic feature. I plot the data in the corrected projection, as well as reprojected to EPSG 4326.

In short, the correct CRS projection of the tiled data is:
+proj=lcc +lat_1=25 +lat_2=60 +lat_0=42.5 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs

unlike what is reported in the tile meta-data!

library(daymetr)
library(raster)
library(sp)
library(rnaturalearth)

# download data
download_daymet_tiles(tiles = 11755, param = "prcp", start = 1980, end = 1980)

# read raster
r <- raster::raster(file.path(tempdir(),"prcp_1980_11755.nc"))

# set the correct projection
raster::projection(r) <- "+proj=lcc +lat_1=25 +lat_2=60 +lat_0=42.5 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs"

# reproject to lat long
r_ll <- raster::projectRaster(r, crs = "+init=epsg:4326")

# grab usa outlines from rnaturalearth
usa_ll <- ne_countries(scale = 50, country = "United States of America", returnclass = "sp")
usa <- spTransform(usa_ll, CRSobj = CRS("+proj=lcc +lat_1=25 +lat_2=60 +lat_0=42.5 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs"))

# plot simple overview graphs
par(mfrow = c(2,1))
plot(r, main = "LLC projection")
lines(usa)

plot(r_ll, main = "lat lon projection")
lines(usa_ll)

cape-cod

@knussear
Copy link

I'm having the same problem - and this definitely does not solve it.

@khufkens
Copy link
Member Author

When querying data using NCSS subsets (with coordinates, not tiled data) you might find that bounding boxes do not correspond to your query. You pass lat / lon coordinates which aren't orthogonal in the LCC "space". Hence, your bounding box of your query will change.

You find visual examples here:
https://daymet.ornl.gov/web_services.html

@khufkens
Copy link
Member Author

For NCSS downloads the units of the projection are in kilometers not meters, use:

# set the correct projection
raster::projection(r) <- "+proj=lcc +lat_1=25 +lat_2=60 +lat_0=42.5 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +units=km +no_defs"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants