Michael,
I've finally had a chance to look at this problem. You were definitely
on the right track with your analysis of the problem.
I changed the fix code slightly, to reduce the number of lines of code
and to centralize the logic. The LinearLocation class now has a
toLowest(Geometry linearGeom) method, which "unnormalizes" a
LinearLocation if required, to ensure that the segmentIndex and
segmentFraction make sense when used with the pointAlongOffset method.
I added your unit tests, and they all pass now. Check it out if you can.
(I think the root of the problem is the decision to always normalize a
LinearLocation to have the lowest segmentFraction, even for endpoints.
This was a early design decision, and may not have been the best one.
It's potentially a bit tricky to change now, though).
Martin
On 10/27/2013 10:56 AM, Michaël Michaud wrote:
> Hi Martin,
>
> After much time spent to understand the rational behind LinearIterator and
>
> LinearLocation, I get a solution. I'm not completely satisfied by the
> design,
> because it happens lately in the process, is based on a naive if/else
> solution,
> and has to be duplicated in two classes...but at least, it seems to pass
> all the
> unit tests.
>
>
> First the test case which makes the current version fail :
> AbstractIndexedLineTest :
> public void testOffsetEndPoint()
> {
> runOffsetTest("LINESTRING (0 0, 13 13, 20 20)", "POINT(20 20)",
> 0.0, "POINT (20 20)");
> runOffsetTest("LINESTRING (0 0, 10 0, 20 0)", "POINT(20 0)", 1.0,
> "POINT (20 1)");
> runOffsetTest("LINESTRING (0 0, 20 0)", "POINT(10 0)", 1.0, "POINT
> (10 1)"); // point on last segment
> runOffsetTest("MULTILINESTRING ((0 0, 10 0), (10 0, 20 0))",
> "POINT(10 0)", -1.0, "POINT (10 -1)");
> runOffsetTest("MULTILINESTRING ((0 0, 10 0), (10 0, 20 0))",
> "POINT(20 0)", 1.0, "POINT (20 1)");
> }
>
> Now the fix for LengthIndexedLine
> public Coordinate extractPoint(double index, double offsetDistance)
> {
> LinearLocation loc = LengthLocationMap.getLocation(linearGeom, index);
> LineSegment segment = loc.getSegment(linearGeom);
> if (loc.isEndpoint(linearGeom)) {
> return segment.pointAlongOffset(1.0, offsetDistance);
> } else {
> return segment.pointAlongOffset(loc.getSegmentFraction(),
> offsetDistance);
> }
> }
>
> And the same for LocationIndexedLine
> public Coordinate extractPoint(LinearLocation index, double offsetDistance)
> {
> LineSegment segment = index.getSegment(linearGeom);
> if (index.isEndpoint(linearGeom)) {
> return segment.pointAlongOffset(1.0, offsetDistance);
> } else {
> return segment.pointAlongOffset(index.getSegmentFraction(),
> offsetDistance);
> }
> }
>
> Hope that helps,
>
> Michaël
>
>> Hi Martin,
>>
>> I found a small problem in linear referencing package (JTS 1.13).
>>
>> If I extract a point at distance 100 on LINESTRING(0 0, 100 0)
>> - I get 100, 0 with extractPoint(100) : test in testbuilder
>> - I get 0, 0 with extractPoint(100, 0) : test through OpenJUMP
>>
>> The result is not the same with the single parameter method
>> and the two parameters method.
>>
>> I think the problem comes from LengthLocationMap#getLocationForward
>> It computes the following LinearLocation (which seems OK so far)
>> getSegmentIndex = 1 (virtual second segment)
>> getSegmentFraction = 0.0 (first point)
>>
>> but in this particular case, LinearLocation#getSegment() returns
>> segment n-1 and not segment n (probably needed to be able to compute
>> offset).
>> To be consistent , returned LinearLocation should probably have
>> segmentIndex = 0
>> segmentFraction = 1.0
>>
>> Not sure if the problem is in LengthLocationMap#getLocationForward itself
>> or in LinearIterator#isEndOfLine() which is used by the former and returns
>> false if (componentIndex >= numLines)
>> or maybe I missed the point,
>>
>> thanks for your help
>>
>> Michaël
>>
>>
>> ------------------------------------------------------------------------------
>> October Webinars: Code for Performance
>> Free Intel webinars can help you accelerate application performance.
>> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
>> the latest Intel processors and coprocessors. See abstracts and register >
>> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Jts-topo-suite-user mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user
>>
>>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
>
> http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
> _______________________________________________
> Jts-topo-suite-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 2013.0.3426 / Virus Database: 3222/6785 - Release Date: 10/27/13
>
>
>
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Jts-topo-suite-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user