1

问题:

NULL pointer读取此 EIA zip 文件ShalePlay_Bakken_Isopach_EIA_08Jan2015.shp返回A。

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 模型的以下链接。¯\_(ツ)_/¯

问题:

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

解决方法:

以下代码使用rgdal::readOGR()andsf::st_as_sf()转换为 class 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()

在此处输入图像描述

4

0 回答 0