public double GetLength(LinearLocation loc) { double totalLength = 0.0; LinearIterator it = new LinearIterator(linearGeom); while (it.HasNext()) { if (!it.EndOfLine) { Coordinate p0 = it.SegmentStart; Coordinate p1 = it.SegmentEnd; double segLen = p1.Distance(p0); // length falls in this segment if (loc.ComponentIndex == it.ComponentIndex && loc.SegmentIndex == it.VertexIndex) { return(totalLength + segLen * loc.SegmentFraction); } totalLength += segLen; } it.Next(); } return(totalLength); }
private double IndexOfFromStart(Coordinate inputPt, double minIndex) { double minDistance = Double.MaxValue; double ptMeasure = minIndex; double segmentStartMeasure = 0.0; LineSegment seg = new LineSegment(linearGeom.Factory); LinearIterator it = new LinearIterator(linearGeom); while (it.HasNext()) { if (!it.EndOfLine) { seg.p0 = it.SegmentStart; seg.p1 = it.SegmentEnd; double segDistance = seg.Distance(inputPt); double segMeasureToPt = SegmentNearestMeasure(seg, inputPt, segmentStartMeasure); if (segDistance < minDistance && segMeasureToPt > minIndex) { ptMeasure = segMeasureToPt; minDistance = segDistance; } segmentStartMeasure += seg.Length; } it.Next(); } return(ptMeasure); }
/// <summary> /// Assumes input is valid (e.g. start <= end) /// </summary> /// <param name="start"> /// </param> /// <param name="end"> /// </param> /// <returns> a linear geometry /// </returns> private Geometry ComputeLinear(LinearLocation start, LinearLocation end) { LinearGeometryBuilder builder = new LinearGeometryBuilder(line.Factory); builder.FixInvalidLines = true; if (!start.Vertex) { builder.Add(start.GetCoordinate(line)); } for (LinearIterator it = new LinearIterator(line, start); it.HasNext(); it.Next()) { if (end.CompareLocationValues(it.ComponentIndex, it.VertexIndex, 0.0) < 0) { break; } Coordinate pt = it.SegmentStart; builder.Add(pt); if (it.EndOfLine) { builder.EndLine(); } } if (!end.Vertex) { builder.Add(end.GetCoordinate(line)); } return(builder.Geometry); }
private LinearLocation IndexOfFromStart(Coordinate inputPt, LinearLocation minIndex) { double minDistance = Double.MaxValue; int minComponentIndex = 0; int minSegmentIndex = 0; double minFrac = -1.0; LineSegment seg = new LineSegment(linearGeom.Factory); for (LinearIterator it = new LinearIterator(linearGeom); it.HasNext(); it.Next()) { if (!it.EndOfLine) { seg.p0 = it.SegmentStart; seg.p1 = it.SegmentEnd; double segDistance = seg.Distance(inputPt); double segFrac = SegmentFraction(seg, inputPt); int candidateComponentIndex = it.ComponentIndex; int candidateSegmentIndex = it.VertexIndex; if (segDistance < minDistance) { // ensure after minLocation, if any if (minIndex == null || minIndex.CompareLocationValues( candidateComponentIndex, candidateSegmentIndex, segFrac) < 0) { // otherwise, save this as new minimum minComponentIndex = candidateComponentIndex; minSegmentIndex = candidateSegmentIndex; minFrac = segFrac; minDistance = segDistance; } } } } LinearLocation loc = new LinearLocation(minComponentIndex, minSegmentIndex, minFrac); return(loc); }
private LinearLocation GetLocationForward(double length) { if (length <= 0.0) { return(new LinearLocation()); } double totalLength = 0.0; LinearIterator it = new LinearIterator(linearGeom); while (it.HasNext()) { if (!it.EndOfLine) { Coordinate p0 = it.SegmentStart; Coordinate p1 = it.SegmentEnd; double segLen = p1.Distance(p0); // length falls in this segment if ((totalLength + segLen) > length) { double frac = (length - totalLength) / segLen; int compIndex = it.ComponentIndex; int segIndex = it.VertexIndex; return(new LinearLocation(compIndex, segIndex, frac)); } totalLength += segLen; } it.Next(); } // length is longer than line - return end location return(LinearLocation.GetEndLocation(linearGeom)); }