Hi!
I have tested this code with JTS 1.8:
String wkt = "LINEARRING (-13900 -920, -8300 120, -5020 3460, -9480 5660,
-15320 2620, -19420 4960, -19300 7600, -14620 8500, -13180 6840, -16380
5460, -22020 6280, -22340 3060, -18860 2120, -14820 4880, -10200 4460, -8680
2640, -8240 1780, -4420 -420, -5140 -2560, -9480 -3640, -12940 -2740, -13900
-920)";
LengthIndexedLine indexedLine = new LengthIndexedLine(lineString);
//A linearring with 4 self intersections that defines 5 cycles
//startIndex = 0
//endIndex = 81925.8327041274
//this coordinate is the first self intersection point. Its indices are
7212.794139706218 and 66311.95514388711.
Coordinate coord = new Coordinate(-7237.0558904219315, 1202.3882091435207);
double computedIndex = indexedLine.indexOf(coord);
And the result is 66311.95514!!!!
In accordance with indexOf javadoc method, resut would must be 7212.794 (the
first point since linearring start).
After some debugging, I have found that the problem is in LengthIndexOfPoint
class, in the private method indexOfFromStart.
double segDistance = seg.distance(inputPt);
double segMeasureToPt = segmentNearestMeasure(seg, inputPt,
segmentStartMeasure);
if (segDistance < minDistance
&& segMeasureToPt > minIndex) {
ptMeasure = segMeasureToPt;
minDistance = segDistance;
}
With the first occurrence of coord (index = 7212), segDistance =
9.947393674383302E-14.
In the second occurrence (index = 66311.9551), segDistance = 0.0, that is
lesser than 9.94E-14 so replace the first one and is the solution.
To solve it provisionally, I have used this approach:
double segDistance = seg.distance(inputPt);
PrecisionModel pm = linearGeom.getPrecisionModel();
segDistance = pm.makePrecise(segDistance);
double segMeasureToPt = segmentNearestMeasure(seg, inputPt,
segmentStartMeasure);
So If my geometries are created with a fixed precision model (for example
scale = 10000) the segment distance is adapted to this precision model, and
I get the right result.
Am I missing something?
Thank you very mutch and best regards!
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
_______________________________________________
jts-devel mailing list
[email protected]
http://lists.refractions.net/mailman/listinfo/jts-devel