Coordinate LengthIndexedLine::extractPoint(double index, double offsetDistance) const { LinearLocation loc = LengthLocationMap::getLocation(linearGeom, index); Coordinate ret; loc.getSegment(linearGeom)->pointAlongOffset(loc.getSegmentFraction(), offsetDistance, ret); return ret; }
/* public static */ LinearLocation LinearLocation::getEndLocation(const Geometry* linear) { // assert: linear is LineString or MultiLineString LinearLocation loc; loc.setToEnd(linear); return loc; }
LinearIterator::LinearIterator(const Geometry* linear, const LinearLocation& start): vertexIndex(segmentEndVertexIndex(start)), componentIndex(start.getComponentIndex()), linear(linear), numLines(static_cast<unsigned int>(linear->getNumGeometries())) { loadCurrentLine(); }
/* private */ LinearLocation LengthLocationMap::resolveHigher(const LinearLocation& loc) const { if (! loc.isEndpoint(*linearGeom)) return loc; unsigned int compIndex = loc.getComponentIndex(); // if last component can't resolve any higher if (compIndex >= linearGeom->getNumGeometries() - 1) return loc; do { compIndex++; } while (compIndex < linearGeom->getNumGeometries() - 1 && linearGeom->getGeometryN(compIndex)->getLength() == 0); // resolve to next higher location return LinearLocation(compIndex, 0, 0.0); }
double LengthLocationMap::getLength(const LinearLocation& loc) const { double totalLength = 0.0; LinearIterator it(linearGeom); while (it.hasNext()) { if (! it.isEndOfLine()) { Coordinate p0 = it.getSegmentStart(); Coordinate p1 = it.getSegmentEnd(); double segLen = p1.distance(p0); // length falls in this segment if (loc.getComponentIndex() == it.getComponentIndex() && loc.getSegmentIndex() == it.getVertexIndex()) { return totalLength + segLen * loc.getSegmentFraction(); } totalLength += segLen; } it.next(); } return totalLength; }
unsigned int LinearIterator::segmentEndVertexIndex(const LinearLocation& loc) { if (loc.getSegmentFraction() > 0.0) return loc.getSegmentIndex() + 1; return loc.getSegmentIndex(); }
Coordinate LengthIndexedLine::extractPoint(double index) const { LinearLocation loc = LengthLocationMap::getLocation(linearGeom, index); Coordinate coord = loc.getCoordinate(linearGeom); return coord; }