Ejemplo n.º 1
0
		public void Linestring()
		{
			LineString l = new LineString();
			Assert.IsTrue(l.IsEmpty());
			Assert.IsNull(l.GetBoundingBox());
			Assert.AreEqual(0, l.Length);
			Assert.IsFalse(l.Equals(null));
			Assert.IsTrue(l.Equals(new LineString()));

			Collection<Point> vertices = new Collection<Point>();
			vertices.Add(new Point(54, 23));
			vertices.Add(new Point(93, 12));
			vertices.Add(new Point(104, 32));
			l.Vertices = vertices;
			Assert.IsFalse(l.IsEmpty());
			Assert.IsFalse(l.IsClosed);
			Assert.AreEqual(3, l.NumPoints);
			Assert.AreEqual(new Point(54, 23), l.StartPoint);
			Assert.AreEqual(new Point(104,32), l.EndPoint);
			l.Vertices.Add(new Point(54, 23));
			Assert.IsTrue(l.IsClosed);
			Assert.AreEqual(114.15056678325843, l.Length);
			Assert.AreNotSame(l.Clone(), l);
			Assert.AreNotSame(l.Clone().Vertices[0], l.Vertices[0]);
			Assert.AreEqual(l.Clone(), l);
			LineString l2 = l.Clone();
			l2.Vertices[2] = l2.Vertices[2] + new Point(1, 1);
			Assert.AreNotEqual(l2, l);
			l2 = l.Clone();
			l2.Vertices.Add(new Point(34, 23));
			Assert.AreNotEqual(l2, l);
		}
Ejemplo n.º 2
0
		private LineString CreateLineString()
		{
			LineString ls = new LineString();
			ls.Vertices.Add(new Point(1, 2));
			ls.Vertices.Add(new Point(10, 22));
			ls.Vertices.Add(new Point(930, 123));
			return ls;
		}
 public void InOutInTest()
 {
     var lc = new SharpMap.Rendering.Symbolizer.CohenSutherlandLineClipping(0, 0, 10, 10);
     var l = new LineString(new[] { new Point(-5, 4), new Point(15, 4), new Point(15, 6), new Point(-5, 6), });
     var res = lc.ClipLineString(l);
     Assert.IsNotNull(res);
     Assert.IsInstanceOfType(typeof (MultiLineString), res);
     Assert.AreEqual("MULTILINESTRING ((0 4, 10 4), (10 6, 0 6))", res.ToString());
 }
Ejemplo n.º 4
0
        private static LineString CreateWKBLineString(BinaryReader reader, WkbByteOrder byteOrder)
        {
            SharpMap.Geometries.LineString l = new SharpMap.Geometries.LineString();
            //l.Vertices.AddRange(ReadCoordinates(reader, byteOrder));
            Point[] arrPoint = ReadCoordinates(reader, byteOrder);
            for (int i = 0; i < arrPoint.Length; i++)
            {
                l.Vertices.Add(arrPoint[i]);
            }

            return(l);
        }
Ejemplo n.º 5
0
        private Label CreateLabel(ILabelLayer layer, Geometry feature, string text, float rotation, ILabelStyle style, Map map, Graphics g)
        {
            System.Drawing.SizeF size = g.MeasureString(text, style.Font);

            System.Drawing.PointF position = map.WorldToImage(feature.GetBoundingBox().GetCentroid());
            position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
            position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f;
            if (position.X - size.Width > map.Size.Width || position.X + size.Width < 0 ||
                position.Y - size.Height > map.Size.Height || position.Y + size.Height < 0)
            {
                return(null);
            }
            else
            {
                SharpMap.Rendering.Label lbl;

                if (!style.CollisionDetection)
                {
                    lbl = new Label(text, position, rotation, layer.Priority, null, style);
                }
                else
                {
                    //Collision detection is enabled so we need to measure the size of the string
                    lbl = new Label(text, position, rotation, layer.Priority,
                                    new LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width, position.Y + size.Height * 0.5f + style.CollisionBuffer.Height,
                                                 size.Width + 2f * style.CollisionBuffer.Width, size.Height + style.CollisionBuffer.Height * 2f), style);
                }
                if (feature.GetType() == typeof(SharpMap.Geometries.LineString))
                {
                    SharpMap.Geometries.LineString line = feature as SharpMap.Geometries.LineString;
                    if (line.Length / map.PixelSize > size.Width) //Only label feature if it is long enough
                    {
                        CalculateLabelOnLinestring(line, ref lbl, map);
                    }
                    else
                    {
                        return(null);
                    }
                }

                return(lbl);
            }
        }
        public void SimpleTest()
        {
            var lc = new SharpMap.Rendering.Symbolizer.CohenSutherlandLineClipping(0, 0, 10, 10);
            var l = new LineString(new[] { new Point(-5, 5), new Point(15, 5), });
            var res = lc.ClipLineString(l);
            Assert.IsNotNull(res);
            Assert.IsInstanceOfType(typeof(MultiLineString), res);
            Assert.AreEqual("MULTILINESTRING ((0 5, 10 5))", res.ToString());

            l = new LineString(new[] { new Point(5, -5), new Point(5, 15), });
            res = lc.ClipLineString(l);
            Assert.IsNotNull(res);
            Assert.IsInstanceOfType(typeof(MultiLineString), res);
            Assert.AreEqual("MULTILINESTRING ((5 0, 5 10))", res.ToString());

            l = new LineString(new[] { new Point(5, -5), new Point(5, 5), new Point(5, 15), });
            res = lc.ClipLineString(l);
            Assert.IsNotNull(res);
            Assert.IsInstanceOfType(typeof(MultiLineString), res);
            Assert.AreEqual("MULTILINESTRING ((5 0, 5 5, 5 10))", res.ToString());
        }
Ejemplo n.º 7
0
        private void CalculateLabelOnLinestring(SharpMap.Geometries.LineString line, ref Label label, Map map)
        {
            double dx, dy;
            double tmpx, tmpy;
            double angle = 0.0;

            // 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 (dy == 0)
            {
                label.Rotation = 0;
            }
            else if (dx == 0)
            {
                label.Rotation = 90;
            }
            else
            {
                // calculate angle of line
                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
            }
            tmpx             = line.Vertices[midPoint].X + (dx * 0.5);
            tmpy             = line.Vertices[midPoint].Y + (dy * 0.5);
            label.LabelPoint = map.WorldToImage(new SharpMap.Geometries.Point(tmpx, tmpy));
        }
Ejemplo n.º 8
0
        protected override void OnRenderInternal(Map map, LineString linestring, Graphics g)
        {
            var clonedPattern = (GraphicsPath) Pattern.Clone();
            var graphicsPath = WarpPathToPath.Warp(LineStringToPath(linestring, map), clonedPattern, true, Interval);
            
            if (graphicsPath == null) return;

            // Fill?
            if (Fill != null)
                g.FillPath(Fill, graphicsPath);
            
            // Outline
            if (Line != null)
                g.DrawPath(Line, graphicsPath);
        }
Ejemplo n.º 9
0
		/// <summary>
		/// Creates a deep copy of the LineString.
		/// </summary>
		/// <returns>A copy of the LineString instance.</returns>
		public override Geometry Clone()
		{
			LineString l = new LineString();

			for (int i = 0; i < _vertices.Count; i++)
			{
				l.Vertices.Add(_vertices[i].Clone() as Point);
			}

			return l;
		}
Ejemplo n.º 10
0
        private static void CalculateLabelAroundOnLineString(SharpMap.Geometries.LineString line, ref BaseLabel label, Map map, System.Drawing.Graphics g, System.Drawing.SizeF textSize)
        {
            IList <SharpMap.Geometries.Point> sPoints = line.Vertices;

            // only get point in enverlop of map
            Collection <System.Drawing.PointF> colPoint = new Collection <System.Drawing.PointF>();
            bool bCheckStarted = false;

            for (int j = 0; j < sPoints.Count; j++)
            {
                if (map.Envelope.Grow(map.PixelSize * 10).Contains(sPoints[j]))
                {
                    //points[j] = map.WorldToImage(sPoints[j]);
                    colPoint.Add(map.WorldToImage(sPoints[j]));
                    bCheckStarted = true;
                }
                else if (bCheckStarted == true)
                {
                    // fix bug curved line out of map in center segment of line
                    break;
                }
            }

            if (colPoint.Count > 1)
            {
                label.TextOnPathLabel = new SharpMap.Rendering.TextOnPath();
                switch (label.Style.HorizontalAlignment)
                {
                case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left:
                    label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
                    break;

                case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right:
                    label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
                    break;

                case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center:
                    label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                    break;

                default:
                    label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                    break;
                }
                switch (label.Style.VerticalAlignment)
                {
                case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom:
                    label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.UnderPath;
                    break;

                case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Top:
                    label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.OverPath;
                    break;

                case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Middle:
                    label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath;
                    break;

                default:
                    label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath;
                    break;
                }
                int idxStartPath = 0;
                int numberPoint  = colPoint.Count;
                // start Optimzes Path points
                int step = 100;
                if (colPoint.Count >= step * 2)
                {
                    numberPoint = step * 2;;
                    switch (label.Style.HorizontalAlignment)
                    {
                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
                        idxStartPath = 0;
                        break;

                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
                        idxStartPath = colPoint.Count - step;
                        break;

                    case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                        idxStartPath = (int)colPoint.Count / 2 - step;
                        break;

                    default:
                        //label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
                        idxStartPath = (int)colPoint.Count / 2 - step;
                        break;
                    }
                }
                // end optimize path point
                System.Drawing.PointF[] points = new System.Drawing.PointF[numberPoint];
                int count = 0;
                if (colPoint[0].X <= colPoint[colPoint.Count - 1].X)
                {
                    for (int l = idxStartPath; l < numberPoint + idxStartPath; l++)
                    {
                        points[count] = colPoint[l];
                        count++;
                    }
                }
                else
                {
                    //reverse the path
                    for (int k = numberPoint - 1 + idxStartPath; k >= idxStartPath; k--)
                    {
                        points[count] = colPoint[k];
                        count++;
                    }
                }
                //get text size in page units ie pixels
                float textheight = label.Style.Font.Size;
                switch (label.Style.Font.Unit)
                {
                case System.Drawing.GraphicsUnit.Display:
                    textheight = textheight * g.DpiY / 75;
                    break;

                case System.Drawing.GraphicsUnit.Document:
                    textheight = textheight * g.DpiY / 300;
                    break;

                case System.Drawing.GraphicsUnit.Inch:
                    textheight = textheight * g.DpiY;
                    break;

                case System.Drawing.GraphicsUnit.Millimeter:
                    textheight = (float)(textheight / 25.4 * g.DpiY);
                    break;

                case System.Drawing.GraphicsUnit.Pixel:
                    //do nothing
                    break;

                case System.Drawing.GraphicsUnit.Point:
                    textheight = textheight * g.DpiY / 72;
                    break;
                }
                System.Drawing.Font topFont = new System.Drawing.Font(label.Style.Font.FontFamily, textheight, label.Style.Font.Style);
                //
                System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
                path.AddLines(points);

                label.TextOnPathLabel.PathColorTop          = System.Drawing.Color.Transparent;
                label.TextOnPathLabel.Text                  = label.Text;
                label.TextOnPathLabel.LetterSpacePercentage = 90;
                label.TextOnPathLabel.FillColorTop          = new System.Drawing.SolidBrush(label.Style.ForeColor);
                label.TextOnPathLabel.Font                  = topFont;
                label.TextOnPathLabel.PathDataTop           = path.PathData;
                label.TextOnPathLabel.Graphics              = g;
                //label.TextOnPathLabel.ShowPath=true;
                //label.TextOnPathLabel.PathColorTop = System.Drawing.Color.YellowGreen;
                if (label.Style.Halo != null)
                {
                    label.TextOnPathLabel.ColorHalo = label.Style.Halo;
                }
                else
                {
                    label.TextOnPathLabel.ColorHalo = null;// new System.Drawing.Pen(label.Style.ForeColor, (float)0.5);
                }
                path.Dispose();

                // MeasureString to get region
                label.TextOnPathLabel.MeasureString = true;
                label.TextOnPathLabel.DrawTextOnPath();
                label.TextOnPathLabel.MeasureString = false;
                // Get Region label for CollissionDetection here.
                System.Drawing.Drawing2D.GraphicsPath pathRegion = new System.Drawing.Drawing2D.GraphicsPath();

                if (label.TextOnPathLabel.RegionList.Count > 0)
                {
                    //int idxCenter = (int)label.TextOnPathLabel.PointsText.Count / 2;
                    //System.Drawing.Drawing2D.Matrix rotationMatrix = g.Transform.Clone();// new Matrix();
                    //rotationMatrix.RotateAt(label.TextOnPathLabel.Angles[idxCenter], label.TextOnPathLabel.PointsText[idxCenter]);
                    //if (label.TextOnPathLabel.PointsTextUp.Count > 0)
                    //{
                    //    for (int up = label.TextOnPathLabel.PointsTextUp.Count - 1; up >= 0; up--)
                    //    {
                    //        label.TextOnPathLabel.PointsText.Add(label.TextOnPathLabel.PointsTextUp[up]);
                    //    }

                    //}
                    pathRegion.AddRectangles(label.TextOnPathLabel.RegionList.ToArray());

                    // get box for detect colission here
                    label.Box = new LabelBox(pathRegion.GetBounds());
                    //g.FillRectangle(System.Drawing.Brushes.YellowGreen, label.Box);
                }
                pathRegion.Dispose();
            }
        }
Ejemplo n.º 11
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);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Convert WellKnownText to linestrings
 /// </summary>
 /// <param name="WKT"></param>
 /// <returns></returns>
 private LineString WktToLineString(string WKT)
 {
     LineString line = new LineString();
     WKT = WKT.Substring(WKT.LastIndexOf('(') + 1).Split(')')[0];
     string[] strPoints = WKT.Split(',');
     foreach (string strPoint in strPoints)
     {
         string[] coord = strPoint.Split(' ');
         line.Vertices.Add(new Point(double.Parse(coord[0], Map.NumberFormatEnUs),
                                     double.Parse(coord[1], Map.NumberFormatEnUs)));
     }
     return line;
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Function that actually renders the linestring
 /// </summary>
 /// <param name="map"></param>
 /// <param name="lineString"></param>
 /// <param name="g"></param>
 protected override void OnRenderInternal(Map map, LineString lineString, Graphics g)
 {
     var gp = new GraphicsPath();
     gp.AddLines(/*LimitValues(*/lineString.TransformToImage(map)/*)*/);
     if (ImmediateMode)
     {
         var tmp = new List<GraphicsPath>(new[] {gp});
         Symbolize(g, map, tmp);
     }
     else
         _graphicsPaths.Add(gp);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Return a copy of this geometry
 /// </summary>
 /// <returns>Copy of Geometry</returns>
 public new LineString Clone()
 {
     LineString l = new LineString();
     for (int i = 0; i < _Vertices.Count;i++ )
         l.Vertices.Add(_Vertices[i].Clone());
     return l;
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Renders a LineString to the map.
        /// </summary>
        /// <param name="g">Graphics reference</param>
        /// <param name="line">LineString to render</param>
        /// <param name="pen">Pen style used for rendering</param>
        /// <param name="map">Map reference</param>
        /// <param name="offset">Offset by which line will be moved to right</param>
        public static void DrawLineString(Graphics g, LineString line, Pen pen, Map map, float offset)
        {
            if (line.Vertices.Count > 1)
            {
                GraphicsPath gp = new GraphicsPath();
                if (offset == 0)
                    gp.AddLines(/*LimitValues(*/line.TransformToImage(map)/*, ExtremeValueLimit)*/);
                else
                    gp.AddLines(OffsetRight(/*LimitValues(*/line.TransformToImage(map)/*, ExtremeValueLimit)*/, offset));

                g.DrawPath(pen, gp);
            }
        }
Ejemplo n.º 16
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 (ReferenceEquals(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;
		}
Ejemplo n.º 17
0
        /// <summary>
        /// Transforms a <see cref="SharpMap.Geometries.LineString"/>.
        /// </summary>
        /// <param name="l">LineString to transform</param>
        /// <param name="transform">MathTransform</param>
        /// <returns>Transformed LineString</returns>
        public static LineString TransformLineString(LineString l, IMathTransform transform)
        {
            try
            {
                List<double[]> points = new List<double[]>();

                for (int i = 0; i < l.Vertices.Count; i++)
                    points.Add(new double[2] {l.Vertices[i].X, l.Vertices[i].Y});

                return new LineString(transform.TransformList(points));
            }
            catch
            {
                return null;
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Transforms a <see cref="SharpMap.Geometries.LineString"/>.
        /// </summary>
        /// <param name="l">LineString to transform</param>
        /// <param name="from">Source Projection</param>
        /// <param name="to">Target Projection</param>
        /// <returns>Transformed LineString</returns>
        public static LineString TransformLineString(LineString l, ProjectionInfo from, ProjectionInfo to)
        {
            try
            {
                List<double[]> points = new List<double[]>();

                for (int i = 0; i < l.Vertices.Count; i++)
                    points.Add(new double[] {l.Vertices[i].X, l.Vertices[i].Y});

                return new LineString(TransformList(points, from, to));
            }
            catch
            {
                return null;
            }
        }
Ejemplo n.º 19
0
 /// <summary>  
 /// Converts a LineString to GeoJSON LineString 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.WriteLine("{");
   writer.WriteLine("\"type\": \"LineString\",");
   writer.WriteLine("\"coordinates\": ");
   AppendLineStringText(lineString, writer);
   //writer.WriteLine("]");  
   writer.WriteLine("}");
 }
Ejemplo 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);
		}
Ejemplo n.º 21
0
 /// <summary>
 /// Renders a LineString to the map.
 /// </summary>
 /// <param name="g">Graphics reference</param>
 /// <param name="line">LineString to render</param>
 /// <param name="pen">Pen style used for rendering</param>
 /// <param name="map">Map reference</param>
 public static void DrawLineString(Graphics g, LineString line, Pen pen, Map map)
 {
     if (line.Vertices.Count > 1)
     {
         GraphicsPath gp = new GraphicsPath();
         gp.AddLines(LimitValues(line.TransformToImage(map), ExtremeValueLimit));
         g.DrawPath(pen, gp);
     }
 }
Ejemplo n.º 22
0
        private void generateLines(Collection<Geometry> geometry, Random rndGen)
        {
            int numLines = rndGen.Next(10, 100);
            for (int lineIndex = 0; lineIndex < numLines; lineIndex++)
            {
                LineString line = new LineString();
                Collection<GeoPoint> verticies = new Collection<GeoPoint>();

                int numVerticies = rndGen.Next(4, 15);

                GeoPoint lastPoint = new GeoPoint(rndGen.NextDouble()*1000, rndGen.NextDouble()*1000);
                verticies.Add(lastPoint);

                for (int vertexIndex = 0; vertexIndex < numVerticies; vertexIndex++)
                {
                    GeoPoint nextPoint = new GeoPoint(lastPoint.X + rndGen.Next(-50, 50),
                                                      lastPoint.Y + rndGen.Next(-50, 50));
                    verticies.Add(nextPoint);

                    lastPoint = nextPoint;
                }

                line.Vertices = verticies;

                geometry.Add(line);
            }
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Function that actually renders the linestring
 /// </summary>
 /// <param name="map">The map</param>
 /// <param name="lineString">The line string to symbolize.</param>
 /// <param name="graphics">The graphics</param>
 protected abstract void OnRenderInternal(Map map, LineString lineString, Graphics graphics);
Ejemplo n.º 24
0
 public static void DrawLineString(Graphics g, LineString line, Pen pen, Map map)
 {
     DrawLineString(g, line, pen, map, 0);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Function to transform a linestring to a graphics path for further processing
 /// </summary>
 /// <param name="lineString">The Linestring</param>
 /// <param name="map">The map</param>
 ///// <param name="useClipping">A value indicating whether clipping should be applied or not</param>
 /// <returns>A GraphicsPath</returns>
 public static GraphicsPath LineStringToPath(LineString lineString, Map map)
 {
     var gp = new GraphicsPath(FillMode.Alternate);
     gp.AddLines(lineString.TransformToImage(map));
     return gp;
 }
Ejemplo n.º 26
0
 private static LineString CreateWKBLineString(BinaryReader reader, WkbByteOrder byteOrder)
 {
     SharpMap.Geometries.LineString l = new SharpMap.Geometries.LineString();
     l.Vertices.AddRange(ReadCoordinates(reader, byteOrder));
     return l;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Very basic test to check for positve direction of Linestring
        /// </summary>
        /// <param name="line">The linestring to test</param>
        /// <param name="isRightToLeft">Value indicating whether labels are to be printed right to left</param>
        /// <returns>The positively directed linestring</returns>
        private static LineString PositiveLineString(LineString line, bool isRightToLeft)
        {
            var s = line.StartPoint;
            var e = line.EndPoint;

            var dx = e.X - s.X;
            if (isRightToLeft && dx < 0)
                return line;
            
            if (!isRightToLeft && dx >= 0)
                return line;

            var revCoord = new Stack<Point>(line.Vertices);
            return new LineString(revCoord.ToArray());
        }
Ejemplo n.º 28
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 != this.Vertices.Count)
         return false;
     for(int i = 0; i < l.Vertices.Count; i++)
         if (!l.Vertices[i].Equals(this.Vertices[i]))
             return false;
     return true;
 }
Ejemplo n.º 29
0
        //private static void WarpedLabel(MultiLineString line, ref BaseLabel baseLabel, Map map)
        //{
        //    var path = MultiLineStringToPath(line, map, true);

        //    var pathLabel = new PathLabel(baseLabel.Text, path, 0f, baseLabel.Priority, new LabelBox(path.GetBounds()), baseLabel.Style);
        //    baseLabel = pathLabel;
        //}

        //private static void WarpedLabel(LineString line, ref BaseLabel baseLabel, Map map)
        //{
            
        //    var path = LineStringToPath(line, map, false);

        //    var pathLabel = new PathLabel(baseLabel.Text, path, 0f, baseLabel.Priority, new LabelBox(path.GetBounds()), baseLabel.Style);
        //    baseLabel = pathLabel;
        //}


        /// <summary>
        /// Function to transform a linestring to a graphics path for further processing
        /// </summary>
        /// <param name="lineString">The Linestring</param>
        /// <param name="map">The map</param>
        ///// <param name="useClipping">A value indicating whether clipping should be applied or not</param>
        /// <returns>A GraphicsPath</returns>
        public static GraphicsPath LineStringToPath(LineString lineString, Map map/*, bool useClipping*/)
        {
            var gp = new GraphicsPath(FillMode.Alternate);
            //if (!useClipping)
                gp.AddLines(lineString.TransformToImage(map));
            //else
            //{
            //    var bb = map.Envelope;
            //    var cohenSutherlandLineClipping = new CohenSutherlandLineClipping(bb.Left, bb.Bottom, bb.Right, bb.Top);
            //    var clippedLineStrings = cohenSutherlandLineClipping.ClipLineString(lineString);
            //    foreach (var clippedLineString in clippedLineStrings.LineStrings)
            //    {
            //        var s = clippedLineString.StartPoint;
            //        var e = clippedLineString.EndPoint;
                    
            //        var dx = e.X - s.X;
            //        //var dy = e.Y - s.Y;

            //        LineString revcls = null;
            //        if (dx < 0)
            //            revcls = ReverseLineString(clippedLineString);
                    
            //        gp.StartFigure();
            //        gp.AddLines(revcls == null ? clippedLineString.TransformToImage(map) : revcls.TransformToImage(map));
            //    }
            //}
            return gp;
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Function that actually renders the linestring
 /// </summary>
 /// <param name="map"></param>
 /// <param name="lineString"></param>
 /// <param name="g"></param>
 protected override void OnRenderInternal(Map map, LineString lineString, Graphics g)
 {
     var gp = new GraphicsPath();
     gp.AddLines(/*LimitValues(*/lineString.TransformToImage(map)/*)*/);
     _graphicsPaths.Add(gp);
 }
Ejemplo n.º 31
0
        //private static LineString ReverseLineString(LineString clippedLineString)
        //{
        //    var coords = new Stack<Point>(clippedLineString.Vertices);
        //    return new LineString(coords.ToArray());
        //}

        ///// <summary>
        ///// Function to transform a linestring to a graphics path for further processing
        ///// </summary>
        ///// <param name="multiLineString">The Linestring</param>
        ///// <param name="map">The map</param>
        ///// <param name="useClipping">A value indicating whether clipping should be applied or not</param>
        ///// <returns>A GraphicsPath</returns>
        //public static GraphicsPath MultiLineStringToPath(MultiLineString multiLineString, Map map, bool useClipping)
        //{
        //    var gp = new GraphicsPath(FillMode.Alternate);
        //    foreach (var lineString in multiLineString.LineStrings)
        //        gp.AddPath(LineStringToPath(lineString, map, useClipping), false);

        //    return gp;
        //}

        //private static GraphicsPath LineToGraphicsPath(LineString line, Map map)
        //{
        //    GraphicsPath path = new GraphicsPath();
        //    path.AddLines(line.TransformToImage(map));
        //    return path;
        //}

        private static void CalculateLabelOnLinestring(LineString line, ref BaseLabel baseLabel, Map map)
        {
            double dx, dy;
            var label = baseLabel as Label;

            // 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 (dy == 0)
                label.Rotation = 0;
            else if (dx == 0)
                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 = map.WorldToImage(new Point(tmpx, tmpy));
        }
Ejemplo n.º 32
0
        private static LineString CreateWKBLineString(BinaryReader reader, WkbByteOrder byteOrder)
        {
            LineString l = new LineString();
            //l.Vertices.AddRange(ReadCoordinates(reader, byteOrder));
            Point[] arrPoint = ReadCoordinates(reader, byteOrder);
            for (int i = 0; i < arrPoint.Length; i++)
                l.Vertices.Add(arrPoint[i]);

            return l;
        }
Ejemplo n.º 33
0
		/// <summary>
		/// Transforms a <see cref="SharpMap.Geometries.LineString"/>.
		/// </summary>
		/// <param name="l">LineString to transform</param>
		/// <param name="transform">MathTransform</param>
		/// <returns>Transformed LineString</returns>
		public static LineString TransformLineString(LineString l, IMathTransform transform)
		{
			try { return new LineString(transform.TransformList(l.Vertices)); }
			catch { return null; }
		}
Ejemplo n.º 34
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(")");
     }
 }
Ejemplo n.º 35
0
 private static LineString CreateWKBLineString(BinaryReader reader, WkbByteOrder byteOrder)
 {
     SharpMap.Geometries.LineString l = new SharpMap.Geometries.LineString();
     l.Vertices.AddRange(ReadCoordinates(reader, byteOrder));
     return(l);
 }