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; }