Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法加载readOGR-ogrinfo:all features为NULL的shapefile_R_Rgdal_Sf - Fatal编程技术网

无法加载readOGR-ogrinfo:all features为NULL的shapefile

无法加载readOGR-ogrinfo:all features为NULL的shapefile,r,rgdal,sf,R,Rgdal,Sf,我试图在Ubuntu18.04中绘制一些地图。我下载了一些shapefile,但无法使用“readOGR”功能读取它们 我已经安装了“libdgal”和“libproj-dev” 但在使用时: library(rgdal) # R wrapper around GDAL/OGR library(ggplot2) # for general plotting library(ggmap) # for fortifying shapefiles # First read in t

我试图在Ubuntu18.04中绘制一些地图。我下载了一些shapefile,但无法使用“readOGR”功能读取它们

我已经安装了“libdgal”和“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")
这是我在加载“rgdal”包后收到的消息:

文件路径:

文件的路径正确:

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:

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"
做:

library(sf)

shapefile <- sf::st_read("/home/ogonzales/Escritorio/maps_in_r/BAS_LIM_DEPARTAMENTO.shp")
更新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
以及:

更新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"

rgdal::ogrListLayers
告诉你什么?
library(sf)
sf::st_read(…/…shp”)
是在R中读取形状文件的“新”方法。@alistaire我发现:rgdal::ogrListLayers()中的错误:缺失dsn@SymbolixAU请参阅更新1。您必须在shapefile上调用它;它应该告诉你它有哪些层。sf等效物为
sf::st_层
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.
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"