public static IGeometry Project(IGeometry g, IGeometry g2)
 {
     var ll = new LengthIndexedLine(g);
     var index = ll.Project(g2.Coordinate);
     var p = ll.ExtractPoint(index);
     return g.Factory.CreatePoint(p);
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="wkt"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        public void RunExtractedLine(string wkt, double start, double end)    
        {
            Console.WriteLine("=========================");
            IGeometry g1 = rdr.Read(wkt);
            Console.WriteLine("Input Geometry: " + g1);
            Console.WriteLine("Indices to extract: " + start + " " + end);
            
            LengthIndexedLine indexedLine = new LengthIndexedLine(g1);

            IGeometry subLine = indexedLine.ExtractLine(start, end);
            Console.WriteLine("Extracted Line: " + subLine);

            double[] index = indexedLine.IndicesOf(subLine);
            Console.WriteLine("Indices of extracted line: " + index[0] + " " + index[1]);

            Coordinate midpt = indexedLine.ExtractPoint((index[0] + index[1]) / 2);
            Console.WriteLine("Midpoint of extracted line: " + midpt);
        }
 public static IGeometry ExtractPoint(IGeometry g, double index)
 {
     var ll = new LengthIndexedLine(g);
     var p = ll.ExtractPoint(index);
     return g.Factory.CreatePoint(p);
 }
 public static double ProjectIndex(IGeometry g, IGeometry g2)
 {
     var ll = new LengthIndexedLine(g);
     return ll.Project(g2.Coordinate);
 }
 public static IGeometry ExtractLine(IGeometry g, double start, double end)
 {
     var ll = new LengthIndexedLine(g);
     return ll.ExtractLine(start, end);
 }
        public void TestExtractPointBeyondRange()
        {
            IGeometry linearGeom = Read("LINESTRING (0 0, 10 10)");
            LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
            Coordinate pt = indexedLine.ExtractPoint(100);
            Assert.IsTrue(pt.Equals(new Coordinate(10, 10)));

            Coordinate pt2 = indexedLine.ExtractPoint(0);
            Assert.IsTrue(pt2.Equals(new Coordinate(0, 0)));
        }
 public void TestProjectExtractPoint()
 {
     IGeometry linearGeom = Read("MULTILINESTRING ((0 2, 0 0), (-1 1, 1 1))");
     LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
     var index = indexedLine.Project(new Coordinate(1, 0));
     Coordinate pt = indexedLine.ExtractPoint(index);
     Assert.IsTrue(pt.Equals(new Coordinate(0, 0)));
 }
 protected override Coordinate ExtractOffsetAt(IGeometry linearGeom, Coordinate testPt, double offsetDistance)
 {
     LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
     double index = indexedLine.IndexOf(testPt);
     return indexedLine.ExtractPoint(index, offsetDistance);
 }
        protected override bool IndexOfAfterCheck(IGeometry linearGeom, Coordinate testPt)
        {
            LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);

            // check locations are consecutive
            double loc1 = indexedLine.IndexOf(testPt);
            double loc2 = indexedLine.IndexOfAfter(testPt, loc1);
            if (loc2 <= loc1) 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;
        }
 protected override IGeometry IndicesOfThenExtract(IGeometry linearGeom, IGeometry subLine)
 {
     LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
     double[] loc = indexedLine.IndicesOf(subLine);
     IGeometry result = indexedLine.ExtractLine(loc[0], loc[1]);
     return result;
 }
 private void CheckExtractLine(String wkt, double start, double end, String expected)
 {
     IGeometry linearGeom = Read(wkt);
     LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
     IGeometry result = indexedLine.ExtractLine(start, end);
     CheckExpected(result, expected);
 }
 public void TestComputeZNaN()
 {
     IGeometry linearGeom = Read("LINESTRING (0 0, 10 10 10)");
     LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
     double projIndex = indexedLine.Project(new Coordinate(5, 5));
     Coordinate projPt = indexedLine.ExtractPoint(projIndex);
     Assert.IsTrue(Double.IsNaN(projPt.Z));
 }
 public void TestComputeZ()
 {
     IGeometry linearGeom = Read("LINESTRING (0 0 0, 10 10 10)");
     LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
     double projIndex = indexedLine.Project(new Coordinate(5, 5));
     Coordinate projPt = indexedLine.ExtractPoint(projIndex);
     //    System.out.println(projPt);
     Assert.IsTrue(projPt.Equals3D(new Coordinate(5, 5, 5)));
 }
 public void TestProjectPointWithDuplicateCoords()
 {
     IGeometry linearGeom = Read("LINESTRING (0 0, 10 0, 10 0, 20 0)");
     LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom);
     double projIndex = indexedLine.Project(new Coordinate(10, 1));
     Assert.IsTrue(projIndex == 10.0);
 }