예제 #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);
}
예제 #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);
}