Example #1
0
        /// <summary>
        /// Appends the specified polygon to the graphics path.
        /// </summary>
        /// <param name="vertices">The vertices.</param>
        /// <param name="shpx">The shape range.</param>
        /// <param name="borderPath">The border path.</param>
        /// <param name="args">The map arguments.</param>
        /// <param name="shClip">The southerland hodgmen polygon clipper.</param>
        private static void BuildPolygon(double[] vertices, ShapeRange shpx, GraphicsPath borderPath, MapArgs args, SoutherlandHodgman shClip)
        {
            double minX = args.MinX;
            double maxY = args.MaxY;
            double dx   = args.Dx;
            double dy   = args.Dy;

            for (int prt = 0; prt < shpx.Parts.Count; prt++)
            {
                PartRange prtx   = shpx.Parts[prt];
                int       start  = prtx.StartIndex;
                int       end    = prtx.EndIndex;
                var       points = new List <double[]>(end - start + 1);

                for (int i = start; i <= end; i++)
                {
                    var pt = new[] { (vertices[i * 2] - minX) * dx, (maxY - vertices[(i * 2) + 1]) * dy };
                    points.Add(pt);
                }

                if (shClip != null)
                {
                    points = shClip.Clip(points);
                }

                var intPoints = DuplicationPreventer.Clean(points).ToArray();
                if (intPoints.Length < 2)
                {
                    continue;
                }

                borderPath.StartFigure();
                borderPath.AddLines(intPoints);
            }
        }
Example #2
0
        /// <summary>
        /// Adds the given points to the given path.
        /// </summary>
        /// <param name="path">Path the points get added to.</param>
        /// <param name="args">MapArgs used for clipping.</param>
        /// <param name="extent">Extent of the feature used for clipping.</param>
        /// <param name="points">Points that get added to the path.</param>
        /// <param name="clipRect">The clipping rectangle.</param>
        private static void AddLineStringToPath(GraphicsPath path, MapArgs args, Extent extent, List <double[]> points, Rectangle clipRect)
        {
            List <List <double[]> > multiLinestrings;

            if (!extent.Within(args.GeographicExtents))
            {
                multiLinestrings = CohenSutherland.ClipLinestring(points, clipRect.Left, clipRect.Top, clipRect.Right, clipRect.Bottom);
            }
            else
            {
                multiLinestrings = new List <List <double[]> >
                {
                    points
                };
            }

            foreach (List <double[]> linestring in multiLinestrings)
            {
                var intPoints = DuplicationPreventer.Clean(linestring).ToArray();
                if (intPoints.Length < 2)
                {
                    continue;
                }

                path.StartFigure();
                path.AddLines(intPoints);
            }
        }
Example #3
0
        internal static void BuildLineString(GraphicsPath path, double[] vertices, ShapeRange shpx, MapArgs args, Rectangle clipRect)
        {
            double minX = args.MinX;
            double maxY = args.MaxY;
            double dx   = args.Dx;
            double dy   = args.Dy;

            for (int prt = 0; prt < shpx.Parts.Count; prt++)
            {
                PartRange prtx   = shpx.Parts[prt];
                int       start  = prtx.StartIndex;
                int       end    = prtx.EndIndex;
                var       points = new List <double[]>(end - start + 1);

                for (int i = start; i <= end; i++)
                {
                    var pt = new[]
                    {
                        (vertices[i * 2] - minX) * dx,
                        (maxY - vertices[i * 2 + 1]) * dy
                    };
                    points.Add(pt);
                }

                List <List <double[]> > multiLinestrings;
                if (!shpx.Extent.Within(args.GeographicExtents))
                {
                    multiLinestrings = CohenSutherland.ClipLinestring(points, clipRect.Left, clipRect.Top,
                                                                      clipRect.Right, clipRect.Bottom);
                }
                else
                {
                    multiLinestrings = new List <List <double[]> > {
                        points
                    };
                }

                foreach (List <double[]> linestring in multiLinestrings)
                {
                    var intPoints = DuplicationPreventer.Clean(linestring).ToArray();
                    if (intPoints.Length < 2)
                    {
                        continue;
                    }

                    path.StartFigure();
                    path.AddLines(intPoints);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Appends the specified polygon to the graphics path.
        /// </summary>
        private static void BuildPolygon(double[] vertices, ShapeRange shpx, GraphicsPath borderPath, MapArgs args, SoutherlandHodgman shClip)
        {
            double minX = args.MinX;
            double maxY = args.MaxY;
            double dx   = args.Dx;
            double dy   = args.Dy;

            for (int prt = 0; prt < shpx.Parts.Count; prt++)
            {
                PartRange       prtx   = shpx.Parts[prt];
                int             start  = prtx.StartIndex;
                int             end    = prtx.EndIndex;
                List <double[]> points = new List <double[]>();

                for (int i = start; i <= end; i++)
                {
                    double[] pt = new double[2];
                    pt[X] = (vertices[i * 2] - minX) * dx;
                    pt[Y] = (maxY - vertices[i * 2 + 1]) * dy;
                    points.Add(pt);
                }
                if (null != shClip)
                {
                    points = shClip.Clip(points);
                }
                List <Point> intPoints = DuplicationPreventer.Clean(points);
                if (intPoints.Count < 2)
                {
                    points.Clear();
                    continue;
                }

                //Would be nice to figure out how to get rid of this lock
                lock (lock1)
                {
                    borderPath.StartFigure();
                    Point[] pointArray = intPoints.ToArray();
                    borderPath.AddLines(pointArray);
                }
                points.Clear();
            }
        }