コード例 #1
0
        private static bool ExportScheme(MapWinGIS.GridColorScheme Scheme, XmlDocument RootDoc, XmlElement Parent)
        {
            int          i;
            XmlElement   brk;
            XmlAttribute caption;
            XmlAttribute sValue;
            XmlAttribute eValue;
            XmlAttribute sColor;
            XmlAttribute eColor;
            XmlAttribute coloringType;
            XmlAttribute gradientModel;

            MapWinGIS.GridColorBreak curBrk;

            if (Scheme == null || Scheme.NumBreaks == 0)
            {
                return(false);
            }

            for (i = 0; i <= Scheme.NumBreaks - 1; i++)
            {
                curBrk                  = Scheme.Break[i];
                brk                     = RootDoc.CreateElement("Break");
                caption                 = RootDoc.CreateAttribute("Caption");
                sValue                  = RootDoc.CreateAttribute("LowValue");
                eValue                  = RootDoc.CreateAttribute("HighValue");
                sColor                  = RootDoc.CreateAttribute("LowColor");
                eColor                  = RootDoc.CreateAttribute("HighColor");
                coloringType            = RootDoc.CreateAttribute("ColoringType");
                gradientModel           = RootDoc.CreateAttribute("GradientModel");
                caption.InnerText       = curBrk.Caption;
                sValue.InnerText        = (curBrk.LowValue).ToString();
                eValue.InnerText        = (curBrk.HighValue).ToString();
                sColor.InnerText        = (ColorScheme.UIntToColor(curBrk.LowColor).ToArgb()).ToString();
                eColor.InnerText        = (ColorScheme.UIntToColor(curBrk.HighColor).ToArgb()).ToString();
                coloringType.InnerText  = (curBrk.ColoringType).ToString();
                gradientModel.InnerText = (curBrk.GradientModel).ToString();
                brk.Attributes.Append(caption);
                brk.Attributes.Append(sValue);
                brk.Attributes.Append(eValue);
                brk.Attributes.Append(sColor);
                brk.Attributes.Append(eColor);
                brk.Attributes.Append(coloringType);
                brk.Attributes.Append(gradientModel);
                Parent.AppendChild(brk);
                curBrk = null;
            }
            return(true);
        }
コード例 #2
0
        public static bool ImportScheme(MapWinGIS.GridColorScheme sch, XmlElement e)
        {
            int i;

            MapWinGIS.GridColorBreak brk;
            string  t;
            double  azimuth;
            double  elevation;
            XmlNode n;

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

            sch.Key = e.Attributes["Key"].InnerText;

            t = e.Attributes["AmbientIntensity"].InnerText;
            sch.AmbientIntensity = MapWinGIS.Utility.MiscUtils.ParseDouble(t, 0.7);

            t       = e.Attributes["LightSourceAzimuth"].InnerText;
            azimuth = MapWinGIS.Utility.MiscUtils.ParseDouble(t, 90.0);

            t         = e.Attributes["LightSourceElevation"].InnerText;
            elevation = MapWinGIS.Utility.MiscUtils.ParseDouble(t, 45.0);
            sch.SetLightSource(azimuth, elevation);

            t = e.Attributes["LightSourceIntensity"].InnerText;
            sch.LightSourceIntensity = MapWinGIS.Utility.MiscUtils.ParseDouble(t, 0.7);

            for (i = 0; i <= e.ChildNodes.Count - 1; i++)
            {
                n                 = e.ChildNodes[i];
                brk               = new MapWinGIS.GridColorBreak();
                brk.Caption       = n.Attributes["Caption"].InnerText;
                brk.LowColor      = ColorScheme.ColorToUInt(Color.FromArgb(System.Convert.ToInt32(n.Attributes["LowColor"].InnerText)));
                brk.HighColor     = ColorScheme.ColorToUInt(Color.FromArgb(System.Convert.ToInt32(n.Attributes["HighColor"].InnerText)));
                brk.LowValue      = MapWinGIS.Utility.MiscUtils.ParseDouble(n.Attributes["LowValue"].InnerText, 0.0);
                brk.HighValue     = MapWinGIS.Utility.MiscUtils.ParseDouble(n.Attributes["HighValue"].InnerText, 0.0);
                brk.ColoringType  = (MapWinGIS.ColoringType)Enum.Parse(typeof(MapWinGIS.ColoringType), n.Attributes["ColoringType"].InnerText);
                brk.GradientModel = (MapWinGIS.GradientModel)Enum.Parse(typeof(MapWinGIS.GradientModel), n.Attributes["GradientModel"].InnerText);
                sch.InsertBreak(brk);
            }
            return(true);
        }
コード例 #3
0
        /// <summary>
        /// adds the new grid as a new layer to the map
        /// </summary>
        private void DisplayGrid(string grFileName)
        {
            MapWindow.Interfaces.Layer newLayer;
            MapWinGIS.GridColorScheme  cS = new MapWinGIS.GridColorScheme();

            try
            {
                newLayer = m_MapWin.Layers.Add(grFileName);
                MapWinGIS.Grid gr = newLayer.GetGridObject;
                cS = (MapWinGIS.GridColorScheme)newLayer.ColoringScheme;
                int i;
                for (i = 0; i < cS.NumBreaks; ++i)
                {
                    cS.get_Break(i).ColoringType = MapWinGIS.ColoringType.Gradient;
                }

                m_MapWin.Layers.RebuildGridLayer(newLayer.Handle, gr, cS);
            }
            catch (Exception ex)
            {
                MapWinUtility.Logger.Msg("ERROR adding grid to the map. " + ex.Message);
            }
        }
コード例 #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);
        }
コード例 #5
0
        /// <summary>
        /// 从指定文件中导入颜色设置
        /// </summary>
        public static object ImportScheme(Interfaces.Layer lyr, string Filename)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement  root;

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

            doc.Load(Filename);
            root = doc.DocumentElement;

            if (lyr.LayerType == Interfaces.eLayerType.LineShapefile || lyr.LayerType == Interfaces.eLayerType.PointShapefile || lyr.LayerType == Interfaces.eLayerType.PolygonShapefile)
            {
                try
                {
                    MapWinGIS.ShapefileColorScheme sch = new ShapefileColorScheme();
                    if (root.Attributes["SchemeType"].InnerText == "Shapefile")
                    {
                        if (ImportScheme(sch, (MapWinGIS.Shapefile)lyr.GetObject(), root["ShapefileColoringScheme"]))
                        {
                            return(sch);
                        }
                    }
                    else
                    {
                        MapWinGIS.Utility.Logger.Message("文件中包含无效的颜色设置.");
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    Program.g_error = ex.Message;
                    return(null);
                }
            }
            else //不是shapefile类型文件
            {
                try
                {
                    MapWinGIS.GridColorScheme sch = new MapWinGIS.GridColorScheme();
                    if (root.Attributes["SchemeType"].InnerText == "Grid")
                    {
                        try
                        {
                            if (root.Attributes["GridName"] != null)
                            {
                                lyr.Name = root.Attributes["GridName"].InnerText;
                            }
                            if (root.Attributes["GroupName"] != null)
                            {
                                string GroupName = root.Attributes["GroupName"].InnerText;
                                bool   found     = false; //是否在legend中找到Group匹配的名字
                                for (int i = 0; i < Program.frmMain.Legend.Groups.Count; i++)
                                {
                                    if (Program.frmMain.Legend.Groups[i].Text.ToLower().Trim() == GroupName.Trim().ToLower())
                                    {
                                        lyr.GroupHandle = Program.frmMain.Legend.Groups[i].Handle;
                                        found           = true;
                                        break;
                                    }
                                }

                                if (!found)
                                {
                                    lyr.GroupHandle = Program.frmMain.Legend.Groups.Add(GroupName);
                                }
                            }
                        }
                        catch { }
                        if (ImportScheme(sch, root["GridColoringScheme"]))
                        {
                            return(sch);
                        }
                    }
                    else //没有GridColorScheme设置
                    {
                        MapWinGIS.Utility.Logger.Message("文件中包含无效的颜色设置.");
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    Program.g_error = ex.ToString();
                    return(null);
                }
            }
            return(null);
        }
コード例 #6
0
        private void AddLayer()
        {
            MapWinGIS.Shapefile shpfileOpen;
            string[] fileNombres;

            MapWinGIS.Grid grid;
            MapWinGIS.GridColorScheme gridScheme;
            MapWinGIS.Image image;
            MapWinGIS.Utils utils;

            OpenFileDialog openDlg = new OpenFileDialog();
            openDlg.Multiselect = true;

            int handle;
            string ext;

            //initialize dialog
            openDlg.Filter = "Supported Formats|*.shp;*.bgd;*asc;*.jpg|Shapefile (*.shp)|*.shp|Binary Grids (*.bgd)|*.bgd|ASCII Grids (*.asc)|*.asc |World File (*.jpg)|*.jpg";
            openDlg.CheckFileExists = true;

            if (openDlg.ShowDialog(this) == DialogResult.OK)
            {
                fileNombres = openDlg.FileNames;
                int totalNombres = fileNombres.Length;
                for (int j = 0; j < totalNombres; j++)
                {

                    //get the extension of the file
                    ext = System.IO.Path.GetExtension(openDlg.FileNames[j]);

                    if (ext == ".bgd" || ext == ".asc" || ext == ".jpg")
                    {
                        if (ext == ".jpg")
                        {
                            image = new MapWinGIS.Image();

                            // open image world file
                            image.Open(openDlg.FileNames[j], MapWinGIS.ImageType.JPEG_FILE, true, null);
                            handle = legend1.Layers.Add(image, true);
                            legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(image.Filename));
                            //handle = axMap1.AddLayer(image, true);
                            handleMap.Add(handle);

                        }
                        else
                        {

                            utils = new MapWinGIS.UtilsClass();
                            gridScheme = new MapWinGIS.GridColorScheme();
                            grid = new MapWinGIS.GridClass();

                            //open the grid
                            grid.Open(openDlg.FileName, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null);

                            //create a coloring scheme for the image
                            gridScheme.UsePredefined(System.Convert.ToDouble(grid.Minimum), System.Convert.ToDouble(grid.Maximum), MapWinGIS.PredefinedColorScheme.SummerMountains);

                            //convert the grid to a image
                            image = utils.GridToImage(grid, gridScheme, null);

                            //add the image to the legend and map
                            handle = axMap1.AddLayer(image, true);
                            handleMap.Add(handle);

                            grid.Close();

                            //utils = new MapWinGIS.UtilsClass();
                            //gridScheme = new MapWinGIS.GridColorScheme();
                            //grid = new MapWinGIS.GridClass();

                            ////open the grid
                            //grid.Open(openDlg.FileName, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null);

                            ////create a coloring scheme for the image
                            //gridScheme.UsePredefined(System.Convert.ToDouble(grid.Minimum), System.Convert.ToDouble(grid.Maximum), MapWinGIS.PredefinedColorScheme.SummerMountains);

                            ////convert the grid to a image
                            //image = utils.GridToImage(grid, gridScheme, null);

                            ////add the image to the legend and map
                            //handle = axMap1.AddLayer(image, true);
                            ////handle = legend1.Layers.Add(image, true);

                            //if (legend1.Layers.IsValidHandle(handle))
                            //{
                            //    //set the layer name
                            //    legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(grid.Filename));

                            //    //set's the legend layer type, this displays a default icon in the legend (line shapefile, point shapefile,polygon shapefile,grid,image)
                            //    legend1.Layers.ItemByHandle(handle).Type = MapWindow.Interfaces.eLayerType.Grid;

                            //    //set coloring scheme
                            //    //when applying a coloring scheme to a shapfile use axMap1.ApplyLegendColors(ShapefileColorScheme)
                            //    //when applying a coloring scheme for a grid or image use axMap1.SetImageLayerColorScheme(handle,GridColorScheme);
                            //    axMap1.SetImageLayerColorScheme(legend1.SelectedLayer, gridScheme);
                            //    legend1.Layers.ItemByHandle(legend1.SelectedLayer).Refresh();
                            //}

                            //close the grid
                            //grid.Close();
                        }

                    }
                    else if (ext == ".shp")
                    {
                        shpfileOpen = new MapWinGIS.ShapefileClass();

                        //open the shapefile
                        shpfileOpen.Open(openDlg.FileNames[j], null);

                        //add the shapefile to the map and legend
                        handle = legend1.Layers.Add(shpfileOpen, true);
                        legend1.Map.set_LayerName(handle, System.IO.Path.GetFileNameWithoutExtension(shpfileOpen.Filename));
                        //handle = axMap1.AddLayer(shpfileOpen, true);
                        handleMap.Add(handle);
                        string oldProj = shpfileOpen.Projection;

                        // bool status = MapWinGeoProc.SpatialReference.ProjectShapefile(sourceProj, destProj, inputSF, resultSF)
                        this.flagMapaAbierto = true;

                    }
                }

            }
        }
コード例 #7
0
ファイル: ShapeGridInfo.cs プロジェクト: qlands/GOBLET
        /// <summary>
        /// adds the new grid as a new layer to the map
        /// </summary>
        private void DisplayGrid(string grFileName)
        {
            MapWindow.Interfaces.Layer newLayer;
            MapWinGIS.GridColorScheme cS = new MapWinGIS.GridColorScheme();

            try
            {
                newLayer = m_MapWin.Layers.Add(grFileName);
                MapWinGIS.Grid gr = newLayer.GetGridObject;
                cS = (MapWinGIS.GridColorScheme)newLayer.ColoringScheme;
                int i;
                for (i = 0; i < cS.NumBreaks; ++i)
                {
                    cS.get_Break(i).ColoringType = MapWinGIS.ColoringType.Gradient;
                }

                m_MapWin.Layers.RebuildGridLayer(newLayer.Handle, gr, cS);
            }
            catch (Exception ex)
            {
                MapWinUtility.Logger.Msg("ERROR adding grid to the map. " + ex.Message);
            }
        }