[geos-devel] Re: [GEOS] #323: A point interpolated from a line does not always intersect the same line

GEOS geos-trac at osgeo.org
Sun Jan 31 16:50:50 EST 2010

#323: A point interpolated from a line does not always intersect the same line
 Reporter:  starsareblue  |        Owner:  geos-devel at lists.osgeo.org
     Type:  defect        |       Status:  reopened                  
 Priority:  major         |    Milestone:                            
Component:  Default       |      Version:  3.2.0                     
 Severity:  Unassigned    |   Resolution:                            
 Keywords:                |  
Comment (by starsareblue):

 My problem is that I am trying to find the coordinates of the projection
 of a Point onto a MultiLineString.  For example, the coordinates of the
 point (2,1) projected onto the line segment (0,0)-(5,0) should be (2,0).

 I understand that the interpolate() method for a MultiLineString composed
 of two line segments wraps into the second line segment if the distance
 argument is longer than the first line segment.  That seems to be working

 Then what exactly is MultiLineString.project(Point) returning?

 I use LineString.interpolate(LineString.project(Point)) to find the
 coordinates of the point projected onto the LineString.  So I assumed that
 MultiLineString.interpolate(MultiLineString.project(Point)) would do the
 same.  However, sometimes it works and sometimes it doesn't, giving
 strange results as in the two examples above.

 Sean, if the interpolate() method is working as intended, is project() for
 MultiLineStrings working as it is intended?  What do 8.0 and 4.0 mean in
 the following example?

 In [1]: import shapely.geometry as g

 In [2]: m = g.MultiLineString([[(0, -2), (0, 2)], [(-2, 0), (2, 0)]])

 In [3]: m.project(g.Point(2,1.9))
 Out[3]: 8.0

 In [4]: m.project(g.Point(2,2.1))
 Out[4]: 4.0


 Currently, my workaround is to first compute the distance of the Point to
 the MultiLineString and then compute the ProjectedPoint using
 ProjectedPoint =
 MultiLineString.interpolate(MultiLineString.project(Point)).  If the
 distance from the ProjectedPoint to the Point does not match the expected
 distance, then I redo the projection for each LineString inside
 MultiLineString until I find the ProjectedPoint whose distance matches the
 first distance.

Ticket URL: <http://trac.osgeo.org/geos/ticket/323#comment:6>
GEOS <http://geos.refractions.net/>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).

More information about the geos-devel mailing list