A LineString is a Curve with linear interpolation between points. Each consecutive pair of points defines a line segment.
Inheritance: Geometry
Esempio n. 1
0
 internal static IEnumerable<Point> WorldToScreen(LineString linearRing, IViewport viewport)
 {
     var v = new Point[linearRing.Vertices.Count];
     for (int i = 0; i < linearRing.Vertices.Count; i++)
         v[i] = viewport.WorldToScreen(linearRing.Vertices[i]);
     return v;
 }
Esempio n. 2
0
 public static void Render(Graphics graphics, LineString line, Pen pen, IViewport viewport)
 {
     if (line.Vertices.Count > 1)
     {
         var points = GeometryRenderer.WorldToScreenGDI(line, viewport);
         graphics.DrawLines(pen, points);
     }
 }
 public static void DrawLineString(Graphics graphics, LineString line, Pen pen, IViewport viewport)
 {
     if (line.Vertices.Count > 1)
     {
         var gp = new GraphicsPath();
         gp.AddLines(ConvertPoints(WorldToView(line, viewport)));
         graphics.DrawPath(pen, gp);
     }
 }
Esempio n. 4
0
        public static XamlShapes.Shape RenderLineString(LineString lineString, IStyle style, IViewport viewport)
        {
            if (!(style is VectorStyle)) throw new ArgumentException("Style is not of type VectorStyle");
            var vectorStyle = style as VectorStyle;

            XamlShapes.Path path = CreateLineStringPath(vectorStyle);
            path.Data = lineString.ToXaml();
            path.RenderTransform = new XamlMedia.MatrixTransform { Matrix = CreateTransformMatrix1(viewport) };
            CounterScaleLineWidth(path, viewport.Resolution);
            return path;
        }
Esempio n. 5
0
        internal static System.Drawing.PointF[] WorldToScreenGDI(LineString linearRing, IViewport viewport)
        {
            var v = new List<System.Drawing.PointF>(linearRing.Vertices.Count);
            for (int i = 0; i < linearRing.Vertices.Count; i++)
            {
                var point = viewport.WorldToScreen(linearRing.Vertices[i]);
                if (v.Count > 0 && i < linearRing.Vertices.Count - 1)
                {
                    var previousPoint = v.Last();
                    var xRange = Math.Round(previousPoint.X - point.X, 2);
                    var yRange = Math.Round(previousPoint.Y - point.Y, 2);

                    // Filter the point based on range.
                    if (!Filter(xRange) && !Filter(yRange))
                        continue;
                }
                v.Add(new System.Drawing.PointF((float)Math.Round(point.X, 2), (float)Math.Round(point.Y, 2)));
            }
            return v.ToArray();
        }
        private static XamlMedia.PathFigure CreatePathFigure(LineString lineString)
        {
            var pathFigure = new XamlMedia.PathFigure();
            pathFigure.IsClosed = lineString.IsClosed; //changed by report of Akrog (item 9194)

            bool first = true;

            foreach (var point in lineString.Vertices)
            {
                if (first)
                {
                    pathFigure.StartPoint = point.ToXaml();
                    first = false;
                }
                else
                {
                    pathFigure.Segments.Add(new XamlMedia.LineSegment { Point = point.ToXaml() });
                }
            }
            return pathFigure;
        }
        private Layer DrawRouteLine(List <Mapsui.Geometries.Point> vertices)
        {
            var list       = new List <IGeometry>();
            var lineString = new Mapsui.Geometries.LineString();

            vertices.ForEach(i => lineString.Vertices.Add(i));

            list.Add(lineString);
            return(new Layer
            {
                Style = new VectorStyle
                {
                    Enabled = true,
                    Line = new Pen(Mapsui.Styles.Color.Red, 7),
                    Fill = new Brush(Color.Red)
                },
                DataSource = new MemoryProvider(list)
                {
                    CRS = "EPSG:4326"
                }
            });
        }
Esempio n. 8
0
 /// <summary>
 /// Converts a LineString to LineString tagged text format, 
 /// </summary>
 /// <param name="lineString">The LineString to process.</param>
 /// <param name="writer">The output stream writer to Append to.</param>
 private static void AppendLineStringTaggedText(LineString lineString, StringWriter writer)
 {
     writer.Write("LINESTRING ");
     AppendLineStringText(lineString, writer);
 }
Esempio n. 9
0
 /// <summary>
 ///     Checks whether this instance is spatially equal to the LineString 'l'
 /// </summary>
 /// <param name="lineString">LineString to compare to</param>
 /// <returns>true of the objects are spatially equal</returns>
 public bool Equals(LineString lineString)
 {
     if (lineString?.Vertices.Count != Vertices.Count)
         return false;
     for (var i = 0; i < lineString.Vertices.Count; i++)
     {
         if (!lineString.Vertices[i].Equals(Vertices[i]))
             return false;
     }
     return true;
 }
Esempio n. 10
0
 /// <summary>
 ///     Return a copy of this geometry
 /// </summary>
 /// <returns>Copy of Geometry</returns>
 public new LineString Clone()
 {
     var l = new LineString();
     foreach (var vertex in Vertices)
     {
         l.Vertices.Add(vertex.Clone());
     }
     return l;
 }
Esempio n. 11
0
        private static void CalculateLabelOnLinestring(LineString line, ref Label label, IViewport viewportTransform)
        {
            double dx, dy;

            // first find the middle segment of the line
            int midPoint = (line.Vertices.Count - 1) / 2;
            if (line.Vertices.Count > 2)
            {
                dx = line.Vertices[midPoint + 1].X - line.Vertices[midPoint].X;
                dy = line.Vertices[midPoint + 1].Y - line.Vertices[midPoint].Y;
            }
            else
            {
                midPoint = 0;
                dx = line.Vertices[1].X - line.Vertices[0].X;
                dy = line.Vertices[1].Y - line.Vertices[0].Y;
            }
            if (Math.Abs(dy - 0) < Constants.Epsilon)
                label.Rotation = 0;
            else if (Math.Abs(dx - 0) < Constants.Epsilon)
                label.Rotation = 90;
            else
            {
                // calculate angle of line
                double angle = -Math.Atan(dy / dx) + Math.PI * 0.5;
                angle *= (180d / Math.PI); // convert radians to degrees
                label.Rotation = (float)angle - 90; // -90 text orientation
            }
            double tmpx = line.Vertices[midPoint].X + (dx * 0.5);
            double tmpy = line.Vertices[midPoint].Y + (dy * 0.5);
            label.LabelPoint = viewportTransform.WorldToScreen(new Geometries.Point(tmpx, tmpy));
        }
Esempio n. 12
0
 /// <summary>
 /// Checks whether this instance is spatially equal to the LineString 'l'
 /// </summary>
 /// <param name="l">LineString to compare to</param>
 /// <returns>true of the objects are spatially equal</returns>
 public bool Equals(LineString l)
 {
     if (l == null)
         return false;
     if (l.Vertices.Count != Vertices.Count)
         return false;
     for (int i = 0; i < l.Vertices.Count; i++)
         if (!l.Vertices[i].Equals(Vertices[i]))
             return false;
     return true;
 }
Esempio n. 13
0
 private static IEnumerable<Point> AllVertices(LineString lineString)
 {
     if (lineString == null)
         throw new ArgumentNullException("lineString");
     return lineString.Vertices;
 }
Esempio n. 14
0
		private static UIBezierPath CreatePathFigure(LineString linearRing, IViewport viewport)
		{
			var pathFigure = new UIBezierPath();
			var start = linearRing.Vertices[0];
			var startPos = viewport.WorldToScreen(start);

			pathFigure.MoveTo(ToUIKit(startPos));

			for(int i = 1; i < linearRing.Vertices.Count; i++)
			{
				var pos = linearRing.Vertices[i];
				var screenPos = viewport.WorldToScreen(pos);
				pathFigure.AddLineTo(ToUIKit(screenPos));
			}
			pathFigure.ClosePath();

			return pathFigure;
		}
Esempio n. 15
0
 protected override List<IGeometry> GetGeometries()
 {
     List<IGeometry> res = new List<IGeometry>();
     MultiLineString mult = new MultiLineString();
     LineString line = new LineString();
     int count = 1;
     foreach (var point in _points)
     {
         Point p = _currentProjection.Project(point.X, point.Y);
         if (p == null)
         {
             return null;
         }
         if (line.Vertices.Count == 0)
         {
             line.Vertices.Add(p);
         }
         else
         {
             var prev = _currentProjection.Inverse(line.Vertices.LastOrDefault().X, line.Vertices.LastOrDefault().Y);
             if (Math.Abs(line.Vertices.LastOrDefault().X - p.X) > 180)
             {
                 double x1 = prev.X >= 0 ? 180 : -180;
                 double x2 = -x1;
                 double y = prev.Y + (point.Y - prev.Y) * Math.Abs(x1 - prev.X) / (Math.Abs(point.X - x2) + Math.Abs(x1 - prev.X));
                 var p1 = _currentProjection.Project(x1, y);
                 if (p1 != null)
                 {
                     line.Vertices.Add(p1);
                 }
                 else
                 {
                     return null;
                 }
                 mult.LineStrings.Add(line);
                 count++;
                 line = new LineString();
                 var p2 = _currentProjection.Project(x2, y);
                 if (p2 != null)
                 {
                     line.Vertices.Add(p2);
                 }
                 else
                 {
                     return null;
                 }
                 line.Vertices.Add(p);
             }
             else
             {
                 line.Vertices.Add(p);
             }
         }
     }
     mult.LineStrings.Add(line);
     if (count == 1)
     {
         res.Add(line);
     }
     res.Add(mult);
     return res;
 }
Esempio n. 16
0
        private static LineString CreateWKBLineString(BinaryReader reader, WkbByteOrder byteOrder)
        {
            var l = new LineString();
            //l.Vertices.AddRange(ReadCoordinates(reader, byteOrder));
            IEnumerable<Point> arrPoint = ReadCoordinates(reader, byteOrder);
            foreach (Point t in arrPoint)
            {
                l.Vertices.Add(t);
            }

            return l;
        }
Esempio n. 17
0
        /// <summary>
        /// Reads and parses the geometry with ID 'oid' from the ShapeFile
        /// </summary>
        /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks>
        /// <param name="oid">Object ID</param>
        /// <returns>geometry</returns>
        private Geometry ReadGeometry(uint oid)
        {
            brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length
            ShapeType type = (ShapeType) brShapeFile.ReadInt32(); //Shape type
            if (type == ShapeType.Null)
                return null;
            if (_ShapeType == ShapeType.Point || _ShapeType == ShapeType.PointM || _ShapeType == ShapeType.PointZ)
            {
                Point tempFeature = new Point();
                return new Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble());
            }
            else if (_ShapeType == ShapeType.Multipoint || _ShapeType == ShapeType.MultiPointM ||
                     _ShapeType == ShapeType.MultiPointZ)
            {
                brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box
                MultiPoint feature = new MultiPoint();
                int nPoints = brShapeFile.ReadInt32(); // get the number of points
                if (nPoints == 0)
                    return null;
                for (int i = 0; i < nPoints; i++)
                    feature.Points.Add(new Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble()));

                return feature;
            }
            else if (_ShapeType == ShapeType.PolyLine || _ShapeType == ShapeType.Polygon ||
                     _ShapeType == ShapeType.PolyLineM || _ShapeType == ShapeType.PolygonM ||
                     _ShapeType == ShapeType.PolyLineZ || _ShapeType == ShapeType.PolygonZ)
            {
                brShapeFile.BaseStream.Seek(32 + brShapeFile.BaseStream.Position, 0); //skip min/max box

                int nParts = brShapeFile.ReadInt32(); // get number of parts (segments)
                if (nParts == 0)
                    return null;
                int nPoints = brShapeFile.ReadInt32(); // get number of points

                int[] segments = new int[nParts + 1];
                //Read in the segment indexes
                for (int b = 0; b < nParts; b++)
                    segments[b] = brShapeFile.ReadInt32();
                //add end point
                segments[nParts] = nPoints;

                if ((int) _ShapeType%10 == 3)
                {
                    MultiLineString mline = new MultiLineString();
                    for (int LineID = 0; LineID < nParts; LineID++)
                    {
                        LineString line = new LineString();
                        for (int i = segments[LineID]; i < segments[LineID + 1]; i++)
                            line.Vertices.Add(new Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble()));
                        mline.LineStrings.Add(line);
                    }
                    if (mline.LineStrings.Count == 1)
                        return mline[0];
                    return mline;
                }
                else //(_ShapeType == ShapeType.Polygon etc...)
                {
                    //First read all the rings
                    List<LinearRing> rings = new List<LinearRing>();
                    for (int RingID = 0; RingID < nParts; RingID++)
                    {
                        LinearRing ring = new LinearRing();
                        for (int i = segments[RingID]; i < segments[RingID + 1]; i++)
                            ring.Vertices.Add(new Point(brShapeFile.ReadDouble(), brShapeFile.ReadDouble()));
                        rings.Add(ring);
                    }
                    bool[] IsCounterClockWise = new bool[rings.Count];
                    int PolygonCount = 0;
                    for (int i = 0; i < rings.Count; i++)
                    {
                        IsCounterClockWise[i] = rings[i].IsCCW();
                        if (!IsCounterClockWise[i])
                            PolygonCount++;
                    }
                    if (PolygonCount == 1) //We only have one polygon
                    {
                        Polygon poly = new Polygon();
                        poly.ExteriorRing = rings[0];
                        if (rings.Count > 1)
                            for (int i = 1; i < rings.Count; i++)
                                poly.InteriorRings.Add(rings[i]);
                        return poly;
                    }
                    else
                    {
                        MultiPolygon mpoly = new MultiPolygon();
                        Polygon poly = new Polygon();
                        poly.ExteriorRing = rings[0];
                        for (int i = 1; i < rings.Count; i++)
                        {
                            if (!IsCounterClockWise[i])
                            {
                                mpoly.Polygons.Add(poly);
                                poly = new Polygon(rings[i]);
                            }
                            else
                                poly.InteriorRings.Add(rings[i]);
                        }
                        mpoly.Polygons.Add(poly);
                        return mpoly;
                    }
                }
            }
            else
                throw (new ApplicationException("Shapefile type " + _ShapeType.ToString() + " not supported"));
        }
Esempio n. 18
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>
 private static void AppendLineStringText(LineString lineString, StringWriter writer)
 {
     if (lineString == null || lineString.IsEmpty())
         writer.Write("EMPTY");
     else
     {
         writer.Write("(");
         for (int i = 0; i < lineString.NumPoints; i++)
         {
             if (i > 0)
                 writer.Write(", ");
             AppendCoordinate(lineString.Vertices[i], writer);
         }
         writer.Write(")");
     }
 }
Esempio n. 19
0
 /// <summary>
 /// Return a copy of this geometry
 /// </summary>
 /// <returns>Copy of Geometry</returns>
 public new LineString Clone()
 {
     var l = new LineString();
     foreach (Point vertex in _vertices)
         l.Vertices.Add(vertex.Clone());
     return l;
 }
Esempio n. 20
0
        /// <summary>
        /// Writes a linestring.
        /// </summary>
        /// <param name="ls">The linestring to be written.</param>
        /// <param name="bWriter">Stream to write to.</param>
        /// <param name="byteorder">Byte order</param>
        private static void WriteLineString(LineString ls, BinaryWriter bWriter, WkbByteOrder byteorder)
        {
            //Write the number of points in this linestring.
            WriteUInt32((uint) ls.Vertices.Count, bWriter, byteorder);

            //Loop on each vertices.
            foreach (Point p in ls.Vertices)
                WritePoint(p, bWriter, byteorder);
        }
Esempio n. 21
0
        /// <summary>
        /// Reads and parses the geometry with ID 'oid' from the ShapeFile
        /// </summary>
        /// <remarks><see cref="FilterDelegate">Filtering</see> is not applied to this method</remarks>
        /// <param name="oid">Object ID</param>
        /// <returns>geometry</returns>
        // ReSharper disable once CyclomaticComplexity // Fix when changes need to be made here
        private Geometry ReadGeometry(uint oid)
        {
            _brShapeFile.BaseStream.Seek(GetShapeIndex(oid) + 8, 0); //Skip record number and content length
            var type = (ShapeType)_brShapeFile.ReadInt32(); //Shape type
            if (type == ShapeType.Null)
                return null;
            if (_shapeType == ShapeType.Point || _shapeType == ShapeType.PointM || _shapeType == ShapeType.PointZ)
            {
                return new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble());
            }
            if (_shapeType == ShapeType.Multipoint || _shapeType == ShapeType.MultiPointM ||
                _shapeType == ShapeType.MultiPointZ)
            {
                _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box
                var feature = new MultiPoint();
                int nPoints = _brShapeFile.ReadInt32(); // get the number of points
                if (nPoints == 0)
                    return null;
                for (int i = 0; i < nPoints; i++)
                    feature.Points.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));

                return feature;
            }
            if (_shapeType == ShapeType.PolyLine || _shapeType == ShapeType.Polygon ||
                _shapeType == ShapeType.PolyLineM || _shapeType == ShapeType.PolygonM ||
                _shapeType == ShapeType.PolyLineZ || _shapeType == ShapeType.PolygonZ)
            {
                _brShapeFile.BaseStream.Seek(32 + _brShapeFile.BaseStream.Position, 0); //skip min/max box

                int nParts = _brShapeFile.ReadInt32(); // get number of parts (segments)
                if (nParts == 0)
                    return null;
                int nPoints = _brShapeFile.ReadInt32(); // get number of points

                var segments = new int[nParts + 1];
                //Read in the segment indexes
                for (int b = 0; b < nParts; b++)
                    segments[b] = _brShapeFile.ReadInt32();
                //add end point
                segments[nParts] = nPoints;

                if ((int)_shapeType % 10 == 3)
                {
                    var mline = new MultiLineString();
                    for (int lineId = 0; lineId < nParts; lineId++)
                    {
                        var line = new LineString();
                        for (int i = segments[lineId]; i < segments[lineId + 1]; i++)
                            line.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
                        mline.LineStrings.Add(line);
                    }
                    if (mline.LineStrings.Count == 1)
                        return mline[0];
                    return mline;
                }
                else //(_ShapeType == ShapeType.Polygon etc...)
                {
                    //First read all the rings
                    var rings = new List<LinearRing>();
                    for (int ringId = 0; ringId < nParts; ringId++)
                    {
                        var ring = new LinearRing();
                        for (int i = segments[ringId]; i < segments[ringId + 1]; i++)
                            ring.Vertices.Add(new Point(_brShapeFile.ReadDouble(), _brShapeFile.ReadDouble()));
                        rings.Add(ring);
                    }
                    var isCounterClockWise = new bool[rings.Count];
                    int polygonCount = 0;
                    for (int i = 0; i < rings.Count; i++)
                    {
                        isCounterClockWise[i] = rings[i].IsCCW();
                        if (!isCounterClockWise[i])
                            polygonCount++;
                    }
                    if (polygonCount == 1) //We only have one polygon
                    {
                        var poly = new Polygon { ExteriorRing = rings[0] };
                        if (rings.Count > 1)
                            for (int i = 1; i < rings.Count; i++)
                                poly.InteriorRings.Add(rings[i]);
                        return poly;
                    }
                    else
                    {
                        var mpoly = new MultiPolygon();
                        var poly = new Polygon { ExteriorRing = rings[0] };
                        for (var i = 1; i < rings.Count; i++)
                        {
                            if (!isCounterClockWise[i])
                            {
                                mpoly.Polygons.Add(poly);
                                poly = new Polygon(rings[i]);
                            }
                            else
                                poly.InteriorRings.Add(rings[i]);
                        }
                        mpoly.Polygons.Add(poly);
                        return mpoly;
                    }
                }
            }

            throw (new ApplicationException("Shapefile type " + _shapeType.ToString() + " not supported"));
        }