Converting spatial polygon to regular data frame without use of gpclib tools

只谈情不闲聊 提交于 2019-11-28 07:40:10

问题


I working with spatial data in R for a commercial application and would like to use ggplot2 for data visualization. If you run the Hadley's example at https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles you find that in order to run the fortify command you need to enable the use of gpclib tools using gpclibPermit().

I'm looking for an efficient way (that doesn't involve manually hacking into the S4 object) to perform the same operation that fortify does here, i.e. take a spatial polygon object and turn it into a regular data frame where row entries contain latitudinal and longitudinal coordinates along with a polygon id.

Has anyone else solved this one?


回答1:


You need to also install the rgeos package. When maptools is loaded and rgeos is not installed, the following message is shown:

> require("maptools")
Loading required package: 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()

When fortify is called with a region argument (as it is in the example you linked to), then some "polygon geometry computations" need to be done. If rgeos is not available, and gpclib is not permitted, it will fail.



来源:https://stackoverflow.com/questions/21125942/converting-spatial-polygon-to-regular-data-frame-without-use-of-gpclib-tools

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!