Exemple #1
0
 /// <summary>
 /// 在所有的层上清空所有选择的shapes
 /// </summary>
 public void ClearSelectedShapes()
 {
     for (int i = 0; i < Program.frmMain.Layers.NumLayers; i++)
     {
         Interfaces.Layer layer = Program.frmMain.Layers[Program.frmMain.Layers.GetHandle(i)];
         if (layer != null)
         {
             layer.ClearSelection();
         }
     }
 }
        /// <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);
        }
        /// <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);
        }
 /// <summary>
 /// 未实现
 /// </summary>
 private void AddGridElement(XmlDocument m_Doc, Interfaces.Layer gridFileLayer, XmlNode parent)
 {
 }
 /// <summary>
 /// 未实现
 /// </summary>
 private void AddShapeFileElement(XmlDocument m_Doc, Interfaces.Layer sfl, XmlNode parent)
 {
 }
Exemple #6
0
        /// <summary>
        /// 清空所有已选择的shape的列表
        /// </summary>
        public void ClearSelectedShapes()
        {
            if (Program.frmMain.MapMain.ShapeDrawingMethod != MapWinGIS.tkShapeDrawingMethod.dmNewSymbology)
            {
                bool isLocked = false;
                try
                {
                    MainProgram.SelectedShape oneShp;
                    int i;
                    int tLyrHandle;

                    tLyrHandle = m_LayerHandle;

                    if (Program.frmMain.MapMain == null)
                    {
                        for (i = m_NumSelected - 1; i >= 0; i--)
                        {
                            m_Shapes[i] = null;
                        }
                        m_Shapes       = null;
                        m_SelectBounds = null;
                        return;
                    }

                    if (Program.frmMain.MapMain.IsLocked == MapWinGIS.tkLockMode.lmUnlock)
                    {
                        Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmLock);
                        isLocked = true;
                    }

                    for (i = m_NumSelected - 1; i >= 0; i--)
                    {
                        oneShp = m_Shapes[i];
                        if (oneShp != null)
                        {
                            Program.frmMain.MapMain.set_ShapePointColor(tLyrHandle, oneShp.ShapeIndex, oneShp.OriginalColor);
                            Program.frmMain.MapMain.set_ShapeLineColor(tLyrHandle, oneShp.ShapeIndex, oneShp.OriginalOutlineColor);
                            Program.frmMain.MapMain.set_ShapeFillColor(tLyrHandle, oneShp.ShapeIndex, oneShp.OriginalColor);
                            Program.frmMain.MapMain.set_ShapeDrawFill(tLyrHandle, oneShp.ShapeIndex, oneShp.OriginalDrawFill);

                            if (Program.projInfo.TransparentSelection)
                            {
                                Program.frmMain.MapMain.set_ShapeFillTransparency(tLyrHandle, oneShp.ShapeIndex, oneShp.OriginalTransparency);
                            }
                        }

                        m_NumSelected--;
                        oneShp = null;

                        m_Shapes[i] = null;
                    }

                    m_Shapes       = null;
                    m_SelectBounds = null;
                    Program.frmMain.UpdateButtons();
                    m_LayerHandle = -1;
                }
                catch (Exception ex)
                {
                    Program.g_error = ex.Message;
                    Program.ShowError(ex);
                }
                if (isLocked)
                {
                    Program.frmMain.MapMain.LockWindow(MapWinGIS.tkLockMode.lmUnlock);
                }
            }
            else //不是dmNewSymbology绘制方式
            {
                int handle;
                for (int i = 0; i < Program.frmMain.Layers.NumLayers; i++)
                {
                    handle = Program.frmMain.MapMain.get_LayerHandle(i);
                    MapWinGIS.Shapefile sf;
                    Interfaces.Layer    layer = Program.frmMain.Layers[handle];
                    if (layer != null)
                    {
                        if (layer.LayerType == Interfaces.eLayerType.LineShapefile || layer.LayerType == Interfaces.eLayerType.PointShapefile || layer.LayerType == Interfaces.eLayerType.PolygonShapefile)
                        {
                            sf = (MapWinGIS.Shapefile)layer.GetObject();
                            if (sf != null)
                            {
                                sf.SelectNone();
                            }
                        }
                    }
                }

                m_Shapes      = null;
                m_LayerHandle = -1;
                m_NumSelected = 0;
                Program.frmMain.UpdateButtons();
                Program.frmMain.MapMain.Redraw();
            }
        }
Exemple #7
0
 /// <summary>
 /// 未实现
 /// </summary>
 public XmlElement Layer2XML(Interfaces.Layer Layer, XmlDocument xmlDoc, string FileName)
 {
     return(null);
 }
Exemple #8
0
        /// <summary>
        /// 在指定的层上更新选择的shapes
        /// 别的层上的选择将保持
        /// </summary>
        /// <param name="sf">要更新的Shapefile</param>
        /// <param name="shpIndices">所有相关的Shape的索引集合</param>
        /// <param name="mode">选择操作</param>
        /// <returns></returns>
        public MapWinGIS.Interfaces.SelectInfo UpdateSelection(int layerHandle, ref int[] shpIndices, Interfaces.SelectionOperation mode)
        {
            //清空原来存储的
            m_selection = null;

            Interfaces.Layer layer = Program.frmMain.m_Layers[layerHandle];
            if (layer == null)
            {
                return(null);
            }
            MapWinGIS.Shapefile sf = layer.GetObject() as MapWinGIS.Shapefile;
            if (sf == null)
            {
                return(null);
            }

            if (mode == Interfaces.SelectionOperation.SelectNew)
            {
                sf.SelectNone();
            }

            if (shpIndices != null && shpIndices.Length > 0)
            {
                int i;
                int shpIndicesLen = shpIndices.Length;
                if (mode == Interfaces.SelectionOperation.SelectNew)
                {
                    for (i = 0; i < shpIndicesLen; i++)
                    {
                        sf.ShapeSelected[shpIndices[i]] = true;
                    }
                }
                else if (mode == Interfaces.SelectionOperation.SelectAdd)
                {
                    for (i = 0; i < shpIndicesLen; i++)
                    {
                        sf.ShapeSelected[shpIndices[i]] = true;
                    }
                }
                else if (mode == Interfaces.SelectionOperation.SelectExclude)
                {
                    for (i = 0; i < shpIndicesLen; i++)
                    {
                        sf.ShapeSelected[shpIndices[i]] = false;
                    }
                }
                else if (mode == Interfaces.SelectionOperation.SelectInvert)
                {
                    for (i = 0; i < shpIndicesLen; i++)
                    {
                        sf.ShapeSelected[shpIndices[i]] = !sf.ShapeSelected[shpIndices[i]];
                    }
                }
            }

            Program.frmMain.UpdateButtons();

            bool handled = false;

            Program.frmMain.FireLayerSelectionChanged(layerHandle, ref handled);

            return(layer.SelectedShapes);
        }