|
From: Schuster S. <ste...@ge...> - 2010-03-04 13:57:44
|
Hi Wouter, thanks a lot for you're suggestion, but this works only for Lines that have only two point, a startPoint and an endPoint. In my case, I must also be able to handle LineStrings with more Coordinates. Therefore, I have to figure between which two Coordinates of the LineString the relevant Point could be. I have to think about that, but thanks so far! Stefan -----Ursprüngliche Nachricht----- Von: Wouter Schaubroeck [mailto:wou...@gm...] Gesendet: Donnerstag, 4. März 2010 14:32 An: Schuster Stefan Cc: geo...@li... Betreff: Re: [Geotools-gt2-users] position on LineString that is closest to Point Hi Stefan, Perhaps you could use math to solve the problem (only if the points are in a Euclidean plane): You have the coordinate of the point, and you have the coordinates of the endpoints of the line. As a third, you have the orthogonal distance between the point and the line. Next, you need to calculate the distance between one endpoint of the line, and the point. Mathworld: http://mathworld.wolfram.com/Point-PointDistance2-Dimensional.html Now you have 2 distances in the triangle, and you can use Pythagoras to solve your missing distance (the distance between the endpoint, and the orthogonal crossing point) Hope this helps, grtz, wouter -- Wouter http://blog.giswhat.be On 4 March 2010 13:35, Schuster Stefan <ste...@ge...> wrote: > 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 > > > > ---------------------------------------------------------------------------- -- > 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 > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > |