Beispiel #1
0
        public static Segment3d ToSegment(this LineString _ls)
        {
            var p0 = _ls.GetCoordinateN(0).ToVector3d();
            var p1 = _ls.GetCoordinateN(1).ToVector3d();

            return(new Segment3d(p0, p1));
        }
Beispiel #2
0
 /// <summary>
 /// Converts a LineString to &lt;LineString Text&gt; format, then
 /// Appends it to the writer.
 /// </summary>
 /// <param name="lineString">The LineString to process.</param>
 /// <param name="writer">The output stream to Append to.</param>
 public void AppendLineStringTextRelative(LineString lineString, TextWriter writer)
 {
     if (lineString.IsEmpty())
     {
         //writer.Write("EMPTY");
     }
     else
     {
         writer.Write(" M ");
         double currentX = lineString.GetCoordinateN(0).X;
         double currentY = lineString.GetCoordinateN(0).Y;
         double x        = 0;
         double y        = 0;
         AppendCoordinate(lineString.GetCoordinateN(0), writer, _precisionModel);
         Coordinate relativeCoordinate = new Coordinate();
         writer.Write(" l ");
         for (int i = 1; i < lineString.GetNumPoints(); i++)
         {
             x = lineString.GetCoordinateN(i).X;
             y = lineString.GetCoordinateN(i).Y;
             relativeCoordinate.X = x - currentX;
             relativeCoordinate.Y = y - currentY;
             AppendCoordinate(relativeCoordinate, writer, _precisionModel);
             currentX = x;
             currentY = y;
             if (i % 5 == 4)
             {
                 writer.WriteLine();
             }
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Gets the <see cref="Coordinate" /> along the
        /// given linear <see cref="Geometry" /> which is
        /// referenced by this location.
        /// </summary>
        /// <param name="linearGeom">A linear geometry.</param>
        /// <returns>The <see cref="Coordinate" /> at the location.</returns>
        public virtual ICoordinate GetCoordinate(IGeometry linearGeom)
        {
            LineString  lineComp = (LineString)linearGeom.GetGeometryN(componentIndex);
            ICoordinate p0       = lineComp.GetCoordinateN(segmentIndex);

            if (segmentIndex >= lineComp.NumPoints - 1)
            {
                return(p0);
            }
            ICoordinate p1 = lineComp.GetCoordinateN(segmentIndex + 1);

            return(PointAlongSegmentByFraction(p0, p1, segmentFraction));
        }
        private void CheckInputNotAltered(String wkt1, String wkt2, int scaleFactor)
        {
            LineString l1 = (LineString)_reader.Read(wkt1);
            LineString l2 = (LineString)_reader.Read(wkt2);

            Coordinate[] pt =
            {
                l1.GetCoordinateN(0),
                l1.GetCoordinateN(1),
                l2.GetCoordinateN(0),
                l2.GetCoordinateN(1)
            };
            CheckInputNotAltered(pt, scaleFactor);
        }
Beispiel #5
0
        public static Line ToLine(this LineString _ls)
        {
            var p0 = _ls.GetCoordinateN(0).ToXYZ();
            var p1 = _ls.GetCoordinateN(1).ToXYZ();

            if (p0.IsAlmostEqualToByDifference(p1, 0.0001))
            {
                return(null);
            }
            try
            {
                var line = Line.CreateBound(p0, p1);
                return(line);
            }
            catch { return(null); }
        }
Beispiel #6
0
        /// <summary>
        /// Gets the length of the segment in the given
        /// Geometry containing this location.
        /// </summary>
        /// <param name="linearGeom">A linear geometry.</param>
        /// <returns>The length of the segment.</returns>
        public virtual double GetSegmentLength(IGeometry linearGeom)
        {
            LineString lineComp = (LineString)linearGeom.GetGeometryN(componentIndex);

            // ensure segment index is valid
            int segIndex = segmentIndex;

            if (segmentIndex >= lineComp.NumPoints - 1)
            {
                segIndex = lineComp.NumPoints - 2;
            }

            ICoordinate p0 = lineComp.GetCoordinateN(segIndex);
            ICoordinate p1 = lineComp.GetCoordinateN(segIndex + 1);

            return(p0.Distance(p1));
        }
        /// <summary>
        /// Tests whether a <see cref="Geometry" /> is sequenced correctly.
        /// <see cref="LineString" />s are trivially sequenced.
        /// <see cref="MultiLineString" />s are checked for correct sequencing.
        /// Otherwise, <c>IsSequenced</c> is defined
        /// to be <c>true</c> for geometries that are not lineal.
        /// </summary>
        /// <param name="geom">The <see cref="Geometry" /> to test.</param>
        /// <returns>
        /// <c>true</c> if the <see cref="Geometry" /> is sequenced or is not lineal.
        /// </returns>
        public static bool IsSequenced(Geometry geom)
        {
            if (!(geom is MultiLineString))
            {
                return(true);
            }

            MultiLineString mls = geom as MultiLineString;

            // The nodes in all subgraphs which have been completely scanned
            ISet <ICoordinate> prevSubgraphNodes = new SortedSet <ICoordinate>();

            ICoordinate         lastNode  = null;
            IList <ICoordinate> currNodes = new List <ICoordinate>();

            for (int i = 0; i < mls.NumGeometries; i++)
            {
                LineString  line      = (LineString)mls.GetGeometryN(i);
                ICoordinate startNode = line.GetCoordinateN(0);
                ICoordinate endNode   = line.GetCoordinateN(line.NumPoints - 1);

                /*
                 * If this linestring is connected to a previous subgraph, geom is not sequenced
                 */
                if (prevSubgraphNodes.Contains(startNode))
                {
                    return(false);
                }
                if (prevSubgraphNodes.Contains(endNode))
                {
                    return(false);
                }

                if (lastNode != null && startNode != lastNode)
                {
                    // start new connected sequence
                    prevSubgraphNodes.AddAll(currNodes);
                    currNodes.Clear();
                }

                currNodes.Add(startNode);
                currNodes.Add(endNode);
                lastNode = endNode;
            }
            return(true);
        }
Beispiel #8
0
        public void test_CoordinateN()
        {
            LineString ls1    = SimpleOpen();
            Coordinate coord1 = new Coordinate(11.0, 12.0);
            Coordinate coord2 = new Coordinate(8.0, 15.0);
            Coordinate coord3 = new Coordinate(11.0, 18.0);
            Coordinate coord4 = new Coordinate(10.0, 21.0);

            Coordinate coord5 = ls1.GetCoordinateN(11);
            Coordinate coord6 = ls1.GetCoordinateN(14);
            Coordinate coord7 = ls1.GetCoordinateN(17);
            Coordinate coord8 = ls1.GetCoordinateN(20);

            Assertion.AssertEquals("CoordinateN-1: ", true, coord1.Equals(coord5));
            Assertion.AssertEquals("CoordinateN-2: ", true, coord2.Equals(coord6));
            Assertion.AssertEquals("CoordinateN-3: ", true, coord3.Equals(coord7));
            Assertion.AssertEquals("CoordinateN-4: ", true, coord4.Equals(coord8));
        }
Beispiel #9
0
        /// <summary>
        /// Given the specified test point, this checks each segment, and will return the closest point on the specified segment.
        /// </summary>
        /// <param name="self">The ILineString, whose point is returned.</param>
        /// <param name="testPoint">The point to test.</param>
        /// <returns>The closest point.</returns>
        public static Coordinate ClosestPoint(this LineString self, Coordinate testPoint)
        {
            Coordinate closest = self.GetCoordinateN(0);
            double     dist    = double.MaxValue;

            for (int i = 0; i < self.NumPoints - 1; i++)
            {
                LineSegment s        = new LineSegment(self.GetCoordinateN(i), self.GetCoordinateN(i + 1));
                Coordinate  temp     = s.ClosestPoint(testPoint);
                double      tempDist = testPoint.Distance(temp);
                if (tempDist < dist)
                {
                    dist    = tempDist;
                    closest = temp;
                }
            }

            return(closest);
        }
Beispiel #10
0
 protected void AppendLineStringTextAbsolute(LineString lineString, TextWriter writer)
 {
     if (lineString.IsEmpty())
     {
         //writer.Write("EMPTY");
     }
     else
     {
         writer.Write(" M ");
         AppendCoordinate(lineString.GetCoordinateN(0), writer, _precisionModel);
         for (int i = 1; i < lineString.GetNumPoints(); i++)
         {
             writer.Write(" L ");
             AppendCoordinate(lineString.GetCoordinateN(i), writer, _precisionModel);
             if (i % 5 == 4)
             {
                 writer.WriteLine();
             }
         }
     }
 }
Beispiel #11
0
        /// <summary>
        /// Add the linestring given to the polygonizer
        /// </summary>
        /// <param name="lineString">The line string</param>
        /// <param name="polygonizer">The polygonizer</param>
        static void AddLineString(LineString lineString, Polygonizer polygonizer)
        {
            if (lineString is LinearRing)
            { // LinearRings are treated differently to line strings : we need a LineString NOT a LinearRing
                lineString = lineString.Factory.CreateLineString(lineString.CoordinateSequence);
            }

            // unioning the linestring with the point makes any self intersections explicit.
            var point = lineString.Factory.CreatePoint(lineString.GetCoordinateN(0));
            var toAdd = lineString.Union(point);

            //Add result to polygonizer
            polygonizer.Add(toAdd);
        }
Beispiel #12
0
        private static LineString ExtractChain(LineString line, int index, int maxChainSize)
        {
            int size = maxChainSize + 1;

            if (index + size > line.NumPoints)
            {
                size = line.NumPoints - index;
            }
            var pts = new Coordinate[size];

            for (int i = 0; i < size; i++)
            {
                pts[i] = line.GetCoordinateN(index + i);
            }
            return(line.Factory.CreateLineString(pts));
        }
 private OrientationIndex getOrientationIndex(LineString ls)
 {
     return(Orientation.Index(ls.GetCoordinateN(0), ls.GetCoordinateN(1), ls.GetCoordinateN(2)));
 }