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!
Related
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?
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.
I'm trying to plot some maps in Ubuntu 18.04 . I've downloaded some shapefiles but cannot read them with "readOGR" function.
I've installed "libdgal" and "libproj-dev".
sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
But when using:
library(rgdal) # R wrapper around GDAL/OGR
library(ggplot2) # for general plotting
library(ggmap) # for fortifying shapefiles
# First read in the shapefile, using the path to the shapefile and the shapefile name minus the
# extension as arguments
shapefile <- readOGR("/home/ogonzales/Escritorio/maps_in_r/", "BAS_LIM_DEPARTAMENTO")
I get this error:
Error in readOGR("/home/ogonzales/Escritorio/maps_in_r/", "BAS_LIM_DEPARTAMENTO") :
no features found
Además: Warning message:
In ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv, :
ogrInfo: all features NULL
This is the message I get after loading "rgdal" package:
library(rgdal) # R wrapper around GDAL/OGR
Loading required package: sp
rgdal: version: 1.3-2, (SVN revision 755)
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: /usr/share/gdal/2.2
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: (autodetected)
Linking to sp version: 1.2-7
Path of file:
The file's path is correct:
list.files('/home/ogonzales/Escritorio/maps_in_r/', pattern='\\.shp$') #"BAS_LIM_DEPARTAMENTO.shp"
file.exists('/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO.shp') #TRUE
UPDATE 1:
Doing:
library(sf)
shapefile <- sf::st_read("/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO.shp")
Returns:
Cannot open data source /home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO.shp
Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, type, :
Open failed.
UPDATE 2:
rgdal::ogrListLayers("/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO")
Returns:
Error in rgdal::ogrListLayers("/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO") :
Cannot open data source
And:
sf::st_layers("/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO")
Cannot open data source /home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO
Error in CPL_get_layers(dsn, options, do_count) : Open failed.
UPDATE 2:
list.files("/home/ogonzales/Escritorio/maps_in_r/")
[1] "BAS_LIM_DEPARTAMENTO.dbf" "BAS_LIM_DEPARTAMENTO.prj" "BAS_LIM_DEPARTAMENTO.sbn"
[4] "BAS_LIM_DEPARTAMENTO.sbx" "BAS_LIM_DEPARTAMENTO.shp" "BAS_LIM_DEPARTAMENTO.shx"
[7] "maps_in_r.Rproj"
I am using the latest OpenStreetMap library on Mac OS. I am able to download a map, but I execute the plot(map) command, I get an error saying "unable to create quartz() device target, given type may not be supported". Can anyone help?
> library(OpenStreetMap)
Loading required package: rJava
Loading required package: raster
Loading required package: sp
Loading required package: rgdal
rgdal: version: 0.8-16, (SVN revision 498)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.10.1, released 2013/08/26
Path to GDAL shared files: /opt/local/share/gdal
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
Path to PROJ.4 shared files: (autodetected)
> upperLeft <- c(lat= 37.950, lon= -122.553)
> lowerRight <- c(lat= 37.650, lon= -122.250)
> mapMercator = openmap(upperLeft, lowerRight, minNumTiles=9,type="esri")
> map <- openproj(mapMercator)
> plot(map)
Error in (function (title, width, height, pointsize, family, antialias, :
unable to create quartz() device target, given type may not be supported
Interestingly, if I add a single plot(0,0) before the calling openmap(), the map will be displayed but with a warning "Process manager already initialized -- can't fully enable headless mode."
> library(OpenStreetMap)
Loading required package: rJava
Loading required package: raster
Loading required package: sp
Loading required package: rgdal
rgdal: version: 0.8-16, (SVN revision 498)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.10.1, released 2013/08/26
Path to GDAL shared files: /opt/local/share/gdal
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
Path to PROJ.4 shared files: (autodetected)
> plot(0,0)
> upperLeft <- c(lat= 37.950, lon= -122.553)
> lowerRight <- c(lat= 37.650, lon= -122.250)
> mapMercator = openmap(upperLeft, lowerRight, minNumTiles=9,type="esri")
2014-02-20 12:45:46.592 R[2539:607] Process manager already initialized -- can't fully enable headless mode.
> map <- openproj(mapMercator)
> plot(map)
This code works fine on a Macbook, but fails on my Windows desktop with the error:
Error in raster(x) :
error in evaluating the argument 'x' in selecting a method for function 'raster': Error: 'merge' is not an exported object from 'namespace:raster'
Any ideas what's causing it?
Full code:
> require(OpenStreetMap)
Loading required package: OpenStreetMap
Loading required package: rJava
Loading required package: raster
Loading required package: sp
Loading required package: rgdal
rgdal: version: 0.8-11, (SVN revision 479M)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.9.2, released 2012/10/08
Path to GDAL shared files: C:/Users/Robin/Documents/R/win-library/3.0/rgdal/gdal
GDAL does not use iconv for recoding strings.
Loaded PROJ.4 runtime: Rel. 4.7.1, 23 September 2009, [PJ_VERSION: 470]
Path to PROJ.4 shared files: C:/Users/Robin/Documents/R/win-library/3.0/rgdal/proj
> lat <- c(51.7, 51.3); lon <- c(-0.53, 0.3)
> map <- openproj(openmap(c(lat[1],lon[1]),c(lat[2],lon[2]), 8, 'osm'))
Error in raster(x) :
error in evaluating the argument 'x' in selecting a method for function 'raster': Error: 'merge' is not an exported object from 'namespace:raster'
Its a bug in raster related to the method used to merge tiles - either upgrade or at a pinch use mergeTiles=FALSE.