1

I have several issues with terra and it's connection to GDAL. I installed terra v. 1.6.7 in R v. 4.2.1 on a Mac running Big Sur v. 11.6.8

I installed GDAL 3.2.2 from www.kyngchaos.com, located in HD/Library/Frameworks/GDAL.Framework

Issue 1: terra reports wrong GDAL version

gdal()
#[1] "3.4.2"

There is no GDAL 3.4.2 on my system (afaik).

Relatedly, gdal(lib = "proj") gives "8.2.1" but I have PROJ 7.2.1 installed.

Issue 2: terra cannot read NetCDF files

r1 <- rast("~/Downloads/soiltemp1.nc")
#Error: [rast] cannot read from /Users/db/Downloads/soiltemp1.nc 
#Warning message: 
#'/Users/db/Downloads/soiltemp1.nc' not recognized as a supported file format. (GDAL error 4)

whereas in terminal gdalinfo ~/Downloads/soiltemp1.nc

gives correct information on file contents.

Issue 3: terra does not list NetCDF drivers in GDAL

In R gdal(drivers = TRUE)

the resulting report does not include NetCDF drivers

Issue 4: Cannot install terra from Github

remotes::install_github("rspatial/terra")

exits with error configure: error: proj_api.h not found in standard or given locations.

whereas proj_api.h is present in HD/Library/Frameworks/PROJ.framework/Headers/

Issue 5: sf also finds wrong Framework versions

Relatedly, library(sf) reports Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE

Any clues as to what is going on, much appreciated!

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
Dan B
  • 21
  • 2

1 Answers1

3

Issue 1: terra reports wrong GDAL version

You have installed a binary package from CRAN. The versions of GDAL/PROJ that the package was built with are reported (and used). It does not matter what version of GDAL you may have installed on your system (if any).

I have installed "terra" on MacOS, using R 4.2.1 and the "r-release (x86_64)" CRAN binary version of terra 1.6-7 (that is, I am not using the "arm64" version). Can you confirm that you are using that version? As expected, I get the same version numbers as you do:

library(terra)
#terra 1.6-7
gdal(lib="")
#   gdal    proj    geos 
#"3.4.2" "8.2.1" "3.10.2" 

Issue 2: terra cannot read NetCDF files
Issue 3: terra does not list NetCDF drivers in GDAL

I also see that

d <- gdal(drivers=TRUE)
d[d$name=="netCDF", ]
#[1] name      type      can       vsi       long.name
#<0 rows> (or 0-length row.names)

Where I would expect what I get on windows:

d[d$name=="netCDF", ]
#     name   type        can   vsi                  long.name
#91 netCDF raster read/write FALSE Network Common Data Format

So the package was built without the netCDF plug-in. netCDF is a fundamentally important file format for spatial data and this is a major problem that should be brought to the attention of CRAN.

A work-around is to install the development version of terra from the R universe, like this: install.packages('terra', repos='https://rspatial.r-universe.dev’)

Issue 4: Cannot install terra from Github

See the suggestions for installing from source (using brew) on the github sites of terra and sf or elsewhere. Problems mostly arise if dependencies are not in the expected path (note the use of "configure.args" to deal with that); or if there are multiple installations of GDAL.

Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
  • Thank you for your help, apologies for my ignorance on these matters. I'll report the lack of netCDF drivers to CRAN. – Dan B Sep 05 '22 at 07:50
  • I confirm that I'm using terra 1.6-7 and that gdal() reports the gdal, proj and geos version numbers you list. – Dan B Sep 05 '22 at 07:57