[R-sig-Geo] method intersect for non-overlapping polygons

Hofer Christoph Jean-Charles christoph.hofer at env.ethz.ch
Sun Nov 11 11:13:23 CET 2012


Dear List

The following simple example works fine

require( sp )
require( gpclib )

t.c1 <- matrix( c(1,5,5,1,1,1,1,5,5,1), ncol = 2)
t.c2 <- t.c1
t.c2[,1] <- t.c1[,1] + 10
t.c2[,2] <- t.c1[,2] +  10
t.p1 <- Polygon( t.c1 )
t.p2 <- Polygon( t.c2 )
t.p1 <- Polygons( srl = list( t.p1 ) , ID = "A")
t.p2 <- Polygons( srl = list( t.p2 ) , ID = "B")

t.sp1 <- SpatialPolygons( list( t.p1 ) )
t.sp2 <- SpatialPolygons( list( t.p2 ) )

plot( SpatialPolygons(list(t.p1,t.p2)) )


g1 <- as( t.sp1 at polygons[[1]]@Polygons[[1]]@coords, "gpc.poly")
g2 <- as(  t.sp2 at polygons[[1]]@Polygons[[1]]@coords, "gpc.poly")

intersect( g1, g2 )

The result is 0.

However, if I use "rgeos" instead of "gpclib" I get the following error message:

Error in as(spres, "gpc.poly") :
 no method or default for coercing "NULL" to "gpc.poly"

If the polygons t.p1 and t.p2  overlap both packages provide the same and right result.


Is this behavior of the intersect method in rgeos a bug or a desired property?


regeos version 0.2-6
gpclib versoin 1.5-1

sessionInfo()

R version 2.15.2 (2012-10-26)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] gpclib_1.5-1 rgeos_0.2-6  plyr_1.7.1   stringr_0.6  sp_0.9-99

loaded via a namespace (and not attached):
[1] compiler_2.15.2 grid_2.15.2     lattice_0.20-6  tools_2.15.2



Best regards


Christoph


..............................................................................................................
Dr. Christoph Hofer
Projektleiter F&E
Institut für Datenanalyse und Prozessdesign (IDP)
ZHAW Zürcher Hochschule für Angewandte Wissenschaften
Rosenstrasse 3, Postfach
CH-8401 Winterthur
T: +41 (0)58 934 69 40
F: +41 (0)58 935 69 40
E: christoph.hofer at zhaw.ch
W: http://www.idp.zhaw.ch
..............................................................................................................



More information about the R-sig-Geo mailing list