예제 #1
0
        /// <summary>
        /// sets the legend image in the layers form
        /// </summary>
        /// <param name="layerHandle"></param>
        /// <param name="pic"></param>
        /// <param name="layerType"></param>
        public void LayerSymbol(int layerHandle, System.Windows.Forms.PictureBox pic, string layerType, ShapeDrawingOptions drawingOptions = null)
        {
            bool isCategory = drawingOptions != null;

            if (pic.Image != null)
            {
                pic.Image.Dispose();
            }
            Rectangle rect = pic.ClientRectangle;
            int       w    = rect.Width / 2;
            int       h    = (rect.Height / 4) * 3;

            Bitmap   bmp = new Bitmap(rect.Width, rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            Graphics g   = Graphics.FromImage(bmp);

            IntPtr ptr = g.GetHdc();
            //int ptr = g.GetHdc().ToInt32();

            var ly = _axmap.get_GetObject(layerHandle);

            switch (layerType)
            {
            case "ShapefileClass":
                ((Shapefile)ly).With(shp =>
                {
                    ShapeDrawingOptions sdo = shp.DefaultDrawingOptions;
                    if (drawingOptions != null)
                    {
                        sdo = drawingOptions;
                    }
                    switch (shp.ShapefileType)
                    {
                    case ShpfileType.SHP_POINT:

                        if (isCategory)
                        {
                            sdo.DrawPoint(ptr, (rect.Width / 5) * 2, rect.Height / 4, 0, 0);
                        }
                        else
                        {
                            sdo.DrawPoint(ptr, (rect.Width / 5) * 2, rect.Height / 2, 0, 0);
                        }

                        break;

                    case ShpfileType.SHP_POLYGON:
                        sdo.DrawRectangle(ptr, rect.Width / 3, rect.Height / 4, w, h, shp.DefaultDrawingOptions.LineVisible, rect.Width, rect.Height);
                        break;

                    case ShpfileType.SHP_POLYLINE:
                        sdo.DrawLine(ptr, rect.Width / 3, rect.Height / 4, w, h, true, rect.Width, rect.Height);
                        break;
                    }

                    g.ReleaseHdc(ptr);
                    pic.Image = bmp;
                });

                break;

            case "ImageClass":
                if (MapLayerDictionary[layerHandle].ImageThumbnail == null)
                {
                    string filename = _axmap.get_Image(layerHandle).Filename;
                    bmp = new Bitmap(w, h);
                    g   = Graphics.FromImage(bmp);
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.FillRectangle(Brushes.White, (rect.Width / 5) * 1, rect.Height / 4, w, h);
                    try
                    {
                        g.DrawImage(new Bitmap(filename), 0, 0, w, h);
                        pic.Image = bmp;
                        MapLayerDictionary[layerHandle].ImageThumbnail = bmp;
                    }
                    catch { }
                }
                else
                {
                    pic.Image = MapLayerDictionary[layerHandle].ImageThumbnail;
                }
                break;
            }
        }
예제 #2
0
        /// <summary>
        /// Displays symbology form of the appropriate type
        /// </summary>
        public static Form GetSymbologyForm(LegendControl.Legend legend, int layerHandle, ShpfileType type, ShapeDrawingOptions options, bool applyDisabled)
        {
            Form form    = null;
            var  shpType = Globals.ShapefileType2D(type);
            var  layer   = legend.Layers.ItemByHandle(layerHandle);

            if (shpType == ShpfileType.SHP_POINT || shpType == ShpfileType.SHP_MULTIPOINT)
            {
                form = new PointsForm(legend, layer, options, applyDisabled);
            }
            else if (shpType == ShpfileType.SHP_POLYLINE)
            {
                form = new LinesForm(legend, layer, options, applyDisabled);
            }
            else if (shpType == ShpfileType.SHP_POLYGON)
            {
                form = new PolygonsForm(legend, layer, options, applyDisabled);
            }
            return(form);
        }
예제 #3
0
        /// <summary>
        /// Creates a new instance of PointsForm class
        /// </summary>
        public PointsForm(LegendControl.Legend legend, Layer layer, ShapeDrawingOptions options, bool applyDisabled)
        {
            InitializeComponent();
            if (options == null || legend == null)
            {
                throw new Exception("PointsForm: Unexpected null parameter");
            }

            m_legend = legend;

            // setting values to the controls
            _options   = options;
            m_layer    = layer;
            _initState = _options.Serialize();
            _noEvents  = true;

            btnApply.Visible = !applyDisabled;

            clpFillColor.SelectedColorChanged      += clpFillColor_SelectedColorChanged;
            cboIconCollection.SelectedIndexChanged += CboIconCollectionSelectedIndexChanged;
            cboFillType.SelectedIndexChanged       += cboFillType_SelectedIndexChanged;

            icbPointShape.ComboStyle = ImageComboStyle.PointShape;
            icbLineType.ComboStyle   = ImageComboStyle.LineStyle;
            icbLineWidth.ComboStyle  = ImageComboStyle.LineWidth;
            icbHatchStyle.ComboStyle = ImageComboStyle.HatchStyle;

            pnlFillPicture.Parent = groupBox3;    // options
            pnlFillPicture.Top    = pnlFillHatch.Top;
            pnlFillPicture.Left   = pnlFillHatch.Left;

            pnlFillGradient.Parent = groupBox3;    // options
            pnlFillGradient.Top    = pnlFillHatch.Top;
            pnlFillGradient.Left   = pnlFillHatch.Left;

            cboFillType.Items.Clear();
            cboFillType.Items.Add("Solid");
            cboFillType.Items.Add("Hatch");
            cboFillType.Items.Add("Gradient");

            cboGradientType.Items.Clear();
            cboGradientType.Items.Add("Linear");
            cboGradientType.Items.Add("Retangular");
            cboGradientType.Items.Add("Circle");

            // character control
            cboFontName.SelectedIndexChanged += cboFontName_SelectedIndexChanged;
            RefreshFontList(null, null);
            characterControl1.SelectedCharacterCode = (byte)_options.PointCharacter;

            // icon control
            RefreshIconCombo();

            chkScaleIcons.Checked = _options.PictureScaleX != 1.0 || _options.PictureScaleY != 1.0;

            //if (layer != null)
            //{
            //SymbologySettings settings = Globals.get_LayerSettings(m_layer.Handle);
            //if (settings != null)
            //{
            //    iconControl1.SelectedIndex = settings.IconIndex;
            //    chkScaleIcons.Checked = settings.ScaleIcons;
            //    string name = settings.IconCollection.ToLower();
            //    for (int i = 0; i < cboIconCollection.Items.Count; i++)
            //    {
            //        if (cboIconCollection.Items[i].ToString().ToLower() == name)
            //        {
            //            cboIconCollection.SelectedIndex = i;
            //            break;
            //        }
            //    }
            //}
            //}

            Options2Gui();
            _noEvents = false;

            // -----------------------------------------------------
            // adding event handlers
            // -----------------------------------------------------
            udRotation.ValueChanged        += Gui2Options;
            udPointNumSides.ValueChanged   += Gui2Options;
            udSideRatio.ValueChanged       += Gui2Options;
            udSize.ValueChanged            += Gui2Options;
            chkShowAllFonts.CheckedChanged += RefreshFontList;

            // line
            chkOutlineVisible.CheckedChanged  += Gui2Options;
            icbLineType.SelectedIndexChanged  += Gui2Options;
            icbLineWidth.SelectedIndexChanged += Gui2Options;
            clpOutline.SelectedColorChanged   += clpOutline_SelectedColorChanged;

            chkFillVisible.CheckedChanged += Gui2Options;

            iconControl1.SelectionChanged += IconControl1SelectionChanged;
            chkScaleIcons.CheckedChanged  += Gui2Options;

            // character
            characterControl1.SelectionChanged += characterControl1_SelectionChanged;
            symbolControl1.SelectionChanged    += SymbolControl1SelectionChanged;

            // hatch
            icbHatchStyle.SelectedIndexChanged  += Gui2Options;
            chkFillBgTransparent.CheckedChanged += Gui2Options;
            clpHatchBack.SelectedColorChanged   += Gui2Options;

            // gradient
            clpGradient2.SelectedColorChanged    += Gui2Options;
            udGradientRotation.ValueChanged      += Gui2Options;
            cboGradientType.SelectedIndexChanged += Gui2Options;

            DrawPreview();

            tabControl1.SelectedIndex = _tabIndex;
        }
예제 #4
0
 public GeometryStyle()
 {
     _style = new ShapeDrawingOptions();
 }
예제 #5
0
        /// <summary>
        /// Fills the image list with icons according to the selected colors
        /// </summary>
        public void RefreshImageList()
        {
            if (m_style == ImageComboStyle.Common)
            {
                return;
            }

            m_list.Images.Clear();

            int width;

            if (m_style == ImageComboStyle.PointShape)
            {
                width = 20;
            }
            else if (m_style == ImageComboStyle.ColorSchemeGraduated || m_style == ImageComboStyle.ColorSchemeRandom)
            {
                width = this.Width - 24;
            }
            else
            {
                width = 64;
            }

            Size sz = new Size(width, 16);

            m_list.ImageSize = sz;

            int _imgHeight = m_list.ImageSize.Height;
            int _imgWidth  = m_list.ImageSize.Width;

            Rectangle rect = new Rectangle(m_paddX, m_paddY, _imgWidth - 1 - m_paddX * 2, _imgHeight - 1 - m_paddY * 2);

            Color foreColor = this.Enabled ? Color.Black : Color.Gray;

            for (int i = 0; i < _itemCount; i++)
            {
                Bitmap   img = new Bitmap(_imgWidth, _imgHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                Graphics g   = Graphics.FromImage(img);

                switch (m_style)
                {
                // frame type combo
                case ImageComboStyle.FrameType:
                {
                    if (i == 0)
                    {
                        g.FillRectangle(new SolidBrush(_color1), rect);
                        g.DrawRectangle(new Pen(foreColor), rect);
                    }
                    else if (i == 1)
                    {
                        g.FillEllipse(new SolidBrush(_color1), rect);
                        g.DrawEllipse(new Pen(foreColor), rect);
                    }
                    else if (i == 2)
                    {
                        float left   = rect.X;
                        float right  = rect.X + rect.Width;
                        float top    = rect.Y;
                        float bottom = rect.Y + rect.Height;

                        GraphicsPath path = new GraphicsPath();
                        path.StartFigure();
                        path.AddLine(left + (rect.Height / 4), top, right - (rect.Height / 4), top);

                        path.AddLine(right - (rect.Height / 4), top, right, (top + bottom) / 2);
                        path.AddLine(right, (top + bottom) / 2, right - (rect.Height / 4), bottom);

                        path.AddLine(right - (rect.Height / 4), bottom, left + (rect.Height / 4), bottom);

                        path.AddLine(left + (rect.Height / 4), bottom, left, (top + bottom) / 2);
                        path.AddLine(left, (top + bottom) / 2, left + (rect.Height / 4), top);

                        path.CloseFigure();
                        g.FillPath(new SolidBrush(_color1), path);
                        g.DrawPath(new Pen(foreColor), path);
                        path.Dispose();
                        break;
                    }
                    break;
                }

                // linear gradient combo
                case ImageComboStyle.LinearGradient:
                {
                    if ((tkLinearGradientMode)i == tkLinearGradientMode.gmNone)
                    {
                        g.FillRectangle(new SolidBrush(_color1), rect);
                        g.DrawRectangle(new Pen(_outlineColor), rect);
                    }
                    else
                    {
                        LinearGradientBrush lgb = new LinearGradientBrush(rect, _color1, _color2, (LinearGradientMode)i);
                        g.FillRectangle(lgb, rect);
                        g.DrawRectangle(new Pen(_outlineColor), rect);
                        lgb.Dispose();
                    }
                    break;
                }

                //  line style combo
                case ImageComboStyle.LineStyle:
                {
                    Pen pen = new Pen(_outlineColor);
                    pen.DashStyle = (DashStyle)i;
                    pen.Width     = 2;
                    g.DrawLine(pen, new System.Drawing.Point(rect.Left, rect.Top + rect.Height / 2),
                               new System.Drawing.Point(rect.Right, rect.Top + rect.Height / 2));
                    break;
                }

                //  line width combo
                case ImageComboStyle.LineWidth:
                {
                    Pen pen = new Pen(_outlineColor);
                    pen.Width = i + 1;
                    g.DrawLine(pen, new System.Drawing.Point(rect.Left, rect.Top + rect.Height / 2),
                               new System.Drawing.Point(rect.Right, rect.Top + rect.Height / 2));
                    break;
                }

                case ImageComboStyle.PointShape:
                {
                    ShapeDrawingOptions sdo = new ShapeDrawingOptions();
                    sdo.FillColor  = Colors.ColorToUInteger(this._color1);
                    sdo.LineColor  = Colors.ColorToUInteger(this._outlineColor);
                    sdo.PointShape = (tkPointShapeType)i;
                    sdo.PointType  = tkPointSymbolType.ptSymbolStandard;
                    sdo.PointSize  = 12;
                    if (sdo.PointShape == tkPointShapeType.ptShapeStar)
                    {
                        sdo.PointSidesCount = 5;
                        sdo.PointRotation   = 17;
                        sdo.PointSize       = 14;
                    }
                    else if (sdo.PointShape == tkPointShapeType.ptShapeArrow)
                    {
                        sdo.PointSize     = 14;
                        sdo.PointRotation = 0;
                    }
                    else
                    {
                        sdo.PointSidesCount = 4;
                        sdo.PointRotation   = 0;
                        sdo.PointSize       = 12;
                    }

                    IntPtr ptr = g.GetHdc();
                    sdo.DrawPoint((int)ptr, 0.0f, 0.0f, _imgWidth, _imgHeight, Colors.ColorToUInteger(this.BackColor));
                    g.ReleaseHdc(ptr);
                    break;
                }

                case ImageComboStyle.HatchStyle:
                {
                    HatchBrush br = new HatchBrush((HatchStyle)i, _color1, Color.Transparent);
                    g.FillRectangle(br, rect);
                    g.DrawRectangle(new Pen(_outlineColor), rect);
                    br.Dispose();
                    break;
                }

                case ImageComboStyle.HatchStyleWithNone:
                {
                    if (i == 0)
                    {
                        g.FillRectangle(new SolidBrush(_color1), rect);
                        g.DrawRectangle(new Pen(_outlineColor), rect);
                    }
                    else
                    {
                        HatchBrush br = new HatchBrush((HatchStyle)(i - 1), _color1, Color.Transparent);
                        g.FillRectangle(br, rect);
                        g.DrawRectangle(new Pen(_outlineColor), rect);
                        br.Dispose();
                    }
                    break;
                }

                case ImageComboStyle.ColorSchemeGraduated:
                {
                    if (_colorSchemes != null)
                    {
                        ColorBlend blend = (_colorSchemes.List[i] as ColorBlend);
                        if (blend != null)
                        {
                            LinearGradientBrush lgb = new LinearGradientBrush(rect, Color.White, Color.White, 0.0f);
                            lgb.InterpolationColors = blend;
                            g.FillRectangle(lgb, rect);
                            g.DrawRectangle(new Pen(_outlineColor), rect);
                            lgb.Dispose();
                            break;
                        }
                    }
                    break;
                }

                case ImageComboStyle.ColorSchemeRandom:
                {
                    if (_colorSchemes != null)
                    {
                        ColorBlend blend = (_colorSchemes.List[i] as ColorBlend);
                        if (blend != null)
                        {
                            MapWinGIS.ColorScheme scheme = ColorSchemes.ColorBlend2ColorScheme(blend);
                            if (scheme != null)
                            {
                                int    n   = 0;
                                Random rnd = new Random();
                                while (n < _imgWidth)
                                {
                                    Color      clr      = Colors.UintToColor(scheme.get_RandomColor(rnd.NextDouble()));
                                    SolidBrush brush    = new SolidBrush(clr);
                                    Rectangle  rectTemp = new Rectangle(rect.X + n, rect.Y, 8, rect.Height);
                                    g.FillRectangle(brush, rectTemp);
                                    g.DrawRectangle(new Pen(_outlineColor), rectTemp);
                                    brush.Dispose();
                                    n += 8;
                                }
                            }
                        }
                    }
                    break;
                }

                default: return;
                }
                // adding an image
                m_list.Images.Add(img);
            }
        }
예제 #6
0
        /// <summary>
        /// Creates a new instance of PolygonsForm class
        /// </summary>
        public LinesForm(LegendControl.Legend legend, Layer layer, ShapeDrawingOptions options, bool applyDisabled)
        {
            InitializeComponent();

            if (options == null || layer == null)
            {
                throw new Exception("PolygonsForm: unexpected null parameter");
            }
            else
            {
                _options = options;
                m_layer  = layer;
            }

            m_legend         = legend;
            btnApply.Visible = !applyDisabled;
            _initState       = options.Serialize();


            icbLineType.ComboStyle  = ImageComboStyle.LineStyle;
            icbLineWidth.ComboStyle = ImageComboStyle.LineWidth;

            groupMarker.Parent = tabLine;
            groupMarker.Top    = groupLine.Top;
            groupMarker.Left   = groupLine.Left;

            cboVerticesType.Items.Clear();
            cboVerticesType.Items.Add("Square");
            cboVerticesType.Items.Add("Circle");

            cboOrientation.Items.Clear();
            cboOrientation.Items.Add("Horizontal");
            cboOrientation.Items.Add("Parallel");
            cboOrientation.Items.Add("Perpendicular");

            cboLineType.Items.Clear();
            cboLineType.Items.Add("Line");
            cboLineType.Items.Add("Marker");

            cboLineType.SelectedIndexChanged += new EventHandler(cboLineType_SelectedIndexChanged);
            cboLineType.SelectedIndex         = 0;

            // vertices
            chkVerticesVisible.CheckedChanged     += new EventHandler(GUI2Options);
            cboVerticesType.SelectedIndexChanged  += new EventHandler(GUI2Options);
            clpVerticesColor.SelectedColorChanged += new EventHandler(GUI2Options);
            chkVerticesFillVisible.CheckedChanged += new EventHandler(GUI2Options);
            udVerticesSize.ValueChanged           += new EventHandler(GUI2Options);

            InitLinePattern();

            Options2Grid();

            Options2GUI();

            linePatternControl1.LoadFromXML();

            _noEvents = true;
            tabControl1.SelectedIndex = _tabIndex;
            _noEvents = false;
        }
예제 #7
0
 /// <summary>
 /// Applies visualization options defined by ShapeDrawingOptions instance.
 /// </summary>
 /// <remarks>This method can be used to make the editor look consistent
 /// with the way subject shape looks in regular mode.</remarks>
 /// <param name="options">Instance of visualization options.</param>
 /// \see Shapefile.DefaultDrawingOptions
 public void CopyOptionsFrom(ShapeDrawingOptions options)
 {
     throw new NotImplementedException();
 }
        // <summary>
        // Calculates the length of intersection of rivers and land parcels
        // </summary>
        public void IntersectionLength(AxMap axMap1, ToolStripStatusLabel label, string dataPath)
        {
            axMap1.Projection             = tkMapProjection.PROJECTION_NONE;
            axMap1.GrabProjectionFromData = true;

            string filename1 = dataPath + "landuse.shp";
            string filename2 = dataPath + "waterways.shp";

            if (!File.Exists(filename1) || !File.Exists(filename2))
            {
                MessageBox.Show("The necessary files (waterways.shp, building.shp) are missing: " + dataPath);
            }
            else
            {
                Shapefile sfParcels = new Shapefile();
                sfParcels.Open(filename1, null);
                sfParcels.StartEditingShapes(true, null);

                Field field = new Field {
                    Name = "Length", Type = FieldType.DOUBLE_FIELD, Precision = 10
                };
                int fieldIndex = sfParcels.NumShapes;
                sfParcels.EditInsertField(field, ref fieldIndex, null);

                Shapefile sfRivers = new Shapefile();
                sfRivers.Open(filename2, null);
                sfRivers.StartEditingShapes(true, null);
                Utils utils = new Utils();
                sfRivers.DefaultDrawingOptions.LineWidth = 2;
                sfRivers.DefaultDrawingOptions.LineColor = utils.ColorByName(tkMapColor.Blue);

                Shapefile           sfNew   = sfRivers.Clone();
                ShapeDrawingOptions options = sfNew.DefaultDrawingOptions;

                LinePattern pattern = new LinePattern();
                pattern.AddLine(utils.ColorByName(tkMapColor.Blue), 8, tkDashStyle.dsSolid);
                pattern.AddLine(utils.ColorByName(tkMapColor.LightBlue), 4, tkDashStyle.dsSolid);
                options.LinePattern    = pattern;
                options.UseLinePattern = true;

                for (int i = 0; i < sfParcels.NumShapes; i++)
                {
                    Shape  shp1   = sfParcels.Shape[i];
                    double length = 0.0;    // the length of intersection

                    for (int j = 0; j < sfRivers.NumShapes; j++)
                    {
                        Shape shp2 = sfRivers.Shape[j];
                        if (shp1.Intersects(shp2))
                        {
                            Shape result = shp1.Clip(shp2, tkClipOperation.clIntersection);
                            if (result != null)
                            {
                                int index = sfNew.EditAddShape(result);
                                length += result.Length;
                            }
                        }
                    }
                    sfParcels.EditCellValue(fieldIndex, i, length);
                    label.Text = string.Format("Parcel: {0}/{1}", i + 1, sfParcels.NumShapes);
                    Application.DoEvents();
                }

                // generating charts
                var chartField = new ChartField();
                chartField.Name  = "Length";
                chartField.Color = utils.ColorByName(tkMapColor.LightBlue);
                chartField.Index = fieldIndex;
                sfParcels.Charts.AddField(chartField);
                sfParcels.Charts.Generate(tkLabelPositioning.lpInteriorPoint);
                sfParcels.Charts.ChartType     = tkChartType.chtBarChart;
                sfParcels.Charts.BarHeight     = 100;
                sfParcels.Charts.ValuesVisible = true;
                sfParcels.Charts.Visible       = true;

                axMap1.AddLayer(sfParcels, true);
                axMap1.AddLayer(sfRivers, true);
                axMap1.AddLayer(sfNew, true);
                axMap1.ZoomToMaxExtents();
            }
        }