コード例 #1
0
        /// <summary>
        /// Draws a label on a polygon with various different methods
        /// </summary>
        /// <param name="e"></param>
        /// <param name="g"></param>
        /// <param name="f"></param>
        /// <param name="category"></param>
        /// <param name="selected"></param>
        /// <param name="existingLabels"></param>
        public static void DrawPolygonFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels)
        {
            ILabelSymbolizer symb = category.Symbolizer;

            if (selected)
            {
                symb = category.SelectionSymbolizer;
            }

            //Gets the features text and calculate the label size
            string txt = GetLabelText(f, category);

            if (txt == null)
            {
                return;
            }
            SizeF labelSize = g.MeasureString(txt, symb.GetFont());

            if (f.NumGeometries == 1)
            {
                RectangleF labelBounds = PlacePolygonLabel(f.BasicGeometry, e, labelSize, symb);
                CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
            }
            else
            {
                if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts)
                {
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        RectangleF labelBounds = PlacePolygonLabel(f.GetBasicGeometryN(n), e, labelSize, symb);
                        CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
                    }
                }
                else
                {
                    double   largestArea = 0;
                    IPolygon largest     = null;
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        IPolygon pg = Geometry.FromBasicGeometry(f.GetBasicGeometryN(n)) as IPolygon;
                        if (pg == null)
                        {
                            continue;
                        }
                        double tempArea = pg.Area;
                        if (largestArea < tempArea)
                        {
                            largestArea = tempArea;
                            largest     = pg;
                        }
                    }
                    RectangleF labelBounds = PlacePolygonLabel(largest, e, labelSize, symb);
                    CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
                }
            }

            //Depending on the labeling strategy we do diff things
        }
コード例 #2
0
        /// <summary>
        /// Draws a label on a line with various different methods.
        /// </summary>
        public static void DrawLineFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels)
        {
            var symb = selected ? category.SelectionSymbolizer : category.Symbolizer;

            //Gets the features text and calculate the label size
            string txt = category.CalculateExpression(f.DataRow, selected, f.Fid);

            if (txt == null)
            {
                return;
            }

            Func <SizeF> labelSize = () => g.MeasureString(txt, _caches.GetFont(symb));

            if (f.NumGeometries == 1)
            {
                var        angle       = GetAngleToRotate(symb, f, f.BasicGeometry);
                RectangleF labelBounds = PlaceLineLabel(f.BasicGeometry, labelSize, e, symb, angle);
                CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle);
            }
            else
            {
                //Depending on the labeling strategy we do diff things
                if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts)
                {
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        var        angle       = GetAngleToRotate(symb, f, f.GetBasicGeometryN(n));
                        RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(n), labelSize, e, symb, angle);
                        CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle);
                    }
                }
                else
                {
                    double longestLine  = 0;
                    int    longestIndex = 0;
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        ILineString ls         = f.GetBasicGeometryN(n) as ILineString;
                        double      tempLength = 0;
                        if (ls != null)
                        {
                            tempLength = ls.Length;
                        }
                        if (longestLine < tempLength)
                        {
                            longestLine  = tempLength;
                            longestIndex = n;
                        }
                    }
                    var        angle       = GetAngleToRotate(symb, f, f.GetBasicGeometryN(longestIndex));
                    RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(longestIndex), labelSize, e, symb, angle);
                    CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Draws a label on a polygon with various different methods
        /// </summary>
        public static void DrawPolygonFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels)
        {
            var symb = selected ? category.SelectionSymbolizer : category.Symbolizer;

            //Gets the features text and calculate the label size
            string txt = category.CalculateExpression(f.DataRow, selected, f.Fid);

            if (txt == null)
            {
                return;
            }
            var          angle     = GetAngleToRotate(symb, f);
            Func <SizeF> labelSize = () => g.MeasureString(txt, _caches.GetFont(symb));

            if (f.NumGeometries == 1)
            {
                RectangleF labelBounds = PlacePolygonLabel(f.BasicGeometry, e, labelSize, symb, angle);
                CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle);
            }
            else
            {
                if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts)
                {
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        RectangleF labelBounds = PlacePolygonLabel(f.GetBasicGeometryN(n), e, labelSize, symb, angle);
                        CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle);
                    }
                }
                else
                {
                    double   largestArea = 0;
                    IPolygon largest     = null;
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        IPolygon pg = Geometry.FromBasicGeometry(f.GetBasicGeometryN(n)) as IPolygon;
                        if (pg == null)
                        {
                            continue;
                        }
                        double tempArea = pg.Area;
                        if (largestArea < tempArea)
                        {
                            largestArea = tempArea;
                            largest     = pg;
                        }
                    }
                    RectangleF labelBounds = PlacePolygonLabel(largest, e, labelSize, symb, angle);
                    CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Draws a label on a point with various different methods.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="g"></param>
        /// <param name="f"></param>
        /// <param name="category"></param>
        /// <param name="selected"></param>
        /// <param name="existingLabels"></param>
        public static void DrawPointFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels)
        {
            var symb = selected ? category.SelectionSymbolizer : category.Symbolizer;

            //Gets the features text and calculate the label size
            string txt = category.CalculateExpression(f.DataRow, selected, f.Fid);

            if (txt == null)
            {
                return;
            }
            var          angle     = GetAngleToRotate(symb, f);
            Func <SizeF> labelSize = () => g.MeasureString(txt, _caches.GetFont(symb));

            //Depending on the labeling strategy we do different things
            if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts)
            {
                for (int n = 0; n < f.NumGeometries; n++)
                {
                    RectangleF labelBounds = PlacePointLabel(f.GetBasicGeometryN(n), e, labelSize, symb, angle);
                    CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle);
                }
            }
            else
            {
                RectangleF labelBounds = PlacePointLabel(f, e, labelSize, symb, angle);
                CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels, angle);
            }
        }
コード例 #5
0
        private static Geometry Intersect(IFeature f, IGeometry envelope)
        {
            Geometry clip;

            if (f.GeometryType == "GeometryCollection")
            {
                // This hack because DotSpatial 1.9 throws NullReferenceException when trying to Intersect GeometryCollection
                List <IBasicGeometry> arr = new List <IBasicGeometry>();
                for (int i = 0; i < f.NumGeometries; i++)
                {
                    IBasicGeometry g            = f.GetBasicGeometryN(i);
                    IFeature       intersection = new Feature(g).Intersection(envelope);
                    if (intersection == null)
                    {
                        continue;
                    }
                    clip = (Geometry)intersection.BasicGeometry;
                    arr.Add(clip);
                }
                clip = new GeometryCollection(arr, new GeometryFactory());
            }
            else
            {
                IFeature intersection = f.Intersection(envelope);
                if (intersection == null)
                {
                    return(null);
                }
                clip = (Geometry)intersection.BasicGeometry;
            }
            return(clip);
        }
コード例 #6
0
        /// <summary>
        /// Separate Parts
        /// </summary>
        /// <param name="poly"></param>
        /// <param name="polyParts"></param>
        public static void SeparateParts(ref IFeature poly, ref IFeature[] polyParts)
        {
            int numParts = poly.NumGeometries;
            if (numParts == 0)
            {
                numParts = 1;
            }

            IFeature[] parts = new IFeature[numParts];

            if (numParts > 1)
            {
                for (int i = 0; i <= numParts - 1; i++)
                {
                    int countPoints = poly.GetBasicGeometryN(i).Coordinates.Count;
                    List<Coordinate> partsList = new List<Coordinate>();
                    for (int j = 0; j <= countPoints - 1; j++)
                    {
                        partsList.Insert(j, poly.Coordinates[j]);
                    }

                    parts[i] = new Feature(FeatureType.Polygon, partsList);
                }

                polyParts = parts;
            }
            else
            {
                parts[0] = new Feature();
                parts[0] = poly;
                polyParts = parts;
            }
        }
コード例 #7
0
        /// <summary>
        /// Takes a MapWinGIS polygon shape and stores all x/y coordinates into a vertex array.
        /// </summary>
        /// <param name="poly">The polygon to be converted.</param>
        /// <param name="polyVertArray">The array[numParts][] that will contain the polygon vertices.</param>
        public static void ConvertPolyToVertexArray(ref IFeature poly, ref Coordinate[][] polyVertArray)
        {
            int numParts = poly.NumGeometries;
            if (numParts == 0)
            {
                numParts = 1;
            }

            int numPoints = poly.NumPoints;
            Coordinate[][] vertArray = new Coordinate[numParts][];
            if (numParts > 1)
            {
                // separate parts of polygon
                for (int i = 0; i <= numParts - 1; i++)
                {
                    int numPtsInPart = poly.GetBasicGeometryN(i).Coordinates.Count;
                    vertArray[i] = new Coordinate[numPtsInPart];
                    for (int j = 0; j <= numPtsInPart - 2; j++)
                    {
                        vertArray[i][j] = poly.GetBasicGeometryN(i).Coordinates[j];
                    }

                    // be sure to 'close' the polygon in the vertex array!
                    vertArray[i][numPtsInPart - 1] = vertArray[i][0];
                }
            }
            else
            {
                // all points in polygon go into same vertex array
                vertArray[0] = new Coordinate[numPoints];
                for (int i = 0; i <= numPoints - 1; i++)
                {
                    vertArray[0][i] = poly.Coordinates[i];
                }
            }

            polyVertArray = vertArray;
        }
コード例 #8
0
        /// <summary>
        /// This function checks to see if the current mouse location is over a vertex.
        /// </summary>
        /// <param name="e">The GeoMouseArgs parameter contains information about the mouse
        /// location and geographic coordinates.</param>
        private bool CheckForVertexDrag(GeoMouseArgs e)
        {
            Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);
            IEnvelope env       = Map.PixelToProj(mouseRect).ToEnvelope();

            if (e.Button == MouseButtons.Left)
            {
                if (_layer.DataSet.FeatureType == FeatureType.Polygon)
                {
                    for (int prt = 0; prt < _selectedFeature.NumGeometries; prt++)
                    {
                        IBasicGeometry     g      = _selectedFeature.GetBasicGeometryN(prt);
                        IList <Coordinate> coords = g.Coordinates;
                        for (int ic = 0; ic < coords.Count; ic++)
                        {
                            Coordinate c = coords[ic];
                            if (env.Contains(c))
                            {
                                _dragging  = true;
                                _dragCoord = c;
                                if (ic == 0)
                                {
                                    _closedCircleCoord = coords[coords.Count - 1];
                                    _previousPoint     = coords[coords.Count - 2];
                                    _nextPoint         = coords[1];
                                }
                                else if (ic == coords.Count - 1)
                                {
                                    _closedCircleCoord = coords[0];
                                    _previousPoint     = coords[coords.Count - 2];
                                    _nextPoint         = coords[1];
                                }
                                else
                                {
                                    _previousPoint     = coords[ic - 1];
                                    _nextPoint         = coords[ic + 1];
                                    _closedCircleCoord = null;
                                }
                                Map.Invalidate();
                                return(true);
                            }
                        }
                    }
                }
                else if (_layer.DataSet.FeatureType == FeatureType.Line)
                {
                    for (int prt = 0; prt < _selectedFeature.NumGeometries; prt++)
                    {
                        IBasicGeometry     g      = _selectedFeature.GetBasicGeometryN(prt);
                        IList <Coordinate> coords = g.Coordinates;
                        for (int ic = 0; ic < coords.Count; ic++)
                        {
                            Coordinate c = coords[ic];
                            if (env.Contains(c))
                            {
                                _dragging  = true;
                                _dragCoord = c;

                                if (ic == 0)
                                {
                                    _previousPoint = null;
                                    _nextPoint     = coords[1];
                                }
                                else if (ic == coords.Count - 1)
                                {
                                    _previousPoint = coords[coords.Count - 2];
                                    _nextPoint     = null;
                                }
                                else
                                {
                                    _previousPoint = coords[ic - 1];
                                    _nextPoint     = coords[ic + 1];
                                }
                                Map.Invalidate();
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
コード例 #9
0
        /// <summary>
        /// Draws a label on a line with various different methods
        /// </summary>
        /// <param name="e"></param>
        /// <param name="g"></param>
        /// <param name="f"></param>
        /// <param name="category"></param>
        /// <param name="selected"></param>
        /// <param name="existingLabels"></param>
        public static void DrawLineFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List<RectangleF> existingLabels)
        {
            if (f == null) return;
            ILabelSymbolizer symb = category.Symbolizer;
            if (selected) symb = category.SelectionSymbolizer;

            //Gets the features text and calculate the label size
            string txt = GetLabelText(f, category);
            if (txt == null) return;
            SizeF labelSize = g.MeasureString(txt, symb.GetFont());

            if (f.NumGeometries == 1)
            {
                RectangleF labelBounds = PlaceLineLabel(f.BasicGeometry, labelSize, e, symb);
                CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
            }
            else
            {
                //Depending on the labeling strategy we do diff things
                if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts)
                {
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(n), labelSize, e, symb);
                        CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
                    }
                }
                else
                {
                    double longestLine = 0;
                    int longestIndex = 0;
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        ILineString ls = f.GetBasicGeometryN(n) as ILineString;
                        double tempLength = 0;
                        if (ls != null) tempLength = ls.Length;
                        if (longestLine < tempLength)
                        {
                            longestLine = tempLength;
                            longestIndex = n;
                        }
                    }
                    RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(longestIndex), labelSize, e, symb);
                    CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Draws a label on a polygon with various different methods
        /// </summary>
        /// <param name="e"></param>
        /// <param name="g"></param>
        /// <param name="f"></param>
        /// <param name="category"></param>
        /// <param name="selected"></param>
        /// <param name="existingLabels"></param>
        public static void DrawPolygonFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List<RectangleF> existingLabels)
        {
            ILabelSymbolizer symb = category.Symbolizer;
            if (selected) symb = category.SelectionSymbolizer;

            //Gets the features text and calculate the label size
            string txt = GetLabelText(f, category);
            if (txt == null) return;
            SizeF labelSize = g.MeasureString(txt, symb.GetFont());

            if (f.NumGeometries == 1)
            {
                RectangleF labelBounds = PlacePolygonLabel(f.BasicGeometry, e, labelSize, symb);
                CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
            }
            else
            {
                if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts)
                {
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        RectangleF labelBounds = PlacePolygonLabel(f.GetBasicGeometryN(n), e, labelSize, symb);
                        CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
                    }
                }
                else
                {
                    double largestArea = 0;
                    IPolygon largest = null;
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        IPolygon pg = Geometry.FromBasicGeometry(f.GetBasicGeometryN(n)) as IPolygon;
                        if (pg == null) continue;
                        double tempArea = pg.Area;
                        if (largestArea < tempArea)
                        {
                            largestArea = tempArea;
                            largest = pg;
                        }
                    }
                    RectangleF labelBounds = PlacePolygonLabel(largest, e, labelSize, symb);
                    CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
                }
            }

            //Depending on the labeling strategy we do diff things
        }
コード例 #11
0
ファイル: Shape.cs プロジェクト: zhongshuiyuan/mapwindowsix
 /// <summary>
 /// Creates a shape based on the specified feature.  This shape will be standing alone,
 /// all by itself.  The fieldnames and field types will be null.
 /// </summary>
 /// <param name="feature"></param>
 public Shape(IFeature feature)
 {
     _shapeRange = new ShapeRange(feature.FeatureType);
     _attributes = feature.DataRow.ItemArray;
     IList<Coordinate> coords = feature.Coordinates;
     _vertices = new double[feature.NumPoints*2];
     _z = new double[feature.NumPoints];
     _m = new double[feature.NumPoints];
     for (int i = 0; i < coords.Count; i++)
     {
         Coordinate c = coords[i];
         _vertices[i*2] = c.X;
         _vertices[i*2 + 1] = c.Y;
         _z[i] = c.Z;
         _m[i] = c.M;
     }
     int offset = 0;
     for(int ig = 0; ig < feature.NumGeometries; ig++)
     {
         IBasicGeometry g = feature.GetBasicGeometryN(ig);
         PartRange prt = new PartRange(_vertices, 0, offset, feature.FeatureType);
         _shapeRange.Parts.Add(prt);
         offset += g.NumPoints;
     }
 }
コード例 #12
0
        /// <summary>
        /// Draws a label on a line with various different methods
        /// </summary>
        /// <param name="e"></param>
        /// <param name="g"></param>
        /// <param name="f"></param>
        /// <param name="category"></param>
        /// <param name="selected"></param>
        /// <param name="existingLabels"></param>
        public static void DrawLineFeature(MapArgs e, Graphics g, IFeature f, ILabelCategory category, bool selected, List <RectangleF> existingLabels)
        {
            if (f == null)
            {
                return;
            }
            ILabelSymbolizer symb = category.Symbolizer;

            if (selected)
            {
                symb = category.SelectionSymbolizer;
            }

            //Gets the features text and calculate the label size
            string txt = GetLabelText(f, category);

            if (txt == null)
            {
                return;
            }
            SizeF labelSize = g.MeasureString(txt, symb.GetFont());

            if (f.NumGeometries == 1)
            {
                RectangleF labelBounds = PlaceLineLabel(f.BasicGeometry, labelSize, e, symb);
                CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
            }
            else
            {
                //Depending on the labeling strategy we do diff things
                if (symb.PartsLabelingMethod == PartLabelingMethod.LabelAllParts)
                {
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(n), labelSize, e, symb);
                        CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
                    }
                }
                else
                {
                    double longestLine  = 0;
                    int    longestIndex = 0;
                    for (int n = 0; n < f.NumGeometries; n++)
                    {
                        ILineString ls         = f.GetBasicGeometryN(n) as ILineString;
                        double      tempLength = 0;
                        if (ls != null)
                        {
                            tempLength = ls.Length;
                        }
                        if (longestLine < tempLength)
                        {
                            longestLine  = tempLength;
                            longestIndex = n;
                        }
                    }
                    RectangleF labelBounds = PlaceLineLabel(f.GetBasicGeometryN(longestIndex), labelSize, e, symb);
                    CollisionDraw(txt, g, symb, f, e, labelBounds, existingLabels);
                }
            }
        }