使用 maptools readShapePoly 在 R 中打开 SHP 文件时出错 [英] Error opening SHP file in R using maptools readShapePoly

查看:313
本文介绍了使用 maptools readShapePoly 在 R 中打开 SHP 文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 R 新手,正在遵循以下关于 ggplot2 包的教程,发现 此处.但是,每当我尝试加载基本 shapefile 时, readShapePoly() 函数都会引发错误.我使用了以下代码:

I am new to R and was following the following tutorial on the ggplot2 package found here. However the readShapePoly() function throws an error whenever I try to load the basic shapefile. I have used the following code:

library("ggplot2")
library("gpclib")
library("maptools")
setwd("~/Documents/R Projects/Intro to ggplot2") 
#Intro to ggplot 2 contains the .shp file and associated data
sport <- readShapePoly("london_sport.shp")

这让我:

Error in getinfo.shape(filen) : Error opening SHP file

我试过省略文件扩展名.我也尝试下载其他 .shp 文件,这些文件也抛出相同的错误.我还尝试使用完整文件路径调用 readShapePoly,这也不起作用.我正在使用 R studio (mac OSX),但使用标准 R 窗口时出现相同的错误.我已经尝试了有关之前关闭的威胁在 Rstudio 中打开 SHP 文件时出错"的建议,但无济于事.

I have tried omitting the file extension. I have also tried downloading other .shp files which throw the same error too. I have also tried calling readShapePoly using the full file path, which doesn't work either. I am using R studio (mac OSX), but I get the same error using the standard R window. I have tried the suggestions on the previous closed threat "Error opening SHP file in Rstudio", but to no avail.

错误是缺少 .dbf 文件.感谢@Spacedman 的修复.

推荐答案

我遇到了类似的问题,这是因为在我下载的 zip 包中还有其他几个文件以及*.shp"形状文件.然后我只将形状文件移动到另一个文件夹,它不起作用.当包含所有文件时,这很好,我可以readShapeSpatial() 函数正常.

I had a similar issue, and it was because there were several other files along with the '*.shp' shape file in the zip package that I downloaded. Then I only moved the shape file to another folder and it didn't work. When including all files together, it was fine and I could readShapeSpatial() function okay.

这篇关于使用 maptools readShapePoly 在 R 中打开 SHP 文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆