Hi Stefan,
> Assume I have a Point p and a LineString ls.
>
> By the statement
>
> double dist = ls.distance(p)
>
> I easily can figure out the distance between them.
Not quite. I think that will give you the distance between the point
and the closest vertex of the LineString NOT the perpendicular
distance. In JTS 1.10 there is a class called EuclideanDistanceToPoint
that will give you the perp distance and the point that you are
calling p_cut...
import com.vividsolutions.jts.algorithm.distance.EuclideanDistanceToPoint;
import com.vividsolutions.jts.algorithm.distance.PointPairDistance;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.io.WKTReader;
import org.geotools.geometry.jts.JTSFactoryFinder;
public class Foo {
public static void main(String[] args) throws Exception {
GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null);
WKTReader reader = new WKTReader(gf);
Geometry line = reader.read("LINESTRING(0 0, 10 0, 10 10, 20 10)");
Coordinate c = new Coordinate(5, 5);
PointPairDistance ppd = new PointPairDistance();
EuclideanDistanceToPoint.computeDistance(line, c, ppd);
System.out.println(ppd.getDistance());
for (Coordinate cc : ppd.getCoordinates()) {
System.out.println(cc);
}
}
}
Keep in mind there can be multiple points on your line that are equal
in distance from the reference point. If you run the example above you
will get p_cut = (5, 0) with distance = 5 but it could also have been
(10, 5).
Michael
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users