Point on line closest to point?

10 views
Skip to first unread message

Antony Chrysochoou

unread,
May 5, 2016, 1:30:47 PM5/5/16
to GeoScript
Hi, 

Is there a way I can achieve this the latest geoscript? I am using python by the way.
I am aware of the geom.distance(geom) function but it ain't enough. 
Also, There is no projection/interpolation method to follow the shapely example (http://stackoverflow.com/questions/24415806/coordinate-of-the-closest-point-on-a-line)

Any thoughts would be much appreciated!

Thanks in advance. 

Justin Deoliveira

unread,
May 5, 2016, 2:28:51 PM5/5/16
to geos...@googlegroups.com

Hey Antony,

It doesn’t look like there is a geoscript method for this, but I do think that jts has the functions you need. In particular:

http://www.vividsolutions.com/jts/javadoc/com/vividsolutions/jts/linearref/LocationIndexedLine.html

I could be off here but the geoscript py code that would do this is:

from com.vividsolutions.jts.linearref import *
from geoscript.geom import *

l = LineString(…)
p = Point(…)

lineIndex = LocationIndexedLine(l)
location = lineIndex.project(p.coordinate) 

closest = Point(location.getCoordinate(l))
Does that look right?

--
--
You received this message because you are subscribed to the GeoScript mailing list.
To post to this group, send email to geos...@googlegroups.com
To unsubscribe from this group, send email to geoscript+...@googlegroups.com
Visit this group at http://groups.google.com/group/geoscript or see http://geoscript.org

---
You received this message because you are subscribed to the Google Groups "GeoScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geoscript+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jericks

unread,
May 5, 2016, 9:13:14 PM5/5/16
to GeoScript
I added a few linear referencing methods but I don't think they are in the latest release:


Jared

Justin Deoliveira

unread,
May 5, 2016, 11:23:08 PM5/5/16
to GeoScript
Ahhhh… right :) I really need to do a release. I’ll throw this on my todo list.

Antony Chrysochoou

unread,
May 6, 2016, 5:17:46 AM5/6/16
to GeoScript
Thank you for your fast reply. 
Yes, indeed the jts.linearref did the trick. 
Amazing, thanks for pointing this out

Cheers,
A
Reply all
Reply to author
Forward
0 new messages