Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Looking for a Java based (foss4g) solution for the following:

I am using a path along with a buffer to find features that are along the path. For each of the features returned I want to find the coordinate that is best fit ... meaning a straight line from the feature to the path and gleaning the point on the path.

share|improve this question
What software do you want to use? – whuber Mar 24 '11 at 17:44
I am already using GeoTools and would like to stick with that if possible ... definitely a Java based solution would be best. – Wally Atkins Mar 24 '11 at 18:33
up vote 6 down vote accepted

For Java, I'd recommend JTS Topology Suite. There is both a "Nearest Point" and "Closest Point" routine (I'm not sure if it is the same, or was renamed between versions) that does what you want. JTS

The result from the above is LINESTRING (205 305, 250 300), so the first point of the result is your closest point coordinates, and the length property of the result is the distance.

share|improve this answer seems to discuss the solution to your problem.

--- update by author of that page --

This page has been ported to sphinx based documentation:

That page just goes through how the JTS classes for snapping to a line can be used.

share|improve this answer
LocationIndexedLine is looking very promising ... – Wally Atkins Mar 24 '11 at 20:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.