从ONS下载County Shapefile

问题描述 投票:0回答:1

我正在尝试从ONS [定义为here的位置下载Ultra Generalized Clipped Boundaries。我打算用它来显示带有ggplot的Choropleth映射。

但是,当我使用readOGR时,会收到以下消息。

ogrInfo中的错误(dsn = dsn,layer =层,编码=编码,use_iconv = use_iconv ,:无法打开图层

下载和解压缩似乎有效,并且作为ESRI Shape文档出现。

我在做什么错?

library(tidyverse)
library(rgeos)
library(rgdal)
library(maptools)

dest_zip_file <- "Counties_December_2017_Ultra_Generalised_Clipped_Boundaries_in_England.zip"
shape_file_name <- "Counties_December_2017_Ultra_Generalised_Clipped_Boundaries_in_England"

download.file("http://geoportal1-ons.opendata.arcgis.com/datasets/c6404b30a373457e9d87f724dd57585c_4.zip?outSR={%22latestWkid%22:27700,%22wkid%22:27700}",
              dest_zip_file)
unzip(dest_zip_file, paste0(shape_file_name,".shp"))

county_shapes <- readOGR(dsn = ".",
                         layer = shape_file_name,
                         verbose = TRUE)
r ggplot2 gis esri
1个回答
0
投票

您要将文件夹解压缩到单个文件-.shp中,实际上您应该将多个文件作为'shape文件'的一部分,包括.shx和.dbf文件。

您可以通过解压缩所有文件并阅读以下内容来修正代码:

unzip(dest_zip_file)

county_shapes <- readOGR(dsn = ".",
                         layer = shape_file_name,
                         verbose = TRUE)

[注意,如果您要查找英国的地理边界,我总是建议您使用geoportal,在这里您经常可以找到通过API下载geojson的链接。例如,我找到了2017年县界的链接,并使用sf进行了阅读:

library(sf)
library(ggplot2)
county <- read_sf('https://opendata.arcgis.com/datasets/c6404b30a373457e9d87f724dd57585c_2.geojson')
ggplot() +
  geom_sf(data = county)

2017 county boundaries

© www.soinside.com 2019 - 2024. All rights reserved.