9

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?

aaron
  • 6,339
  • 12
  • 54
  • 80
  • I'm probably not understanding your question, but I use `fortify(...)` all the time and have never had to use gpclibPermot(...). – jlhoward Jan 14 '14 at 23:31
  • have you checked the example that i posted? when i run it the error `Error: isTRUE(gpclibPermitStatus()) is not TRUE` gets thrown up. it may be that fortify works fine for some sp objects and not for others... – aaron Jan 14 '14 at 23:41

1 Answers1

16

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.

Brian Diggs
  • 57,757
  • 13
  • 166
  • 188
  • I'm seeing the same message when I tried to use maptools for the first time. Am I correct in understanding that I need EITHER (1) rgeos or (2) enabled gpclib? Does the latter come with a non-commercial license or something? Between rgeos and gpclib, which is better (faster, better results, etc.)? – stackoverflowuser2010 Feb 18 '14 at 20:32
  • @stackoverflowuser2010 Correct; you need one or the other, and since `gpclib` had a [license that does not allow for commercial use](http://cran.r-project.org/web/packages/gpclib/LICENSE), there is the extra safety step of requiring an explicit function call to enable it. – Brian Diggs Feb 19 '14 at 05:36
  • @BrianDiggs: is there any difference between them in terms of results or performance? – stackoverflowuser2010 Feb 19 '14 at 16:24
  • @stackoverflowuser2010 I don't have any information about results or performance either way. – Brian Diggs Feb 19 '14 at 20:21
  • same here in 2016.. having got that message and not implementing commercial software, which of the two packages is better supported/ more commonly used? – Antonello Jul 08 '16 at 09:49