我正在尝试在Ubuntu 18.04中绘制一些地图。我已经下载了一些shapefile,但无法通过“readOGR”函数读取它们。
我安装了“libdgal”和“libproj-dev”。
sudo apt-get install libudunits2-dev libgdal-dev libgeos-dev libproj-dev
但使用时:
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")
我收到此错误:
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
这是我在加载“rgdal”包后得到的消息:
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
档案路径:
文件的路径是正确的:
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
更新1:
这样做的:
library(sf)
shapefile <- sf::st_read("/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO.shp")
返回:
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.
更新2 :
rgdal::ogrListLayers("/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO")
返回:
Error in rgdal::ogrListLayers("/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO") :
Cannot open data source
和
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.
更新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"