Ejemplo n.º 1
0
LinearLocation LengthLocationMap::getLocationForward(double length) const
{
	if (length <= 0.0)
		return LinearLocation();

	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 (totalLength + segLen > length)
			{
				double frac = (length - totalLength) / segLen;
				unsigned int compIndex = it.getComponentIndex();
				unsigned int segIndex = it.getVertexIndex();
				return LinearLocation(compIndex, segIndex, frac);
			}
			totalLength += segLen;
		}
		it.next();
	}
	// length is longer than line - return end location
	return LinearLocation::getEndLocation(linearGeom);
}
Ejemplo n.º 2
0
/* private */
LinearLocation
LengthLocationMap::getLocationForward(double length) const
{
    if (length <= 0.0)
        return LinearLocation();

    double totalLength = 0.0;

    LinearIterator it (linearGeom);
    while (it.hasNext())
    {
        /**
         * Special handling is required for the situation when the
         * length references exactly to a component endpoint.
         * In this case, the endpoint location of the current component
         * is returned,
         * rather than the startpoint location of the next component.
         * This produces consistent behaviour with the project method.
         */
        if (it.isEndOfLine()) {
            if (totalLength == length) {
                unsigned int compIndex = it.getComponentIndex();
                unsigned int segIndex = it.getVertexIndex();
                return LinearLocation(compIndex, segIndex, 0.0);
            }
        }
        else {
            Coordinate p0 = it.getSegmentStart();
            Coordinate p1 = it.getSegmentEnd();
            double segLen = p1.distance(p0);
            // length falls in this segment
            if (totalLength + segLen > length)
            {
                double frac = (length - totalLength) / segLen;
                unsigned int compIndex = it.getComponentIndex();
                unsigned int segIndex = it.getVertexIndex();
                return LinearLocation(compIndex, segIndex, frac);
            }
            totalLength += segLen;
        }

        it.next();
    }
    // length is longer than line - return end location
    return LinearLocation::getEndLocation(linearGeom);
}
Ejemplo n.º 3
0
/* 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);
}