[R-sig-Geo] Alternate methods: Polygon Algebra / Polygon Overlay with R Spatial objects..

Roger Bivand Roger.Bivand at nhh.no
Fri Jan 15 20:00:30 CET 2010


On Fri, 15 Jan 2010, rick reeves wrote:

> Hello List:
>
> I have been reviewing techniques within R for performing the GIS-like 
> operation 'polygon algebra' (computing the union and intersection of 
> polygons within two SpatialPolygonDataFrame objects). The goal is to 
> combine two polygon data frames, to produce a new polygon data frames 
> that contain the union or intersection of the two input sets.
>
> Thus far, the only method that I have found for this is the 
> combinePolys() method within the PBSmapping package. The PBSmapping 
> routines work well, but require the transformation out of the 
> SpatialXXXDataFrame classes.

For union, aka dissolve, see unionSpatialPolygons() in maptools. Perhaps 
better, don't look yet. The underlying problem is the license of the 
gpclib package, which should be avoided. The reason for attention to 
package licenses is that CRAN is getting very large, and taking 
responsibility for distributing non-free software through package 
dependencies needs to be automated. So GPL and other free packages should 
not depend on or suggest non-free packages, because users (including 
commercial users) may not be aware that they are using packages with 
non-free licences. Some of these users already block the installation of 
free packages with "upstream" non-free dependencies, and more will do so 
in the future.

One solution is the R-Forge rgeos package, which I'm working on.

https://r-forge.r-project.org/projects/rgeos/

Before long, again thanks to Uwe Ligges and others, we should have a 
working production line for Windows binary packages with GEOS 3.1.1 
included. Linux distributions have binaries or can install from source; 
OSX has a Kyngchaos framework to handle the external dependency on GEOS.

rgeos has unionSpatialPolygonsGEOS(), which, when rgeos reaches CRAN, will 
be used by maptools in unionSpatialPolygons() if rgeos is available.

GEOS has the necessary functions to do what you would like, but someone 
has to write the R and C code and add it to rgeos. The current 
SpatialLinesIntersections() function returns a SpatialPointsDataFrame 
object with the IDs if the intersecting lines, but more is needed for 
SpatialPolygons intersection. The handling of the data frame variables is 
far from obvious too - just copying across count or rate variables isn't 
appropriate. Most likely the handling of the data slots would have to be 
done by hand for the new SpatialPolygons objects based on the intersecting 
ID values.

R-Forge has the possibility for new developers to join projects ...

Hope this helps,

Roger

>
> The overlay() method within sp seems like the best routine for this job as it
> performs intersection operations on pairs of Spatial objects, but it
> does not appear to operate on two SpatialPolygonDataFrame objects.
> So I have not tried to use it for this.
>
> Do other packages contain polygon algebra routines that operate on the 
> Spatial classes?
> If not, are there any alternatives to the PBSmapping methods?
>
> Thanks,
> Rick R
>
>
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list