Split Line To Two Parts using an Point that intesects the line - Robust Line Intersector

816 views
Skip to first unread message

mindspit

unread,
Apr 27, 2009, 9:25:03 AM4/27/09
to NetTopologySuite
i am trying to find a way to split a line by using an intersection
point already known. So the function must return two line segments.
The code doen't work. seperationOnIndex is always -1.
Any ideas?

.
Private Function SplitGeometryLineToTwoParts( lineToSplit As
GisSharpBlog.NetTopologySuite.Geometries.Geometry , splitPoint As
GisSharpBlog.NetTopologySuite.Geometries.Geometry )

Dim splitPointCoordinate As ICoordinate = splitPoint.Coordinate

Dim seperationOnIndex As Integer = -1
For CoordIndex As Integer = 0 To
lineToSplit.Coordinates.Length - 2
Dim coord1 As ICoordinate = lineToSplit.Coordinates
(CoordIndex)
Dim coord2 As ICoordinate = lineToSplit.Coordinates
(CoordIndex + 1)

Dim rli As New
GisSharpBlog.NetTopologySuite.Algorithm.RobustLineIntersector
'NonRobustLineIntersector()
rli.ComputeIntersection(splitPointCoordinate, coord1,
coord2)
Dim intNum As Integer = rli.IntersectionNum
Dim check As Boolean = rli.IsIntersection
(splitPointCoordinate)

If rli.IsInteriorIntersection Then
seperationOnIndex = CoordIndex
End If
If intNum <> 0 Then
seperationOnIndex = CoordIndex
End If
If check Then
seperationOnIndex = CoordIndex
End If
If rli.HasIntersection Then
seperationOnIndex = CoordIndex
End If
Next

If seperationOnIndex = -1 Then
' MsgBox("What's the error?")
Exit Sub
End If


'-------------------------------------------------------------
Dim myLeftCoords As New List(Of GeoAPI.Geometries.ICoordinate)
Dim myRightCoords As New List(Of
GeoAPI.Geometries.ICoordinate)
'add the intersection point at the beginning of myRightCoords
myRightCoords.Add(splitPointCoordinate)
For CoordIndex As Integer = 0 To
lineToSplit.Coordinates.Length - 1
Dim coord As GeoAPI.Geometries.ICoordinate =
lineToSplit.Coordinates(CoordIndex)

'myLeftCoords should include the coordinates from 0 up to
and including seperationIndex
If CoordIndex <= seperationOnIndex Then
myLeftCoords.Add(coord)
End If

'myRightCoords should include all the coordinates Greater
than separationIndex
If CoordIndex > seperationOnIndex Then
myRightCoords.Add(coord)
End If
Next
'-------------------------------------------------------------

'add the intersection point at
'the end of myLeftCoords
myLeftCoords.Add(splitPointCoordinate)
Dim LeftSegment As New
GisSharpBlog.NetTopologySuite.Geometries.LineString
(myLeftCoords.ToArray)
Dim RightSegment As New
GisSharpBlog.NetTopologySuite.Geometries.LineString
(myRightCoords.ToArray)


'------------------------------------------------------------------------------

return Nothing
end Function

mindspit

unread,
Apr 28, 2009, 10:51:25 AM4/28/09
to NetTopologySuite
this does not work either ... any ideas ?
:(
http://pastebin.com/m3de539d

1.
Private Function SplitFuncLAST(ByVal splitPoint As
GisSharpBlog.NetTopologySuite.Geometries.Geometry, ByVal lineToSplit
As GisSharpBlog.NetTopologySuite.Geometries.Geometry, ByRef
RightSegment As GisSharpBlog.NetTopologySuite.Geometries.LineString,
ByRef LeftSegment As
GisSharpBlog.NetTopologySuite.Geometries.LineString) As Boolean
2.
'what you could do instead is loop through
3.
'each pair of coordinates -
4.
'create a new line string geometry -
5.
'do an intersection test between the point and the line
string etc
6.
Dim splitPointCoordinate As ICoordinate =
splitPoint.Coordinate
7.
Dim splitPointNTS As
GisSharpBlog.NetTopologySuite.Geometries.Point = GSfactory.CreatePoint
(splitPointCoordinate)
8.

9.
Dim seperationOnIndex As Integer = -1
10.
For CoordIndex As Integer = 0 To
lineToSplit.Coordinates.Length - 2
11.
Dim coord1 As ICoordinate = lineToSplit.Coordinates
(CoordIndex)
12.
Dim coord2 As ICoordinate = lineToSplit.Coordinates
(CoordIndex + 1)
13.

14.
Dim point1 As
GisSharpBlog.NetTopologySuite.Geometries.Point = GSfactory.CreatePoint
(coord1)
15.
Dim point2 As
GisSharpBlog.NetTopologySuite.Geometries.Point = GSfactory.CreatePoint
(coord2)
16.

17.
Dim vertices(1) As ICoordinate
18.
vertices(0) = point1.Coordinate
19.
vertices(1) = point2.Coordinate
20.
Dim thisLineString As New
GisSharpBlog.NetTopologySuite.Geometries.LineString(vertices)
21.
Dim CHECK As Boolean = thisLineString.Intersects
(splitPointNTS)
22.
If CHECK Then
23.
seperationOnIndex = CoordIndex
24.
End If
25.

26.

27.
Next
28.

29.
If seperationOnIndex = -1 Then
30.
'Didn't find anything!
31.
Return False
32.
End If
33.

34.

35.

'-------------------------------------------------------------
36.
Dim myLeftCoords As New List(Of
GeoAPI.Geometries.ICoordinate)
37.
Dim myRightCoords As New List(Of
GeoAPI.Geometries.ICoordinate)
38.
'add the intersection point at the beginning of
myRightCoords
39.
myRightCoords.Add(splitPointCoordinate)
40.
For CoordIndex As Integer = 0 To
lineToSplit.Coordinates.Length - 1
41.
Dim coord As GeoAPI.Geometries.ICoordinate =
lineToSplit.Coordinates(CoordIndex)
42.

43.
'myLeftCoords should include the coordinates from 0
up to and including seperationIndex
44.
If CoordIndex <= seperationOnIndex Then
45.
myLeftCoords.Add(coord)
46.
End If
47.

48.
'myRightCoords should include all the coordinates
Greater than separationIndex
49.
If CoordIndex > seperationOnIndex Then
50.
myRightCoords.Add(coord)
51.
End If
52.
Next
53.

'-------------------------------------------------------------
54.

55.
'add the intersection point at
56.
'the end of myLeftCoords
57.
myLeftCoords.Add(splitPointCoordinate)
58.
LeftSegment = New
GisSharpBlog.NetTopologySuite.Geometries.LineString
(myLeftCoords.ToArray)
59.
RightSegment = New
GisSharpBlog.NetTopologySuite.Geometries.LineString
(myRightCoords.ToArray)
60.
Return True
61.
End Function

Diego Guidi

unread,
Apr 28, 2009, 1:25:01 PM4/28/09
to NetTopologySuite
not so easy as expected :(
try to search in JTS mailing list for some suggests
http://www.google.it/search?hl=it&rlz=1C1GGIT_enIT313IT311&q=site:http://lists.jump-project.org/pipermail/jts-devel/+split&btnG=Cerca&meta=

On Apr 28, 4:51 pm, mindspit <agelospanagiota...@gmail.com> wrote:
> this does not work either ... any ideas ?
> :(http://pastebin.com/m3de539d

mindspit

unread,
Apr 28, 2009, 7:02:54 PM4/28/09
to NetTopologySuite
thanks a lot !
i found some of them.
I don't know in which version of jts they refer to and if these
function also exist in nts
I will look into it and see what i can do on my own.
so i found these :-o a lot of info :-o for anyone else intrested



Split algorithm http://lists.jump-project.org/pipermail/jts-devel/2006-April/001598.html
Intersection issues http://lists.jump-project.org/pipermail/jts-devel/2007-June/001990.html
Finding a point in a polyline related to a point outside it
http://lists.jump-project.org/pipermail/jts-devel/2008-May/002498.html
closest point on a line to a point http://lists.jump-project.org/pipermail/jts-devel/2007-June/001985.html
Closest point on line to a given point...
http://lists.jump-project.org/pipermail/jts-devel/2006-March/001536.html
closest point on a line to a point http://lists.jump-project.org/pipermail/jts-devel/2007-June/001986.html
Split LineString http://lists.jump-project.org/pipermail/jts-devel/2007-September/002145.html

On Apr 28, 8:25 pm, Diego Guidi <diegogu...@gmail.com> wrote:
> not so easy as expected :(
> try to search in JTS mailing list for some suggestshttp://www.google.it/search?hl=it&rlz=1C1GGIT_enIT313IT311&q=site:htt...
Reply all
Reply to author
Forward
0 new messages