public void TestRepeatedCoordsLineString()
 {
     var line = reader.Read("LINESTRING (10 0, 10 0, 20 0)");
     var indexedLine = new LocationIndexedLine(line);
     var loc0 = indexedLine.IndexOf(new Coordinate(11, 0));
     Assert.IsTrue(loc0.CompareTo(new LinearLocation(1, 0.1)) == 0);
 }
 protected override Coordinate ExtractOffsetAt(IGeometry linearGeom, Coordinate testPt, double offsetDistance)
 {
     LocationIndexedLine indexedLine = new LocationIndexedLine(linearGeom);
     LinearLocation index = indexedLine.IndexOf(testPt);
     
     return indexedLine.ExtractPoint(index, offsetDistance);
 }
 protected override IGeometry IndicesOfThenExtract(IGeometry input, IGeometry subLine)
 {
     LocationIndexedLine indexedLine = new LocationIndexedLine(input);
     LinearLocation[] loc = indexedLine.IndicesOf(subLine);
     IGeometry result = indexedLine.ExtractLine(loc[0], loc[1]);
     return result;
 }
 public void TestZeroLengthLineString()
 {
     var line = reader.Read("LINESTRING (10 0, 10 0)");
     var indexedLine = new LocationIndexedLine(line);
     var loc0 = indexedLine.IndexOf(new Coordinate(11, 0));
     Assert.IsTrue(loc0.CompareTo(new LinearLocation(0, Double.NaN)) == 0);
 }
 private void RunExtractLine(String wkt, LinearLocation start, LinearLocation end, String expected)
 {
     IGeometry geom = Read(wkt);
     LocationIndexedLine lil = new LocationIndexedLine(geom);
     IGeometry result = lil.ExtractLine(start, end);
     //System.out.println(result);
     CheckExpected(result, expected);
 }
 /// <summary>
 /// Computes the <see cref="LineString" /> for the interval
 /// on the line between the given indices.
 /// If the <paramref name="endIndex" /> lies before the <paramref name="startIndex" />,
 /// the computed geometry is reversed.
 /// </summary>
 /// <param name="startIndex"></param>
 /// <param name="endIndex"></param>
 /// <returns></returns>
 public IGeometry ExtractLine(double startIndex, double endIndex)
 {
     LocationIndexedLine lil = new LocationIndexedLine(_linearGeom);
     double startIndex2 = ClampIndex(startIndex);
     double endIndex2 = ClampIndex(endIndex);
     // if extracted line is zero-length, resolve start lower as well to ensure they are equal
     bool resolveStartLower = startIndex2 == endIndex2;
     LinearLocation startLoc = LocationOf(startIndex2, resolveStartLower);
     //    LinearLocation endLoc = locationOf(endIndex2, true);
     //    LinearLocation startLoc = locationOf(startIndex2);
     LinearLocation endLoc = LocationOf(endIndex2);
     return ExtractLineByLocation.Extract(_linearGeom, startLoc, endLoc);
 }
        /// <summary>
        /// Computes the <see cref="LineString" /> for the interval
        /// on the line between the given indices.
        /// If the <paramref name="endIndex" /> lies before the <paramref name="startIndex" />,
        /// the computed geometry is reversed.
        /// </summary>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns></returns>
        public IGeometry ExtractLine(double startIndex, double endIndex)
        {
            var lil         = new LocationIndexedLine(_linearGeom);
            var startIndex2 = ClampIndex(startIndex);
            var endIndex2   = ClampIndex(endIndex);
            // if extracted line is zero-length, resolve start lower as well to ensure they are equal
            var resolveStartLower = startIndex2 == endIndex2;
            var startLoc          = LocationOf(startIndex2, resolveStartLower);
            //    LinearLocation endLoc = locationOf(endIndex2, true);
            //    LinearLocation startLoc = locationOf(startIndex2);
            var endLoc = LocationOf(endIndex2);

            return(ExtractLineByLocation.Extract(_linearGeom, startLoc, endLoc));
        }
        protected override bool IndexOfAfterCheck(IGeometry linearGeom, Coordinate testPt)
        {
            LocationIndexedLine indexedLine = new LocationIndexedLine(linearGeom);

            // check locations are consecutive
            LinearLocation loc1 = indexedLine.IndexOf(testPt);
            LinearLocation loc2 = indexedLine.IndexOfAfter(testPt, loc1);
            if (loc2.CompareTo(loc1) <= 0) return false;

            // check extracted points are the same as the input
            Coordinate pt1 = indexedLine.ExtractPoint(loc1);
            Coordinate pt2 = indexedLine.ExtractPoint(loc2);
            if (!pt1.Equals2D(testPt)) return false;
            if (!pt2.Equals2D(testPt)) return false;

            return true;
        }
        public void TestSameSegmentMultiLineString()
        {
            IGeometry line = reader.Read("MULTILINESTRING ((0 0, 10 0, 20 0), (20 0, 30 0))");
            LocationIndexedLine indexedLine = new LocationIndexedLine(line);

            LinearLocation loc0 = indexedLine.IndexOf(new Coordinate(0, 0));
            LinearLocation loc0_5 = indexedLine.IndexOf(new Coordinate(5, 0));
            LinearLocation loc1 = indexedLine.IndexOf(new Coordinate(10, 0));
            LinearLocation loc2 = indexedLine.IndexOf(new Coordinate(20, 0));
            LinearLocation loc2B = new LinearLocation(1, 0, 0.0);

            LinearLocation loc2_5 = indexedLine.IndexOf(new Coordinate(25, 0));
            LinearLocation loc3 = indexedLine.IndexOf(new Coordinate(30, 0));

            Assert.IsTrue(loc0.IsOnSameSegment(loc0));
            Assert.IsTrue(loc0.IsOnSameSegment(loc0_5));
            Assert.IsTrue(loc0.IsOnSameSegment(loc1));
            Assert.IsTrue(!loc0.IsOnSameSegment(loc2));
            Assert.IsTrue(!loc0.IsOnSameSegment(loc2_5));
            Assert.IsTrue(!loc0.IsOnSameSegment(loc3));

            Assert.IsTrue(loc0_5.IsOnSameSegment(loc0));
            Assert.IsTrue(loc0_5.IsOnSameSegment(loc1));
            Assert.IsTrue(!loc0_5.IsOnSameSegment(loc2));
            Assert.IsTrue(!loc0_5.IsOnSameSegment(loc3));

            Assert.IsTrue(!loc2.IsOnSameSegment(loc0));
            Assert.IsTrue(loc2.IsOnSameSegment(loc1));
            Assert.IsTrue(loc2.IsOnSameSegment(loc2));
            Assert.IsTrue(!loc2.IsOnSameSegment(loc3));
            Assert.IsTrue(loc2B.IsOnSameSegment(loc3));

            Assert.IsTrue(loc2_5.IsOnSameSegment(loc3));

            Assert.IsTrue(!loc3.IsOnSameSegment(loc0));
            Assert.IsTrue(!loc3.IsOnSameSegment(loc2));
            Assert.IsTrue(loc3.IsOnSameSegment(loc2B));
            Assert.IsTrue(loc3.IsOnSameSegment(loc2_5));
            Assert.IsTrue(loc3.IsOnSameSegment(loc3));
        }
        public void TestGetSegmentMultiLineString()
        {
            IGeometry line = reader.Read("MULTILINESTRING ((0 0, 10 0, 20 0), (20 0, 30 0))");
            LocationIndexedLine indexedLine = new LocationIndexedLine(line);

            LinearLocation loc0 = indexedLine.IndexOf(new Coordinate(0, 0));
            LinearLocation loc0_5 = indexedLine.IndexOf(new Coordinate(5, 0));
            LinearLocation loc1 = indexedLine.IndexOf(new Coordinate(10, 0));
            LinearLocation loc2 = indexedLine.IndexOf(new Coordinate(20, 0));
            LinearLocation loc2B = new LinearLocation(1, 0, 0.0);

            LinearLocation loc2_5 = indexedLine.IndexOf(new Coordinate(25, 0));
            LinearLocation loc3 = indexedLine.IndexOf(new Coordinate(30, 0));

            LineSegment seg0 = new LineSegment(new Coordinate(0, 0), new Coordinate(10, 0));
            LineSegment seg1 = new LineSegment(new Coordinate(10, 0), new Coordinate(20, 0));
            LineSegment seg2 = new LineSegment(new Coordinate(20, 0), new Coordinate(30, 0));

            Assert.IsTrue(loc0.GetSegment(line).Equals(seg0));
            Assert.IsTrue(loc0_5.GetSegment(line).Equals(seg0));

            Assert.IsTrue(loc1.GetSegment(line).Equals(seg1));
            Assert.IsTrue(loc2.GetSegment(line).Equals(seg1));

            Assert.IsTrue(loc2_5.GetSegment(line).Equals(seg2));
            Assert.IsTrue(loc3.GetSegment(line).Equals(seg2));
        }