I'm having a problem I can't solve with rgdal in which the projection file seems to be
missing. This is the error I get:
proj4string(d) <- CRS("+init=epsg:28992")
Error in CRS("+init=epsg:28992") : no system list, errno: 2
It's confusing because when I load the package, it seems to successfully
autodetect the PROJ.4 files:
> library(rgdal)
rgdal: version: 0.9-2, (SVN revision 526)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
Path to GDAL shared files:
Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
Path to PROJ.4 shared files: (autodetected)
But when I do this, it returns zero:
.Call("PROJcopyEPSG", tempfile(), PACKAGE = "rgdal")
The only answer I've found from googling this and searching SO is that epsg has to be lowercase, which it is in my code.
I'm on a Mac running Yosemite, with R 3.2.0, and working inside RStudio
(version 0.99.441). Other packages and versions from my session info:
rgeos_0.3-8 ggmap_2.4 ggplot2_1.0.1 rgdal_0.9-2
leaflet_0.0.15 tidyr_0.2.0 dplyr_0.4.1
UScensus2010blk_1.00 UScensus2010_0.11 foreign_0.8-63
maptools_0.8-36 sp_1.1-0
I had a quick Google and came across this post which suggests this was an OS X error where the packages were built incorrectly.
On my Mac system, I wasn't able to reproduce your error, so for what it's worth I installed my versions of rgdal and rgeos from http://www.kyngchaos.com/software:frameworks Maybe you can reinstall your versions of these packages and see if this resolves the issue? I would also update sp at the same time.
As a workaround, you might be able to specify the projection manually. The proj string for your projection can be obtained from: http://spatialreference.org/ref/epsg/amersfoort-rd-new/
So, for example, instead of:
proj4string(d) <- CRS("+init=epsg:28992")
you could specify:
proj4string(d) <- CRS("+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs ")
Not an answer, maybe, but worth a try? Good luck.
Related
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!
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.
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!
I'm having problems trying to use the adehabitatHR package in R. When I load the rgdal package I get the following error message.
> 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 haven't found an answer that's suitable for someone who isn't highly skilled in computer programming (such as how to upgrade proj4 for rgdal). The extant answers on this topic are not written in a form that's understandable to a layperson - for example I don't know how to "compile", "clone" etc from the GitHub codes linked in other threads. These answers presuppose (what seems to me to be) a significant amount of programming knowledge that isn't applicable to my field of study. I would appreciate if someone could explain it in a straightforward manner to someone who has basic computer knowledge.
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.
I have problems installing rgdal in windows 8.1, i installed OSGeo4W (is it mandatory btw?), understood that I have to install proj4, but do not really understand what to install on page, I read some documentation, but I feel really ignorant and can't get it to work properly.
I want to access rgdal through R-studio through rgdal, but how can i tell r-studio where to look for gdal and proj4?
I am really confused, clearly need some documentation but do not understand where to look for it, because all I read did not seem useful.
rgdal is installed according to R but when I use spTransform it says
Error in spTransform(locations, CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")) :
load package rgdal for spTransform methods
moreover in the system requirements GDAL and proj4 are needed I know that because I already installed all this in Ubuntu, with a lot of effort.
EDIT: I re-started R, now doing library(rgdal) I get this:
Carico il pacchetto richiesto: sp
rgdal: version: 0.8-16, (SVN revision 498)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.11.0, released 2014/04/16
Path to GDAL shared files: C:/R/i686-pc-linux-gnu-library/3.0/rgdal/gdal
GDAL does not use iconv for recoding strings.
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
Path to PROJ.4 shared files: C:/R/i686-pc-linux-gnu-library/3.0/rgdal/proj
Warning message:
package ‘rgdal’ was built under R version 3.0.3
is it all ok?
EDIT 2: I updated R, just to see if that could have been the reason. Absolutely no changes in the error message.
Any help is appreciated :)
The problem solved itself after updating R and turning the pc on and off twice. no idea why but it works.