[R-sig-Geo] gIntersection error in rgeos package

maogui.hu maogui.hu at gmail.com
Mon Sep 24 03:55:43 CEST 2012


Hi all,
I found a problem when using the "gIntersection" in rgeos for two lines. The expected result is a long line shared by two lines. However, the result I obtained is a short line (a part of the afore mentioned long line). I have tried to change the setScale() value for different operation precision. But the result is almost the same. I think may be it is a bug of the function. Attached are the data, r code and results. Can anybody help me to solve it? thanks very much.

require(maptools)
require(rgeos)

ws <- "E:/testdata/"
sline1 <- readShapeLines(file.path(ws, "Line01.shp"))
sline2 <- readShapeLines(file.path(ws, "Line02.shp"))

Intersection <- function(line1, line2)
{
gL <- c()
nLength <- 0
for(s in 10^c(-2:8))
{
setScale(s)
gL0 <- gIntersection(line1, line2)
if(gLength(gL0) > nLength) 
{
gL <- gL0
nLength <- gLength(gL)
}
}
setScale()
return(gL)
}

par(mfrow=c(2,2))
plot(sline1, col="red")
plot(sline2, col="blue")
plot(rbind.SpatialLines(sline1, sline2, makeUniqueIDs=TRUE), col=c("red","blue"))
rslt <- Intersection(sline1, sline2)
plot(rslt, col="green")




maogui.hu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120924/13492c6e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: expected result.png
Type: application/octet-stream
Size: 14832 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120924/13492c6e/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: intersection.png
Type: application/octet-stream
Size: 8789 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120924/13492c6e/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rgeos_check2.r
Type: application/octet-stream
Size: 623 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120924/13492c6e/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testdata.zip
Type: application/octet-stream
Size: 3840 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120924/13492c6e/attachment-0003.obj>


More information about the R-sig-Geo mailing list