Ejemplo n.º 1
0
        /// <summary>
        /// Assumes input is valid (e.g. start &lt;= end)
        /// </summary>
        /// <param name="start">
        /// </param>
        /// <param name="end">
        /// </param>
        /// <returns>A linear geometry.</returns>
        private LineString ComputeLine(LinearLocation start, LinearLocation end)
        {
            ICoordinateList      coordinates    = line.Coordinates;
            CoordinateCollection newCoordinates = new CoordinateCollection();

            int startSegmentIndex = start.SegmentIndex;

            if (start.SegmentFraction > 0.0)
            {
                startSegmentIndex += 1;
            }
            int lastSegmentIndex = end.SegmentIndex;

            if (end.SegmentFraction == 1.0)
            {
                lastSegmentIndex += 1;
            }
            if (lastSegmentIndex >= coordinates.Count)
            {
                lastSegmentIndex = coordinates.Count - 1;
            }
            // not needed - LinearLocation values should always be correct
            //Assert.isTrue(end.getSegmentFraction() <= 1.0, "invalid segment fraction value");

            if (!start.Vertex)
            {
                newCoordinates.Add(start.GetCoordinate(line));
            }

            for (int i = startSegmentIndex; i <= lastSegmentIndex; i++)
            {
                newCoordinates.Add(coordinates[i]);
            }
            if (!end.Vertex)
            {
                newCoordinates.Add(end.GetCoordinate(line));
            }

            // ensure there is at least one coordinate in the result
            if (newCoordinates.Count <= 0)
            {
                newCoordinates.Add(start.GetCoordinate(line));
            }

            Coordinate[] newCoordinateArray = newCoordinates.ToArray();

            // Ensure there is enough coordinates to build a valid line.
            // Make a 2-point line with duplicate coordinates, if necessary.
            // There will always be at least one coordinate in the coordList.
            if (newCoordinateArray.Length <= 1)
            {
                newCoordinateArray = new Coordinate[] { newCoordinateArray[0],
                                                        newCoordinateArray[0] };
            }

            return(line.Factory.CreateLineString(newCoordinateArray));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Assumes input is valid (e.g. start &lt;= 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);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Computes the <see cref="Coordinate"/> for the point on the line
        /// at the given index.
        /// </summary>
        /// <param name="index">The index of the desired point.</param>
        /// <returns>The Coordinate at the given index.</returns>
        /// <remarks>
        /// If the index is out of range the first or last point on the
        /// line will be returned.
        /// </remarks>
        public virtual Coordinate ExtractPoint(double index)
        {
            LinearLocation loc = LengthLocationMap.GetLocation(
                linearGeom, index);

            return(loc.GetCoordinate(linearGeom));
        }
Ejemplo n.º 4
0
 /// <summary> Computes the <see cref="Coordinate"/> for the point
 /// on the line at the given index.
 /// If the index is out of range the first or last point on the
 /// line will be returned.
 ///
 /// </summary>
 /// <param name="length">the index of the desired point
 /// </param>
 /// <returns> the Coordinate at the given index
 /// </returns>
 public Coordinate ExtractPoint(LinearLocation index)
 {
     return(index.GetCoordinate(linearGeom));
 }