Пример #1
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);
        }
Пример #2
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);
        }