<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE>
BLOCKQUOTE {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em
}
OL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
UL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
BODY {
        LINE-HEIGHT: 1.5; FONT-FAMILY: 宋 COLOR: #000000; FONT-SIZE: 10.5pt; 20307: 
}
P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
</STYLE>

<META name=GENERATOR content="MSHTML 8.00.7600.16385"></HEAD>
<BODY style="MARGIN: 10px">
<DIV>Hi all,</DIV>
<DIV style="TEXT-INDENT: 2em">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.</DIV>
<DIV> </DIV>
<DIV>
<DIV>require(maptools)</DIV>
<DIV>require(rgeos)</DIV>
<DIV> </DIV>
<DIV>ws <- "E:/testdata/"</DIV>
<DIV>sline1 <- readShapeLines(file.path(ws, "Line01.shp"))</DIV>
<DIV>sline2 <- readShapeLines(file.path(ws, "Line02.shp"))</DIV>
<DIV> </DIV>
<DIV>Intersection <- function(line1, line2)</DIV>
<DIV>{</DIV>
<BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr>
  <DIV>gL <- c()</DIV>
  <DIV>nLength <- 0</DIV>
  <DIV>for(s in 10^c(-2:8))</DIV>
  <DIV>{</DIV>
  <BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr>
    <DIV>setScale(s)</DIV>
    <DIV>gL0 <- gIntersection(line1, line2)</DIV>
    <DIV>if(gLength(gL0) > nLength) </DIV>
    <DIV>{</DIV>
    <BLOCKQUOTE style="MARGIN-RIGHT: 0px" dir=ltr>
      <DIV>gL <- gL0</DIV>
      <DIV>nLength <- gLength(gL)</DIV></BLOCKQUOTE>
    <DIV>}</DIV></BLOCKQUOTE>
  <DIV>}</DIV>
  <DIV>setScale()</DIV>
  <DIV>return(gL)</DIV></BLOCKQUOTE>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>par(mfrow=c(2,2))</DIV>
<DIV>plot(sline1, col="red")</DIV>
<DIV>plot(sline2, col="blue")</DIV>
<DIV>plot(rbind.SpatialLines(sline1, sline2, makeUniqueIDs=TRUE), col=c("red","blue"))</DIV>
<DIV>rslt <- Intersection(sline1, sline2)</DIV>
<DIV>plot(rslt, col="green")</DIV></DIV>
<DIV> </DIV>
<HR style="WIDTH: 210px; HEIGHT: 1px" align=left color=#b5c4df SIZE=1>

<DIV><SPAN>maogui.hu</SPAN></DIV></BODY></HTML>