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

Passing gdal config options to rast #608

Closed
ebolch opened this issue Apr 7, 2022 · 1 comment
Closed

Passing gdal config options to rast #608

ebolch opened this issue Apr 7, 2022 · 1 comment

Comments

@ebolch
Copy link

ebolch commented Apr 7, 2022

I'm trying to use rast to access NASA Earthdata cloud optimized geotiffs. A NASA Earthdata account and a netrc file with login and password are required(Earthdata netrc setup script).

I've been trying the following, but seem to be getting an authentication error:

library(terra)
url <- "/vsicurl/https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/HLSS30.020/HLS.S30.T10SEJ.2021214T184919.v2.0/HLS.S30.T10SEJ.2021214T184919.v2.0.B8A.tif"
r <- rast(url, opts=c("GDAL_HTTP_UNSAFESSL=YES",
                                      "GDAL_HTTP_COOKIEFILE=.rcookies",
                                      "GDAL_HTTP_COOKIEJAR=.rcookies",
                                      "GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR",
                                      "CPL_VSIL_CURL_ALLOWED_EXTENSIONS=TIF"))

I am able to do this successfully with the raster and rgdal packages:

library(raster)
library(rgdal)
rgdal::setCPLConfigOption(ConfigOption ="GDAL_HTTP_UNSAFESSL",value ="YES")
rgdal::setCPLConfigOption(ConfigOption ="GDAL_HTTP_COOKIEFILE",value =".rcookies")
rgdal::setCPLConfigOption(ConfigOption ="GDAL_HTTP_COOKIEJAR",value =".rcookies")
rgdal::setCPLConfigOption(ConfigOption ="GDAL_DISABLE_READDIR_ON_OPEN",value ="EMPTY_DIR")
rgdal::setCPLConfigOption(ConfigOption ="CPL_VSIL_CURL_ALLOWED_EXTENSIONS",value ="TIF")
url <-"/vsicurl/https://data.lpdaac.earthdatacloud.nasa.gov/lp-prod-protected/HLSS30.020/HLS.S30.T10SEJ.2021214T184919.v2.0/HLS.S30.T10SEJ.2021214T184919.v2.0.B8A.tif"
r <-raster(url)

Am I just passing on the gdal config options incorrectly? Any help would be appreciated.

rhijmans added a commit that referenced this issue Apr 7, 2022
@rhijmans
Copy link
Member

rhijmans commented Apr 7, 2022

Thank you. The GDAL configuration options were not exposed by terra. On linux you could set them with rgdal, as GDAL is a shared library, but on windows each R package has its own copy. I now get:

library(terra)
#terra 1.5.26

## options not set
getGDALconfig(c("GDAL_HTTP_UNSAFESSL", "GDAL_HTTP_COOKIEFILE"))
# GDAL_HTTP_UNSAFESSL GDAL_HTTP_COOKIEFILE 
#                  ""                   "" 

## set options as "option=value"
setGDALconfig(c("GDAL_HTTP_UNSAFESSL=YES", 
         "GDAL_HTTP_COOKIEFILE=.rcookies",
          "GDAL_HTTP_COOKIEJAR=.rcookies", 
          "GDAL_DISABLE_READDIR_ON_OPEN=EMPTY_DIR",
          "CPL_VSIL_CURL_ALLOWED_EXTENSIONS=TIF"))
 
## options have been set
getGDALconfig(c("GDAL_HTTP_UNSAFESSL", "GDAL_HTTP_COOKIEFILE", "GDAL_HTTP_COOKIEJAR"))
# GDAL_HTTP_UNSAFESSL GDAL_HTTP_COOKIEFILE  GDAL_HTTP_COOKIEJAR 
#               "YES"          ".rcookies"          ".rcookies" 
 
## reset to default
setGDALconfig(c("GDAL_HTTP_UNSAFESSL", "GDAL_HTTP_COOKIEFILE", "GDAL_HTTP_COOKIEJAR"),  c("", "", ""))
 
getGDALconfig(c("GDAL_HTTP_UNSAFESSL", "GDAL_HTTP_COOKIEFILE", "GDAL_HTTP_COOKIEJAR"))
# GDAL_HTTP_UNSAFESSL GDAL_HTTP_COOKIEFILE  GDAL_HTTP_COOKIEJAR 
#                  ""                   ""                   "" 

## set options as "options, values"
setGDALconfig(c("GDAL_HTTP_UNSAFESSL", "GDAL_HTTP_COOKIEFILE"),  c("YES", ".rcookies"))

getGDALconfig(c("GDAL_HTTP_UNSAFESSL", "GDAL_HTTP_COOKIEFILE", "GDAL_HTTP_COOKIEJAR"))
# GDAL_HTTP_UNSAFESSL GDAL_HTTP_COOKIEFILE  GDAL_HTTP_COOKIEJAR 
#               "YES"          ".rcookies"                   "" 

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

No branches or pull requests

2 participants