Exemplo n.º 1
0
        private void btnQuant_Click(object sender, EventArgs e)
        {
            //Create a new instance for MapWinGIS.Table
            MapWinGIS.Table myTable = new MapWinGIS.Table();
            //Define the data source of Table instance
            myTable.Open(@"D:\GISSampleData2\arabcntry.dbf", null);
            //Define the index of the field will used in symbology
            int myFieldIndex = 1;
            //Get the number of rows in the table
            int numberOfRows = myTable.NumRows;

            //Create an array to store the cell values of the field
            double[] myCellsValues = new double[numberOfRows];
            //Populate the array with cell values restored from the Table instance
            for (int i = 0; i < numberOfRows - 1; i++)
            {
                myCellsValues[i] =
                    System.Convert.ToDouble(myTable.get_CellValue(1, i));
            }
            //Get the minimum and maximum values
            double minValue = myCellsValues.Min();
            double maxValue = myCellsValues.Max();

            //Create a new instance for MapWinGIS.ShapefileColorScheme
            MapWinGIS.ShapefileColorScheme myScheme = new MapWinGIS.ShapefileColorScheme();
            //Set the layer handler to the MapWinGIS.ShapefileColorScheme instance
            myScheme.LayerHandle = intHandler;
            //Set the field index to use in symbology
            myScheme.FieldIndex = myFieldIndex;
            //Create a new instance for MapWinGIS.ShapefileColorBreak
            MapWinGIS.ShapefileColorBreak myBreak = new MapWinGIS.ShapefileColorBreak();
            //Set the minimum value in the field as a start value
            myBreak.StartValue = minValue;
            //Set the start color of the scheme
            myBreak.StartColor =
                (UInt32)(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Aqua));
            //Set the maximum value in the field as an end value
            myBreak.EndValue = maxValue;
            //Set the end color of the sceme
            myBreak.EndColor =
                (UInt32)(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.DarkBlue));
            //Add the break to the color scheme
            myScheme.Add(myBreak);
            //Upgrade display using the scheme
            axMap1.ApplyLegendColors(myScheme);
        }
Exemplo n.º 2
0
        private static bool ImportScheme(MapWinGIS.ShapefileColorScheme sch, MapWinGIS.Shapefile sf, XmlElement e)
        {
            string FldName;
            int    i;

            MapWinGIS.ShapefileColorBreak brk;
            XmlNode n;
            bool    foundField = false;

            if (e == null)
            {
                return(false);
            }

            FldName = e.Attributes["FieldName"].InnerText;
            for (i = 0; i < sf.NumFields; i++)
            {
                if (sf.Field[i].Name.ToLower() == FldName.ToLower())
                {
                    sch.FieldIndex = i;
                    foundField     = true;
                    break;
                }
            }
            if (!foundField)
            {
                MapWinGIS.Utility.Logger.Message("无法找到 field \'" + FldName + "\'  无法导入coloring scheme.");
                return(false);
            }
            sch.Key = e.Attributes["Key"].InnerText;

            for (i = 0; i < e.ChildNodes.Count; i++)
            {
                n              = e.ChildNodes[i];
                brk            = new MapWinGIS.ShapefileColorBreak();
                brk.Caption    = n.Attributes["Caption"].InnerText;
                brk.StartColor = ColorScheme.ColorToUInt(Color.FromArgb(System.Convert.ToInt32(n.Attributes["StartColor"].InnerText)));
                brk.EndColor   = ColorScheme.ColorToUInt(Color.FromArgb(System.Convert.ToInt32(n.Attributes["EndColor"].InnerText)));
                brk.StartValue = n.Attributes["StartValue"].InnerText;
                brk.EndValue   = n.Attributes["EndValue"].InnerText;
                sch.Add(brk);
            }
            return(true);
        }
Exemplo n.º 3
0
        private static bool ExportScheme(MapWinGIS.ShapefileColorScheme Scheme, XmlDocument RootDoc, XmlElement Parent)
        {
            int          i;
            XmlElement   brk;
            XmlAttribute caption;
            XmlAttribute sValue;
            XmlAttribute eValue;
            XmlAttribute sColor;
            XmlAttribute eColor;

            MapWinGIS.ShapefileColorBreak curBrk;

            for (i = 0; i < Scheme.NumBreaks(); i++)
            {
                curBrk            = Scheme.ColorBreak[i];
                brk               = RootDoc.CreateElement("Break");
                caption           = RootDoc.CreateAttribute("Caption");
                sValue            = RootDoc.CreateAttribute("StartValue");
                eValue            = RootDoc.CreateAttribute("EndValue");
                sColor            = RootDoc.CreateAttribute("StartColor");
                eColor            = RootDoc.CreateAttribute("EndColor");
                caption.InnerText = curBrk.Caption;
                sValue.InnerText  = (curBrk.StartValue).ToString();
                eValue.InnerText  = (curBrk.EndValue).ToString();
                sColor.InnerText  = (ColorScheme.UIntToColor(curBrk.StartColor).ToArgb()).ToString();
                eColor.InnerText  = (ColorScheme.UIntToColor(curBrk.EndColor).ToArgb()).ToString();
                brk.Attributes.Append(caption);
                brk.Attributes.Append(sValue);
                brk.Attributes.Append(eValue);
                brk.Attributes.Append(sColor);
                brk.Attributes.Append(eColor);
                Parent.AppendChild(brk);
                curBrk = null;
            }
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 将图层颜色设置输出到一个指定路径
        /// </summary>
        public static bool ExportScheme(Interfaces.Layer lyr, string path)
        {
            XmlDocument  doc = new XmlDocument();
            XmlElement   mainScheme;
            XmlElement   root;
            XmlAttribute schemeType;

            root = doc.CreateElement("ColoringScheme");

            if (lyr == null)
            {
                return(false);
            }

            if (lyr.LayerType == Interfaces.eLayerType.LineShapefile || lyr.LayerType == Interfaces.eLayerType.PointShapefile || lyr.LayerType == Interfaces.eLayerType.PolygonShapefile)
            {
                MapWinGIS.ShapefileColorScheme sch = (MapWinGIS.ShapefileColorScheme)lyr.ColoringScheme;
                MapWinGIS.Shapefile            sf  = (MapWinGIS.Shapefile)lyr.GetObject();
                XmlAttribute fldName;
                XmlAttribute key;

                if (sch == null || sch.NumBreaks() == 0)
                {
                    return(false);
                }
                schemeType           = doc.CreateAttribute("SchemeType");
                schemeType.InnerText = "Shapefile";
                root.Attributes.Append(schemeType);
                mainScheme        = doc.CreateElement("ShapefileColoringScheme");
                fldName           = doc.CreateAttribute("FieldName");
                key               = doc.CreateAttribute("Key");
                fldName.InnerText = sf.Field[sch.FieldIndex].Name;
                key.InnerText     = sch.Key;

                mainScheme.Attributes.Append(fldName);
                mainScheme.Attributes.Append(key);
                root.AppendChild(mainScheme);
                doc.AppendChild(root);
                if (ExportScheme(((MapWinGIS.ShapefileColorScheme)lyr.ColoringScheme), doc, mainScheme))
                {
                    doc.Save(path);
                    return(true);
                }
                else
                {
                    MapWinGIS.Utility.Logger.Message("导出 coloring scheme 失败.", "错误");
                    return(false);
                }
            }
            else if (lyr.LayerType == Interfaces.eLayerType.Grid)
            {
                MapWinGIS.GridColorScheme sch = (MapWinGIS.GridColorScheme)lyr.ColoringScheme;
                MapWinGIS.Grid            grd = lyr.GetGridObject;
                XmlAttribute AmbientIntensity;
                XmlAttribute Key;
                XmlAttribute LightSourceAzimuth;
                XmlAttribute LightSourceElevation;
                XmlAttribute LightSourceIntensity;
                XmlAttribute NoDataColor;
                XmlAttribute GridName;
                XmlAttribute GroupName;
                XmlAttribute ImageLayerFillTransparency;
                XmlAttribute ImageUpsamplingMethod;
                XmlAttribute ImageDownsamplingMethod;

                if (sch == null || sch.NumBreaks == 0)
                {
                    return(false);
                }
                GridName             = doc.CreateAttribute("GridName");
                GroupName            = doc.CreateAttribute("GroupName");
                schemeType           = doc.CreateAttribute("SchemeType");
                schemeType.InnerText = "Grid";
                root.Attributes.Append(schemeType);

                AmbientIntensity = doc.CreateAttribute("AmbientIntensity");
                Key = doc.CreateAttribute("Key");
                LightSourceAzimuth         = doc.CreateAttribute("LightSourceAzimuth");
                LightSourceElevation       = doc.CreateAttribute("LightSourceElevation");
                LightSourceIntensity       = doc.CreateAttribute("LightSourceIntensity");
                ImageLayerFillTransparency = doc.CreateAttribute("ImageLayerFillTransparency");
                ImageUpsamplingMethod      = doc.CreateAttribute("ImageUpsamplingMethod");
                ImageDownsamplingMethod    = doc.CreateAttribute("ImageDownsamplingMethod");

                NoDataColor                          = doc.CreateAttribute("NoDataColor");
                GridName.InnerText                   = lyr.Name;
                GroupName.InnerText                  = Program.frmMain.Legend.Groups.ItemByHandle(lyr.GroupHandle).Text;
                AmbientIntensity.InnerText           = (sch.AmbientIntensity).ToString();
                Key.InnerText                        = sch.Key;
                LightSourceAzimuth.InnerText         = (sch.LightSourceAzimuth).ToString();
                LightSourceElevation.InnerText       = (sch.LightSourceElevation).ToString();
                LightSourceIntensity.InnerText       = (sch.LightSourceIntensity).ToString();
                NoDataColor.InnerText                = (ColorScheme.UIntToColor(sch.NoDataColor).ToArgb()).ToString();
                ImageLayerFillTransparency.InnerText = ((System.Convert.ToInt32(lyr.ImageLayerFillTransparency * 100)) / 100).ToString();

                MapWinGIS.Image img = new MapWinGIS.Image();
                img = (MapWinGIS.Image)(Program.frmMain.MapMain.get_GetObject(lyr.Handle));
                if (img.DownsamplingMode == MapWinGIS.tkInterpolationMode.imBicubic)
                {
                    ImageDownsamplingMethod.InnerText = "Bicubic";
                }
                else if (img.DownsamplingMode == MapWinGIS.tkInterpolationMode.imBilinear)
                {
                    ImageDownsamplingMethod.InnerText = "Bilinear";
                }
                else if (img.DownsamplingMode == MapWinGIS.tkInterpolationMode.imHighQualityBicubic)
                {
                    ImageDownsamplingMethod.InnerText = "HighQualityBicubic";
                }
                else if (img.DownsamplingMode == MapWinGIS.tkInterpolationMode.imHighQualityBilinear)
                {
                    ImageDownsamplingMethod.InnerText = "HighQualityBilinear";
                }
                else if (img.DownsamplingMode == MapWinGIS.tkInterpolationMode.imNone)
                {
                    ImageDownsamplingMethod.InnerText = "None";
                }
                else
                {
                    ImageDownsamplingMethod.InnerText = "None";
                }

                if (img.UpsamplingMode == MapWinGIS.tkInterpolationMode.imBicubic)
                {
                    ImageUpsamplingMethod.InnerText = "Bicubic";
                }
                else if (img.UpsamplingMode == MapWinGIS.tkInterpolationMode.imBilinear)
                {
                    ImageUpsamplingMethod.InnerText = "Bilinear";
                }
                else if (img.UpsamplingMode == MapWinGIS.tkInterpolationMode.imHighQualityBicubic)
                {
                    ImageUpsamplingMethod.InnerText = "HighQualityBicubic";
                }
                else if (img.UpsamplingMode == MapWinGIS.tkInterpolationMode.imHighQualityBilinear)
                {
                    ImageUpsamplingMethod.InnerText = "HighQualityBilinear";
                }
                else if (img.UpsamplingMode == MapWinGIS.tkInterpolationMode.imNone)
                {
                    ImageUpsamplingMethod.InnerText = "None";
                }
                else
                {
                    ImageUpsamplingMethod.InnerText = "None";
                }

                mainScheme = doc.CreateElement("GridColoringScheme");
                mainScheme.Attributes.Append(AmbientIntensity);
                mainScheme.Attributes.Append(Key);
                mainScheme.Attributes.Append(LightSourceAzimuth);
                mainScheme.Attributes.Append(LightSourceElevation);
                mainScheme.Attributes.Append(LightSourceIntensity);
                mainScheme.Attributes.Append(NoDataColor);
                mainScheme.Attributes.Append(ImageLayerFillTransparency);
                mainScheme.Attributes.Append(ImageUpsamplingMethod);
                mainScheme.Attributes.Append(ImageDownsamplingMethod);

                root.AppendChild(mainScheme);
                root.Attributes.Append(GridName);
                root.Attributes.Append(GroupName);
                doc.AppendChild(root);
                if (ExportScheme(((MapWinGIS.GridColorScheme)lyr.ColoringScheme), doc, mainScheme))
                {
                    doc.Save(path);
                    return(true);
                }
                else
                {
                    MapWinGIS.Utility.Logger.Message("导出 coloring scheme 失败.", "错误");
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 从mwsr中取得每个shape的颜色设置,并应用到图层中
        /// </summary>
        private void LoadShpFileColoringScheme(XmlElement legend, int handle)
        {
            MapWinGIS.ShapefileColorScheme shpscheme = new MapWinGIS.ShapefileColorScheme();
            int numOfBreaks;

            MapWinGIS.ShapefileColorBreak _break;
            int i;

            try
            {
                //设置ShapefileColorScheme
                shpscheme.FieldIndex  = int.Parse(legend.Attributes["FieldIndex"].InnerText);
                shpscheme.LayerHandle = handle;
                shpscheme.Key         = legend.Attributes["Key"].InnerText;

                try
                {
                    Program.frmMain.Legend.Layers.ItemByHandle(handle).ColorSchemeFieldCaption = legend.Attributes["SchemeCaption"].InnerText;
                }
                catch
                {
                }

                //设置所有的breaks
                numOfBreaks = legend["ColorBreaks"].ChildNodes.Count;
                for (i = 0; i < numOfBreaks; i++)
                {
                    object with_1 = legend["ColorBreaks"].ChildNodes[i];
                    _break            = new MapWinGIS.ShapefileColorBreak();
                    _break.Caption    = legend["ColorBreaks"].ChildNodes[i].Attributes["Caption"].InnerText;
                    _break.StartColor = System.Convert.ToUInt32(legend["ColorBreaks"].ChildNodes[i].Attributes["StartColor"].InnerText);
                    _break.EndColor   = System.Convert.ToUInt32(legend["ColorBreaks"].ChildNodes[i].Attributes["EndColor"].InnerText);
                    if (legend["ColorBreaks"].ChildNodes[i].Attributes["StartValue"].InnerText == "(null)")
                    {
                        _break.StartValue = null;
                    }
                    else
                    {
                        _break.StartValue = legend["ColorBreaks"].ChildNodes[i].Attributes["StartValue"].InnerText;
                    }

                    if (legend["ColorBreaks"].ChildNodes[i].Attributes["EndValue"].InnerText == "(null)")
                    {
                        _break.EndValue = null;
                    }
                    else
                    {
                        _break.EndValue = legend["ColorBreaks"].ChildNodes[i].Attributes["EndValue"].InnerText;
                    }

                    if (legend["ColorBreaks"].ChildNodes[i].Attributes["Visible"] != null && legend["ColorBreaks"].ChildNodes[i].Attributes["Visible"].InnerText != "")
                    {
                        _break.Visible = bool.Parse(legend["ColorBreaks"].ChildNodes[i].Attributes["Visible"].InnerText);
                    }

                    shpscheme.Add(_break);
                }

                if (numOfBreaks > 0)
                {
                    //set that layers scheme and redraw the legend
                    //设置Layer的颜色设置,并重回legend
                    Program.frmMain.Layers[handle].ColoringScheme = shpscheme;
                    Program.frmMain.Legend.Refresh();
                }
            }
            catch (System.Exception e)
            {
                m_ErrorMsg    += "在LoadShpFileColoringScheme()方法中出错:" + e.Message + "\r\n";
                m_ErrorOccured = true;
            }
        }