Does installing the package rgdal also install GDAL on your computer? - r

When I look at the documentation of the package rgdal it says
"The R contributed package rgdal is available from CRAN as a source package for installation on platforms with the full build train and external dependencies."
GDAL is one of the external dependencies, so I though this meant that it would download off CRAN and be installed along with the package.
When I load the package rgdal into my R workspace, I get this message:
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/andersonch/Documents/R/win-library/3.5/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/andersonch/Documents/R/win-library/3.5/rgdal/proj
Linking to sp version: 1.4-1
Again, I would have thought that means that there is a valid version of GDAL that the package is connecting to.
But when I try to use functions from the gdalUtils package, I get this warning message:
Warning messages:
1: In gdal_setInstallation(ignore.full_scan = ignore.full_scan, verbose = verbose) :
No GDAL installation found. Please install 'gdal' before continuing:
- www.gdal.org (no HDF4 support!)
- trac.osgeo.org/osgeo4w/ (with HDF4 support RECOMMENDED)
- www.fwtools.maptools.org (with HDF4 support)
2: In gdal_setInstallation(ignore.full_scan = ignore.full_scan, verbose = verbose) :
If you think GDAL is installed, please run:
gdal_setInstallation(ignore.full_scan=FALSE)"
Does this mean that I need to install gdal separately?

Related

R: How can I install terra on Amazon Linux 2?

I'm having some trouble running install.packages("terra") on Amazon Linux 2 with R 4.0.2 on an EC2. The output is the following:
checking GDAL: checking whether PROJ is available for linking:... yes
checking GDAL: checking whether PROJ is available fur running:... ./gdal_proj: error while loading shared libraries: libgdal.so.28: cannot open shared object file: No such file or directory
no
configure: error: OGRCoordinateTransformation() does not return a coord.trans: PROJ not available?
ERROR: configuration failed for package 'terra'
* removing '/usr/lib64/R/library/terra'
The downloaded source packages are in
'/tmp/RtmplRJO0R/downloaded_packages'
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
My understanding is that terra depends on compiled packages GDAL and PROJ. The best guide I found to install is this one. Unfortunately I still get the above error even though GDAL and PROJ are installed. Before this guide I tried using yum to install proj, but yum would install proj 4.8.0 which is too old to meet the minimum requirements for GDAL. Has anyone successfully installed terra on Amazon Linux 2?

R package doesn't detect updated version of GDAL

I am trying to shift from raster to the new terra R package, which requires a recent version of GDAL to be installed on my machine (MacOS 10.14.6).
I updated GDAL following the instructions here: http://www.alexchubaty.com/post/2020-01-08-using-latest-gdal-macos-redux/ and it seemed to work. When I run gdalinfo --version in the terminal it displays:
GDAL 3.1.1, released 2020/06/22
But when I load the terra library in R it still seems to link to an old version of GDAL (2.4.2):
> library(terra)
This is terra version 0.7.11 (alpha-release)
NOTE: You are using GDAL version 2.4.2
For full functionality you need at least version 3.0.4
Interestingly, rgdal package seems to detect the updated version:
> library(rgdal)
Loading required package: sp
rgdal: version: 1.5-12, (SVN revision 1018)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.1.2, released 2020/07/07
Path to GDAL shared files: /usr/local/Cellar/gdal/3.1.2/share/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ runtime: Rel. 7.1.0, August 1st, 2020, [PJ_VERSION: 710]
Path to PROJ shared files: /Users/jamesmccarthy/Library/Application Support/proj:/usr/local/opt/proj/share/proj:/usr/local/Cellar/proj/7.1.0/share/proj
PROJ CDN enabled:FALSE
Linking to sp version:1.4-2
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading rgdal.
Attaching package: ‘rgdal’
The following object is masked from ‘package:terra’:
project
Does anyone know how to get terra to link to the most recent version of GDAL? I'm guessing the old version is still installed somewhere on the machine.
I am guessing that you installed rgdal from source, but the binary version of terra from CRAN. So after doing (what you already did) from the command line:
brew install pkg-config
brew install gdal
You should get what you are looking for with the following R command
install.packages("terra", type = "source")
Or, for the cutting edge
remotes::install_github("rspatial/terra")
Good luck with terra!

Error in readOGR(dsn, layer) : could not find function "readOGR"

I am very new to R and so what does this mean? Does this tell me that I need to install some package named "ReadOGR"
I am following along using code written by someone else in an effort to generate a heat map. here is the current section to give some context.
setwd("C:/Users/Someone/Documents/R")
dsn <- "cb_2017_us_state_20m.shp"
layer <- "cb_2017_us_state_20m"
cb5 = readOGR(dsn, layer)
Installed rgdal to no success. Tried library(rgdal)
library(rgdal)
Loading required package: sp
rgdal: version: 1.3-9, (SVN revision 794)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/trwilcox/Documents/R/win-
library/3.5/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/someone/Documents/R/win-
library/3.5/rgdal/proj
Linking to sp version: 1.3-1
Warning messages:
1: package ‘rgdal’ was built under R version 3.5.2
2: package ‘sp’ was built under R version 3.5.2
> cb5 = readOGR(dsn, layer)
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv =
use_iconv, :
Cannot open data source
Try:
setwd("C:/Users/Someone/Documents/R")
dsn <- "cb_2017_us_state_20m.shp"
cb5 = readOGR(dsn)
Also, you can find the original files here: https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html. Maybe there are some extra info there you want to use.
You have to use the one with .shp not the shp.xlm If you do not have it, download from the link above!!!
It should work now, if not, happy to help you!

Problem with Rgdal package on R software version 3.5.1

I'm trying to load in R a shapefile but I can't do it.
When I load a Rgdal package I have this error message
"rgdal: version: 1.3-6, (SVN revision 773)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
Path to GDAL shared files: C:/Users/Matteo/Documents/R/win-library/3.5/rgdal/gdal
GDAL binary built with GEOS: TRUE
Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
Path to PROJ.4 shared files: C:/Users/Matteo/Documents/R/win-library/3.5/rgdal/proj
Linking to sp version: 1.3-1 "
What may have happened?
I tried to update the package but the problem remains.
My version of R is 3.5.1 and my PC is Windows
It doesn't look like an error message to me, just some loading notes.
You can confirm that the package is loaded, if you're using RStudio, under the "Packages" pane in the lower right-hand corner; the rgdal package should have a check mark next to it.
Alternatively, you can use print(.packages()), which will give you a list of all your loaded packages.

how to upgrade proj4 for rgdal

I use the R packages rgdal and rgeos extensively (currently with R v3.2.2). Recently, on my ubuntu machine (ubuntu v15.10), when I load the rgdal package, I see the following:
> library(rgdal)
Loading required package: sp
rgdal: version: 1.0-7, (SVN revision 559)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.11.1, released 2014/09/24
Path to GDAL shared files: /usr/local/share/gdal
Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
Path to PROJ.4 shared files: (autodetected)
WARNING: no proj_defs.dat in PROJ.4 shared files
Linking to sp version: 1.2-1
I have seen on a recent r-sig-geo posting that this is a known issue, and that an update to the rgdal package has been released to fix this issue. However, despite reinstalling the rgdal package, reinstalling gdal and proj4 with the following:
sudo apt-get update && sudo apt-get install libgdal-dev libproj-dev
I see no difference. This problem generates hundreds of warning messages when I use the functions of these packages.
In comparison, on my mac, if I load the rgdal package, I see
> library(rgdal)
Loading required package: sp
rgdal: version: 1.0-7, (SVN revision 559)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.11.3, released 2015/09/16
Path to GDAL shared files: /usr/local/Cellar/gdal/1.11.3/share/gdal
Loaded PROJ.4 runtime: Rel. 4.9.2, 08 September 2015, [PJ_VERSION: 491]
Path to PROJ.4 shared files: (autodetected)
Linking to sp version: 1.2-0
So there are clearly updates to gdal and proj.4 that are not making it onto my linux machine.
Does anybody have any ideas how I can get the updates?
Thanks!
I ended up compiling both proj4 and gdal from source, by cloning the respective github repositories.
https://github.com/OSGeo/proj.4
https://github.com/OSGeo/gdal
Installing rgdal on ubuntu should work (have done it, 2 months ago, on the amazone webservers). And yes, I received errors, but i could fix it by adding a folder with extra files, which didn't were installed during the installation of RGDAL.

Resources