st_read()错误:GetGeomFieldRef返回的NULL指针

时间:2017-04-27 11:21:05

标签: r sf

问题:

this EIA zip file阅读NULL pointer时返回ShalePlay_Bakken_Isopach_EIA_08Jan2015.shp

library(sf)

tmp_file <- tempfile()
tmp_dir <- tempdir()

zp <- "https://www.eia.gov/maps/map_data/TightOil_ShaleGas_IndividualPlays_Lower48_EIA.zip"

download.file(zp, tmp_file)
unzip(zipfile = tmp_file, exdir = tmp_dir)

fpath <- paste(tmp_dir, "ShalePlay_Bakken_Isopach_EIA_08Jan2015.shp", sep = "\\")
iso <- st_read(fpath)

# > Error in CPL_read_ogr(dsn, layer, as.character(options), quiet, iGeomField -  : 
# > NULL pointer returned by GetGeomFieldRef

?st_read指向关于OGR模型的following link。 ¯\ _(ツ)_ /¯

问题:

有没有办法使用st_read()删除空几何?

解决方法:

以下代码使用rgdal::readOGR()sf::st_as_sf()转换为类sf,成功运行(带警告)。

library(rgdal)
library(ggplot2)  # devtools::install_github("tidyverse/ggplot2")

iso <- rgdal::readOGR(fpath)

# > Warning message:
# > In rgdal::readOGR(paste(tmp_dir, "ShalePlay_Bakken_Isopach_EIA_08Jan2015.shp",  :
# > Dropping null geometries: 17, 42, 62, 67, 70, 80, 98, 101, 118

iso_sf <- sf::st_as_sf(iso)

ggplot(iso_sf) +
  geom_sf()

enter image description here

0 个答案:

没有答案