31

此问题可能与之前未回答的问题重复。我仍然有问题。

我正在尝试使用邮政编码 shapefile 并出现以下错误:

tract <- readOGR(dsn = ".", layer = "cb_2013_us_zcta510_500k")
tract<-fortify(tract, region="GEOID10")
Error: isTRUE(gpclibPermitStatus()) is not TRUE

我曾尝试安装 gpclib 来解决此问题,但随后出现以下错误:

install.packages("gpclib")

Installing package into ‘C:/Users/Nick/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
Package which is only available in source form, and may need compilation of C/C++/Fortran: ‘gpclib’
  These will not be installed

帮助?

4

3 回答 3

40

您可以查看 Hadley 的ggplot2/R/fortify-spatial.r文件。基于这个外部链接,我的理解是第 31-34 行(以当前形式)曾经读过类似

# Union together all polygons that make up a region
try_require(c("gpclib", "maptools"))
unioned <- unionSpatialPolygons(cp, invert(polys))

所以当时解决问题的一种方法是打开许可证

library(rgdal)
library(maptools)
if (!require(gpclib)) install.packages("gpclib", type="source")
gpclibPermit()

正如@rcs、@Edzer Pebesma 和这个答案提到的那样,rgeos应该可以解决最近安装的问题。

于 2015-06-23T14:04:46.837 回答
18

我遇到了同样的问题,但解决方案与上面列出的略有不同。

正如其他人所提到的,问题是对 gpclib 的依赖,这是 maptools 所需的。

但是,在加载 maptools 后,它提供了以下消息...

> library('maptools')

Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry     computations in maptools depend on gpclib,
which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()

所以可以使用 rgeos 来代替 gpclib。为了解决,我做了以下...

install.packages('rgeos', type='source')
install.packages('rgdal', type='source')

重装rgdal去掉了对gpclib的依赖,指向rgeos。

希望这会有所帮助。

于 2017-02-02T18:50:26.197 回答
7

我在其他地方学到了这个答案:我必须输入

install.packages("gpclib", type="source")

它工作得很好。

于 2015-06-21T14:37:04.093 回答