|
From: Schuster S. <ste...@ge...> - 2010-03-04 12:42:55
|
Hi again,
while trying to implement my suggested solution, I realised that it is not
only ugly, but it also doesnt work, as there is no CIRCLE Geometry I
could use.
Therefore, I really need help, thanks in advance!
Stefan
_____
Von: Schuster Stefan [mailto:ste...@ge...]
Gesendet: Donnerstag, 4. März 2010 12:42
An: geo...@li...
Betreff: [Geotools-gt2-users] position on LineString that is closest to
Point
Hi,
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.
But now I want to now the Point p_cut on the LineString that was used to
calculate the distance, more accurate I want to know the length of the
LineString from the beginning to the Point p_cut.
Any suggestions?
My first idea was to create a circle around Point p with a radius of
distance, and the intersection between this circle and the LineString is
point p_cut.
To get the length of LineString from the beginning to this point the
following algorithm could do it:
Create new empty line String lsCopy
Add first coordinate of the original LineString to lsCopy
DO
Add next coordinate of the original LineString to lsCopy
IF NOT lsCopy intersects p_cut THEN
Continue;
ELSE
Remove last coordinate from ls_copy
Add coordinates of p_cut to ls_copy
WHILE original LineString has next coordinate
I have not yet tried it, I guess it would work but this looks very ugly and
I wonder if there is a more beautiful solution?
Thanks for help
Stefan
|