Exemplo n.º 1
0
 private void initMap123(IMapLayers pMapLayer, DevComponents.AdvTree.Node advN)
 {
     if (!advN.HasChildNodes && advN.Checked)
     {
         string tag = advN.Tag as string;
         if (tag == "Layer")
         {
             //获取xml节点
             if (advN.DataKey != null)
             {
                 XmlNode layerNode = advN.DataKey as XmlNode;
                 string  nodeKey   = "";
                 if ((layerNode as XmlElement).HasAttribute("NodeKey"))
                 {
                     nodeKey = layerNode.Attributes["NodeKey"].Value;
                 }
                 ILayer addLayer = ModGetData.GetLayerByNodeKey(pAxMapControl.Map, nodeKey);
                 pMapLayer.InsertLayer(addLayer, false, pMapLayer.LayerCount);
             }
         }
         else if (tag == "OutLayer")
         {
         }
         return;
     }
     else if (advN.HasChildNodes)
     {
         foreach (DevComponents.AdvTree.Node avN in advN.Nodes)
         {
             initMap(pMapLayer, avN);
         }
     }
 }
Exemplo n.º 2
0
        public static bool InsertShapeLayer(Boolean IsEqual, ILayer pFlayer)//插入矢量图
        {
            int count = MainFrom.m_mapControl.LayerCount;

            if (count == 0)
            {
                MainFrom.groupLayer.Add(pFlayer);
                MainFrom.m_mapControl.AddLayer(MainFrom.groupLayer);
            }
            else
            {
                for (int m = count - 1; m >= 0; m--)
                {
                    IMapLayers pLayers = MainFrom.m_mapControl.Map as IMapLayers;
                    ILayer     pGL     = MainFrom.m_mapControl.get_Layer(m);
                    if (pGL.Name == MainFrom.groupLayer.Name)
                    {
                        IsEqual = true;
                        if (pGL is IGroupLayer)
                        {
                            pLayers.InsertLayerInGroup((IGroupLayer)pGL, pFlayer, false, 0);
                        }
                    }
                }
                if (!IsEqual)
                {
                    MainFrom.groupLayer.Add(pFlayer);
                    MainFrom.m_mapControl.AddLayer(MainFrom.groupLayer);
                }
            }
            return(IsEqual);
        }
Exemplo n.º 3
0
        private void bindCboxTable(ComboBox comb, int LayerNO)
        {
            IMapLayers    mapLayers = Program.myMap.Map as IMapLayers;
            IFeatureLayer pFeatureLayer;
            ILayer        layer;

            //IList<Info> infoList = new List<Info>();


            layer = mapLayers.get_Layer(LayerNO);

            pFeatureLayer = layer as IFeatureLayer;


            //ITable table = pFeatureLayer.FeatureClass as ITable;
            int           num     = pFeatureLayer.FeatureClass.Fields.FieldCount;
            List <string> lstName = new List <string>();

            for (int j = 0; j < num; j++)
            {
                string name = pFeatureLayer.FeatureClass.Fields.get_Field(j).Name;
                lstName.Add(name);
            }

            //Info infoLayer = new Info() { CBId = i.ToString(), CBName = layer.Name };
            //infoList.Add(infoLayer);
            //i++;


            comb.DataSource = lstName;
            //comb.ValueMember = "CBId";
            //comb.DisplayMember = "CBName";
        }
        /// <summary>
        /// Handles the click event of the Button and starts asynchronous geoprocessing.
        /// </summary>
        private void btnRunGP_Click(object sender, EventArgs e)
        {
            try
            {
                #region tidy up any previous gp runs

                //Clear the ListView control
                listView1.Items.Clear();

                //Remove any result layers present in the map
                IMapLayers mapLayers = axMapControl1.Map as IMapLayers;
                foreach (IFeatureLayer resultLayer in _resultsList)
                {
                    mapLayers.DeleteLayer(resultLayer);
                }

                axTOCControl1.Update();

                //Empty the results layer list
                _resultsList.Clear();

                //make sure that my GP tool queue is empty
                _myGPToolsToExecute.Clear();

                #endregion

                //Buffer the selected cities by the specified distance
                ESRI.ArcGIS.AnalysisTools.Buffer bufferTool = new ESRI.ArcGIS.AnalysisTools.Buffer();
                bufferTool.in_features = _layersDict["Cities"];
                bufferTool.buffer_distance_or_field = txtBufferDistance.Text + " Miles";
                bufferTool.out_feature_class        = "city_buffer.shp";

                //Clip the zip codes layer with the result of the buffer tool
                ESRI.ArcGIS.AnalysisTools.Clip clipTool = new ESRI.ArcGIS.AnalysisTools.Clip();
                clipTool.in_features       = _layersDict["ZipCodes"];
                clipTool.clip_features     = bufferTool.out_feature_class;
                clipTool.out_feature_class = "city_buffer_clip.shp";

                //To run multiple GP tools asynchronously, all tool inputs must exist before ExecuteAsync is called.
                //The output from the first buffer operation is used as an input to the second clip
                //operation. To deal with this restriction a Queue is created and all tools added to it. The first tool
                //is executed from this method, whereas the second is executed from the ToolExecuted event. This approach
                //is scalable - any additional geoprocessing tools added to this queue will also be executed in turn.
                _myGPToolsToExecute.Enqueue(bufferTool);
                _myGPToolsToExecute.Enqueue(clipTool);
                _gp.ExecuteAsync(_myGPToolsToExecute.Dequeue());
            }
            catch (Exception ex)
            {
                listView1.Items.Add(new ListViewItem(new string[2] {
                    "N/A", ex.Message
                }, "error"));
            }
        }
Exemplo n.º 5
0
 public bool AddDatasetLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, IDataset pDataset)
 {
     try
     {
         if ((pBasicMap == null) & (pParentLayer == null))
         {
             return(false);
         }
         if (pDataset == null)
         {
             return(false);
         }
         Collection pLayersColl = new Collection();
         if (!this.GetLayerFormDataset(pDataset, pLayersColl))
         {
             return(false);
         }
         if (pLayersColl.Count <= 0)
         {
             return(false);
         }
         IMapLayers layers = pBasicMap as IMapLayers;
         foreach (ILayer layer in pLayersColl)
         {
             if (layer != null)
             {
                 if (pParentLayer != null)
                 {
                     pParentLayer.Add(layer);
                 }
                 else
                 {
                     pBasicMap.AddLayer(layer);
                 }
                 if (pParentLayer == null)
                 {
                     layers.MoveLayer(layer, 0);
                 }
                 else if (pBasicMap is IMap)
                 {
                     layers.MoveLayerEx(pParentLayer, pParentLayer, layer, 0);
                 }
             }
         }
         pLayersColl = null;
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddDataLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Exemplo n.º 6
0
        public static ILayer GetLayerBySource(FileSystemInfo fiFullPath)
        {
            //if (!fiFullPath.Exists)
            //    return null;

            IMapLayers mapLayers = (IMapLayers)ArcMap.Document.FocusMap;
            UID        pID       = new UIDClass();

            pID.Value = "{6CA416B1-E160-11D2-9F4E-00C04F6BC78E}"; // eEsriLayerTypes.Esri_DataLayer
            IEnumLayer pEnumLayer = ((IMapLayers)ArcMap.Document.FocusMap).Layers[pID, true];
            ILayer     pLayer     = pEnumLayer.Next();

            while (pLayer != null)
            {
                if (pLayer is IGeoFeatureLayer)
                {
                    IGeoFeatureLayer pGFL  = (IGeoFeatureLayer)pLayer;
                    string           sPath = ((IDataset)pGFL).Workspace.PathName;
                    if (pGFL.FeatureClass.FeatureDataset is IFeatureDataset)
                    {
                        sPath = Path.Combine(sPath, pGFL.FeatureClass.FeatureDataset.Name);
                    }

                    sPath = Path.Combine(sPath, ((IDataset)pGFL.FeatureClass).Name);

                    if (((IDataset)pGFL.FeatureClass).Workspace.Type == esriWorkspaceType.esriFileSystemWorkspace)
                    {
                        sPath = Path.ChangeExtension(sPath, "shp");
                    }

                    string testPath = fiFullPath.FullName.Replace('\\', '/');
                    sPath = sPath.Replace('\\', '/');

                    if (string.Compare(testPath, sPath, true) == 0)
                    {
                        return(pLayer);
                    }
                }
                else if (pLayer is IRasterLayer)
                {
                    if (string.Compare(((IRasterLayer)pLayer).FilePath, fiFullPath.FullName, true) == 0)
                    {
                        return(pLayer);
                    }
                }

                pLayer = pEnumLayer.Next();
            }

            return(null);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Generates the report.
        /// </summary>
        public void GenerateReport()
        {
            this.ReportFileStream = new StreamWriter(this.ReportFilePath, true);

            Console.WriteLine("Report Path=" + this.ReportFilePath);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            FileInfo mxdfileinfo = new FileInfo(this.MXDFilePath);

            try
            {
                IMapDocument mapDocument = new MapDocumentClass();
                mapDocument.Open(this.MXDFilePath, string.Empty);

                for (int m = 0; m < mapDocument.MapCount; m++)
                {
                    IMap map = mapDocument.get_Map(m);

                    IMapLayers mapLayers = (IMapLayers)map;

                    IEnumLayer rootLayers = (IEnumLayer)map.get_Layers(null, false);

                    ILayer rootLayer = null;

                    while ((rootLayer = rootLayers.Next()) != null)
                    {
                        ReadLayer(rootLayer, null);
                    }
                }

                // mapDocument.Save(mapDocument.UsesRelativePaths, false);
                mapDocument.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            this.ReportFileStream.Close();

            Console.WriteLine("Report File Stream Closed: " + this.ReportFilePath);
        }
Exemplo n.º 8
0
 public bool AddGroupLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sLayerName)
 {
     try
     {
         if (sLayerName == null)
         {
             sLayerName = "";
         }
         if (pBasicMap == null)
         {
             return(false);
         }
         if (string.IsNullOrEmpty(sLayerName))
         {
             sLayerName = "新建图层组";
         }
         IGroupLayer pLayer = null;
         pLayer = new GroupLayerClass {
             Name = sLayerName
         };
         if (pParentLayer == null)
         {
             pBasicMap.AddLayer(pLayer);
         }
         else
         {
             pParentLayer.Add(pLayer);
         }
         IMapLayers layers = pBasicMap as IMapLayers;
         if (pParentLayer == null)
         {
             layers.MoveLayer(pLayer, 0);
         }
         else if (pBasicMap is IMap)
         {
             layers.MoveLayerEx(pParentLayer, pParentLayer, pLayer, 0);
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGroupLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Exemplo n.º 9
0
 public bool AddGraphicsLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sLayerName)
 {
     try
     {
         if (sLayerName == null)
         {
             sLayerName = "";
         }
         if (pBasicMap == null)
         {
             return(false);
         }
         if (string.IsNullOrEmpty(sLayerName))
         {
             sLayerName = "<新建图像图层>";
         }
         IGraphicsLayer layer = null;
         if (this.FindGraphicsLayer(pBasicMap, sLayerName) == null)
         {
             layer = new CompositeGraphicsLayerClass();
             ILayer layer2 = null;
             layer2      = layer as ILayer;
             layer2.Name = sLayerName;
             pBasicMap.AddLayer(layer as ILayer);
             IMapLayers layers = pBasicMap as IMapLayers;
             if (pParentLayer == null)
             {
                 layers.MoveLayer(layer2, 0);
             }
             else if (pBasicMap is IMap)
             {
                 layers.MoveLayerEx(pParentLayer, pParentLayer, layer2, 0);
             }
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGraphicsLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Exemplo n.º 10
0
 private void initMap(IMapLayers pMapLayer, DevComponents.AdvTree.Node advN)
 {
     if (!advN.HasChildNodes && advN.Checked)
     {
         string tag = advN.Tag as string;
         if (tag == "Layer")
         {
             //获取xml节点
             if (advN.DataKey != null)
             {
                 XmlNode layerNode = advN.DataKey as XmlNode;
                 string  nodeKey   = "";
                 if ((layerNode as XmlElement).HasAttribute("NodeKey"))
                 {
                     nodeKey = layerNode.Attributes["NodeKey"].Value;
                 }
                 ILayer addLayer = ModGetData.GetLayerByNodeKey(pAxMapControl.Map, nodeKey);
                 pMapLayer.InsertLayer(addLayer, false, pMapLayer.LayerCount);
             }
         }
         else if (tag == "OutLayer")
         {
         }
         return;
     }
     else if (advN.HasChildNodes)
     {
         List <string> lstName = getXZQMC();
         foreach (DevComponents.AdvTree.Node avN in advN.Nodes)
         {
             if (lstName.Contains(avN.Text.Split('_')[0]))
             {
                 ILayer pLyr = getLayer(avN);
                 if (pLyr != null)
                 {
                     pMapLayer.InsertLayer(pLyr, false, pMapLayer.LayerCount);
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
        //由专题类型构造制图页面的地图图层-----多了个专题名称针对DOM
        public static void AddMapOfNoneXZQ(IMap inMap, string inType, string LyrNT, IMap inSourceMap)
        {
            IMapLayers inMapLayers = inMap as IMapLayers;

            if (!File.Exists(LayerXMLpath))
            {
                return;
            }
            XmlDocument cXmlDoc = new XmlDocument();

            cXmlDoc.Load(LayerXMLpath);
            if (cXmlDoc == null)
            {
                return;
            }
            XmlNode xn = cXmlDoc.SelectSingleNode("//DIR[@DIRType='" + inType + "']");

            if (xn == null)
            {
                return;
            }
            inMap.Name = xn.Attributes["NodeText"].Value;//设置地图名称
            IGroupLayer gLayer = new GroupLayerClass();

            gLayer.Name = xn.Attributes["NodeText"].Value;
            XmlNodeList xnl = xn.SelectNodes(".//Layer[@NodeText='" + LyrNT + "']");

            foreach (XmlNode pxn in xnl)
            {
                string nodeKey = pxn.Attributes["NodeKey"].Value;
                ILayer pLayer  = GetLayerByNodeKey(inSourceMap, nodeKey);
                if (pLayer != null)
                {
                    gLayer.Add(pLayer);
                }
            }
            inMapLayers.InsertLayer(gLayer as ILayer, false, inMapLayers.LayerCount);
            cXmlDoc = null;
        }
Exemplo n.º 12
0
        /// <summary>
        /// combobox控件绑定数据
        /// </summary>
        private void bindCboxLayer(ComboBox comb)
        {
            IMapLayers mapLayers = Program.myMap.Map as IMapLayers;
            ILayer     layer;
            //UID uid = new UIDClass();
            IList <Info> infoList = new List <Info>();
            //uid.Value = "{40A9E885-5533-11d0-98BE-00805F7CED21}"; // 代表只获取矢量图层
            //IEnumLayer layers = mapLayers.get_Layers(uid, true);
            //layer=mapLayers.get_Layer();
            //for (int i = 0; i <= 10;i++ )
            int i = 0;

            while (i < mapLayers.LayerCount)
            {
                layer = mapLayers.get_Layer(i);
                Info infoLayer = new Info()
                {
                    CBId = i.ToString(), CBName = layer.Name
                };
                infoList.Add(infoLayer);
                i++;
            }
            comb.DataSource    = infoList;
            comb.ValueMember   = "CBId";
            comb.DisplayMember = "CBName";

            //Info info1 = new Info() { CBId = "1", CBName = "张三" };
            //Info info2 = new Info() { CBId = "2", CBName = "李四" };
            //Info info3 = new Info() { CBId = "3", CBName = "王五" };
            //infoList.Add(info1);
            //infoList.Add(info2);
            //infoList.Add(info3);
            //comboBox1.DataSource = infoList;
            //comboBox1.ValueMember = "Id";
            //comboBox1.DisplayMember = "Name";
        }
Exemplo n.º 13
0
 public bool SetLayerPosition(IBasicMap pBasicMap, ILayer pSourceLayer, ILayer pTargetLayer)
 {
     try
     {
         if (pBasicMap == null)
         {
             return(false);
         }
         if (pSourceLayer == null)
         {
             return(false);
         }
         int         num          = 0;
         IGroupLayer pParentLayer = null;
         num = this.FindLayerPosition(pBasicMap, pSourceLayer, ref pParentLayer);
         if (num == -1)
         {
             return(false);
         }
         int         toIndex = 0;
         IGroupLayer layer2  = null;
         if (pTargetLayer == null)
         {
             toIndex = 0;
             layer2  = null;
         }
         else if (pTargetLayer is IGroupLayer)
         {
             toIndex = 0;
             layer2  = pTargetLayer as IGroupLayer;
         }
         else
         {
             toIndex = this.FindLayerPosition(pBasicMap, pTargetLayer, ref layer2) + 1;
         }
         if (object.Equals(pParentLayer, layer2))
         {
             if (num == toIndex)
             {
                 return(false);
             }
             if (num < toIndex)
             {
                 toIndex--;
             }
         }
         IMapLayers layers = pBasicMap as IMapLayers;
         if ((pParentLayer == null) & (layer2 == null))
         {
             layers.MoveLayer(pSourceLayer, toIndex);
         }
         else if (pBasicMap is IMap)
         {
             layers.MoveLayerEx(pParentLayer, layer2, pSourceLayer, toIndex);
         }
         else
         {
             return(false);
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "SetLayerPosition", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Exemplo n.º 14
0
 public bool AddGxFileLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sFileName)
 {
     try
     {
         if (sFileName == null)
         {
             sFileName = "";
         }
         if (pBasicMap == null)
         {
             return(false);
         }
         if (string.IsNullOrEmpty(sFileName))
         {
             OpenFileDialog dialog = new OpenFileDialog {
                 Filter      = "图层文件 (*.lyr)|*.lyr",
                 Multiselect = false,
                 Title       = "选择输入的图层文件"
             };
             if (dialog.ShowDialog() != DialogResult.OK)
             {
                 return(false);
             }
             sFileName = dialog.FileName;
             dialog    = null;
         }
         if (string.IsNullOrEmpty(sFileName))
         {
             return(false);
         }
         if (!File.Exists(sFileName))
         {
             Interaction.MsgBox("地图图层加载失败,图层文件 " + sFileName + " 不存在。", MsgBoxStyle.Exclamation, "错误警告");
             return(false);
         }
         IMapDocument document = null;
         document = new MapDocumentClass();
         if (!document.get_IsMapDocument(sFileName))
         {
             Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是 MapDocument 文件。", MsgBoxStyle.Exclamation, "失败");
             return(false);
         }
         if (document.get_IsRestricted(sFileName))
         {
             Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件受到限制,无权使用。", MsgBoxStyle.Exclamation, "失败");
             return(false);
         }
         document.Open(sFileName, null);
         ILayer pLayer = null;
         if (document.DocumentType == esriMapDocumentType.esriMapDocumentTypeLyr)
         {
             pLayer = document.get_Layer(0, 0);
             if (pLayer == null)
             {
                 Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n图层文件或数据错误。", MsgBoxStyle.Exclamation, "加载失败");
             }
         }
         else
         {
             Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是地图图层文件。", MsgBoxStyle.Exclamation, "加载失败");
         }
         document.Close();
         document = null;
         if (pLayer == null)
         {
             return(false);
         }
         if (pParentLayer == null)
         {
             pBasicMap.AddLayer(pLayer);
         }
         else
         {
             pParentLayer.Add(pLayer);
         }
         IMapLayers layers = pBasicMap as IMapLayers;
         if (pParentLayer == null)
         {
             layers.MoveLayer(pLayer, 0);
         }
         else if (pBasicMap is IMap)
         {
             layers.MoveLayerEx(pParentLayer, pParentLayer, pLayer, 0);
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGxFileLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// 对mapcontrol上groupLayer内的图层进行排序
        /// </summary>
        /// <param name="groupLayer"></param>
        public static void LayersComposeEx(IMap pMap, IGroupLayer groupLayer)
        {
            //判断参数有效性
            if (pMap == null)
            {
                return;
            }
            if (groupLayer == null)
            {
                return;
            }
            ICompositeLayer comLayer   = groupLayer as ICompositeLayer;
            int             iCount     = comLayer.Count;
            IMapLayers      pMapLayers = pMap as IMapLayers;

            //对Dimension层进行排序 冒泡排序
            for (int iIndex = 0; iIndex < iCount; iIndex++)
            {
                ILayer TempLayeri = comLayer.get_Layer(iIndex) as ILayer;
                for (int jindex = iIndex + 1; jindex < iCount; jindex++)
                {
                    ILayer TempLayerj = comLayer.get_Layer(jindex) as ILayer;
                    if (TempLayeri != null && TempLayerj != null)
                    {
                        //获取图层顺序号
                        string strOrderid_i = GetOrderIDofLayer(TempLayeri);
                        string strOrderid_j = GetOrderIDofLayer(TempLayerj);
                        int    iOrderi      = -1;
                        int    iOrderj      = -1;

                        if (!strOrderid_i.Equals("") && !strOrderid_j.Equals(""))
                        {
                            try
                            {
                                iOrderi = int.Parse(strOrderid_i);
                                iOrderj = int.Parse(strOrderid_j);
                            }
                            catch
                            { }
                        }
                        if (iOrderi > 0 && iOrderj > 0)
                        {
                            if (iOrderi > iOrderj)
                            {
                                groupLayer.Delete(TempLayerj);
                                pMapLayers.InsertLayerInGroup(groupLayer, TempLayerj, false, iIndex);
                                TempLayeri = comLayer.get_Layer(iIndex) as ILayer;
                            }
                        }
                        else
                        {
                            int intDataTypeID_i = GetDataTypeIDofLayer(TempLayeri);
                            int intDataTypeID_j = GetDataTypeIDofLayer(TempLayerj);
                            if (intDataTypeID_i > intDataTypeID_j)
                            {
                                groupLayer.Delete(TempLayerj);
                                pMapLayers.InsertLayerInGroup(groupLayer, TempLayerj, false, iIndex);
                                TempLayeri = comLayer.get_Layer(iIndex) as ILayer;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 16
0
        //区分行政区
        public static void AddMapOfByXZQ(IMap inMap, string inType, string ZTMC, IMap inSourceMap, string inXZQMC)
        {
            IMapLayers inMapLayers = inMap as IMapLayers;

            if (!File.Exists(LayerXMLpath))
            {
                return;
            }
            XmlDocument cXmlDoc = new XmlDocument();

            cXmlDoc.Load(LayerXMLpath);
            if (cXmlDoc == null)
            {
                return;
            }
            string xpath = "";

            if (ZTMC == "")//规划不分年度
            {
                xpath = "//DIR[@DIRType='" + inType + "']";
            }
            else//现状分年度专题
            {
                xpath = "//DIR[@DIRType='" + inType + "' and @NodeText='" + ZTMC + "']";
            }
            XmlNode xn = cXmlDoc.SelectSingleNode(xpath);

            if (xn == null)
            {
                return;
            }
            inMap.Name = xn.Attributes["NodeText"].Value; //设置地图名称
            string xzqmc = getXIAN(inXZQMC);              //从不同级别的行政区获得县名称,以获得数据

            if (xzqmc == null)
            {
                return;
            }
            if (ZTMC != "")//区分现状和规划
            {
                string nxzq = ModGetData.AttrValueByXpath("//SpecialXZQ[@ZTMC='" + ZTMC + "']", "New");
                if (nxzq != "")
                {
                    if (nxzq.Contains(xzqmc))
                    {
                        xzqmc = ModGetData.AttrValueByXpath("//SpecialXZQ[@ZTMC='" + ZTMC + "']", "Old");
                    }

                    if (xzqmc == "")
                    {
                        return;
                    }
                }
            }
            XmlNode xnXZQ = xn.SelectSingleNode(".//DataDIR[contains(@NodeText,'" + xzqmc + "')]");

            if (xnXZQ == null)
            {
                return;
            }
            IGroupLayer gLayer = new GroupLayerClass();

            gLayer.Name = xnXZQ.Attributes["NodeText"].Value;
            XmlNodeList xnl = xnXZQ.SelectNodes(".//Layer");

            foreach (XmlNode pxn in xnl)
            {
                string nodeKey = pxn.Attributes["NodeKey"].Value;
                ILayer pLayer  = GetLayerByNodeKey(inSourceMap, nodeKey);
                if (pLayer != null)
                {
                    gLayer.Add(pLayer);
                }
            }
            if ((gLayer as ICompositeLayer).Count != 0)
            {
                if (!isExistGpLyr(inMap, gLayer.Name))
                {
                    inMapLayers.InsertLayer(gLayer as ILayer, false, inMapLayers.LayerCount);
                }
            }
            cXmlDoc = null;
        }
Exemplo n.º 17
0
        public static void AddToMapVector(FileInfo sSource, string sDisplayName, IGroupLayer pGrpLyr, string displayField, IFeatureRenderer pRenderer, string queryFilter, string labelField, short fTransparency = -1)
        {
            if (string.IsNullOrEmpty(sDisplayName))
            {
                throw new ArgumentNullException("Display Name", "Null or empty display Name");
            }

            IFeatureLayer pResultLayer = IsFeatureLayerInGroupLayer(sSource.FullName, pGrpLyr);


            IFeatureWorkspace pWS = (IFeatureWorkspace)ArcMapUtilities.GetWorkspace(sSource);
            IFeatureClass     pFC = pWS.OpenFeatureClass(Path.GetFileNameWithoutExtension(sSource.FullName));

            pResultLayer = new FeatureLayer();
            pResultLayer.FeatureClass = pFC;
            if (fTransparency >= 0)
            {
                ILayerEffects pLayerEffects = (ILayerEffects)pResultLayer;
                pLayerEffects.Transparency = fTransparency;
            }

            if (!string.IsNullOrEmpty(sDisplayName))
            {
                pResultLayer.Name = sDisplayName;
            }

            IMapLayers pMapLayers = (IMapLayers)ArcMap.Document.FocusMap;

            if (pGrpLyr == null)
            {
                pMapLayers.InsertLayer(pResultLayer, true, 0);
            }
            else
            {
                pMapLayers.InsertLayerInGroup(pGrpLyr, pResultLayer, true, 0);
            }

            if (pRenderer != null)
            {
                ((IGeoFeatureLayer)pResultLayer).Renderer = pRenderer;
            }

            if (!string.IsNullOrEmpty(labelField))
            {
                IGeoFeatureLayer pGFL = pResultLayer as IGeoFeatureLayer;

                // This first attempt seems to set the label field, but doesn't
                // cause the labeling to refresh and take effect
                //IDisplayString displayString = pGFL as IDisplayString;
                //IDisplayExpressionProperties properties = displayString.ExpressionProperties;
                //properties.Expression = string.Format("[{0}]", labelField);

                // This second attempt takes more effort but actually works
                // https://community.esri.com/thread/19005
                IAnnotateLayerPropertiesCollection labelPropsCollection = pGFL.AnnotationProperties;
                labelPropsCollection.Clear();

                //IBasicOverposterLayerProperties pBOLayerProps = new BasicOverposterLayerProperties();
                //pBOLayerProps.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon
                //pBOLayerProps.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape
                //pBOLayerProps.FeatureWeight = esriBasicOverposterWeight.esriNoWeight
                //pBOLayerProps.LabelWeight = esriBasicOverposterWeight.esriLowWeight

                //Dim tSym As ITextSymbol
                //Set tSym = New TextSymbol
                //Dim font As IFontDisp
                //Set font = tSym.font
                //font.Bold = False
                //font.size = 6
                //tSym.font = font

                ILabelEngineLayerProperties aLELayerProps = (ILabelEngineLayerProperties) new LabelEngineLayerProperties();
                aLELayerProps.Expression = string.Format("[{0}]", labelField);

                //Set aLELayerProps.Symbol = tSym
                //Set aLELayerProps.BasicOverposterLayerProperties = pBOLayerProps
                IAnnotateLayerProperties lProps = aLELayerProps as IAnnotateLayerProperties;
                lProps.Class = "Any Name";
                labelPropsCollection.Add(lProps);

                pGFL.DisplayAnnotation = true;
            }

            if (pRenderer is IUniqueValueRenderer)
            {
                // If you didn't use a color ramp that was predefined in a style,
                // you need to use "Custom" here, otherwise use the name of the color ramp you chose.
                ((IGeoFeatureLayer)pResultLayer).DisplayField = displayField;

                // This makes the layer properties symbology tab show the correct interface
                IUID pUID = new UIDClass();
                pUID.Value = "{683C994E-A17B-11D1-8816-080009EC732A}";
                ((IGeoFeatureLayer)pResultLayer).RendererPropertyPageClassID = pUID as UIDClass;
            }

            if (!string.IsNullOrEmpty(queryFilter))
            {
                ((IFeatureLayerDefinition)pResultLayer).DefinitionExpression = queryFilter;
            }

            int refsLeft = 0;

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pFC);
            }while (refsLeft > 0);

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pResultLayer);
            }while (refsLeft > 0);

            ArcMap.Document.UpdateContents();
            ArcMap.Document.ActiveView.Refresh();
            ArcMap.Document.CurrentContentsView.Refresh(null);
        }
Exemplo n.º 18
0
        private void LegendWizard_Load(object sender, EventArgs e)
        {
            if (m_pageLayoutControl.ActiveView.FocusMap == null)
            {
                MessageBox.Show("请先添加地图");
                return;

            }
            #region //点击 添加图例按钮 或在 PageLayoutControl中双击图例时
            if (mapSurroundFrame == null)  //当点击 添加图例按钮 或在 PageLayoutControl中双击图例时 先创建图例 或从地图上获得已经添加的图例;
            {

                //Get the GraphicsContainer
                IGraphicsContainer graphicsContainer = m_pageLayoutControl.GraphicsContainer;
                graphicsContainer.Reset();
                IElementProperties pElementPerties = graphicsContainer.Next() as IElementProperties;
                //Get the MapFrame
                IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap);
                if (mapFrame == null) return;
                while (pElementPerties != null) //从地图中获得已有的图例
                {
                    if (pElementPerties.Type == "Map Surround Frame")
                    {
                        pMapSurrounFrame = pElementPerties as IMapSurroundFrame;
                        if (pMapSurrounFrame.MapSurround.Name == "Legend")
                        {
                            m_legend = pMapSurrounFrame.MapSurround as ILegend;
                            break;
                        }
                    }
                    pElementPerties = (IElementProperties)graphicsContainer.Next();
                }
                if (m_legend == null) //当地图中没有添加图例时 创建新图例
                {
                    //Create a legend
                    UID uID = new UIDClass();
                    uID.Value = "esriCarto.Legend";

                    //Create a MapSurroundFrame from the MapFrame
                    mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

                    if (mapSurroundFrame == null) return;
                    if (mapSurroundFrame.MapSurround == null) return;

                    m_legend = mapSurroundFrame.MapSurround as ILegend;
                }
                else
                {
                    mapSurroundFrame = pMapSurrounFrame;

                }

                UID m_uid = new UIDClass();
                m_uid.Value = "{34C20002-4D3C-11D0-92D8-00805F7C28B0}";
                m_mapLayers = m_mapControl.Map as IMapLayers;
                m_emuLayer = m_mapLayers.get_Layers(m_uid, true);//获取图层
                if (m_emuLayer != null)
                {
                    m_emuLayer.Reset();
                    ILayer m_layer = null;
                    while ((m_layer = m_emuLayer.Next()) != null)
                    {
                        this.listBox1.Items.Add(m_layer.Name);//将图层名添加到图例备选项中
                    }
                }
            }
               #endregion
            else //在双击任意范围打印框中图例时,获得图例,及图层信息;
            {
                if (m_Map == null)
                {
                    MessageBox.Show("请先添加地图!");
                }
                for (int k = 0; k < m_Map.LayerCount; k++)
                {
                    listBox1.Items.Add(m_Map.get_Layer(k).Name.ToString());
                }
                m_legend = mapSurroundFrame .MapSurround as ILegend;
            }
            //以下设置需要用到的变量 及初始化 对话框
            plegendFormat = m_legend.Format as ILegendFormat; //设置图例格式需要用到的

            pTextSymbol = new TextSymbolClass();
            pTextSymbol.Size = 10;
            pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; //初始化图例标签的文本格式

            if (m_legend.Title != null)
                textBox1.Text = m_legend.Title.ToString(); //初始化对话框中的文本框 文本
            else
                textBox1.Text = "Legend";

            this.textBoxWidth.Text = "36";
            this.textBoxHeight.Text = "15";
            IMapSurround mapSurround = m_legend as IMapSurround;
            mapSurroundFrame.MapSurround = mapSurround;
            m_FrameProperties = (IFrameProperties)mapSurroundFrame;
            ISymbolBackground pSymbolBack = m_FrameProperties.Background as ISymbolBackground;
            ISymbolBorder pSymbolBorder = m_FrameProperties.Border as ISymbolBorder;
            ISymbolShadow pSymbolShadow = m_FrameProperties.Shadow as ISymbolShadow;
            if (pSymbolBack !=null )
            this.btnBackGroundColor.BackColor =ColorTranslator.FromOle ( pSymbolBack.FillSymbol.Color.RGB ) ;
            if (pSymbolBorder != null)
            this.btnBolderColor.BackColor = ColorTranslator.FromOle(pSymbolBorder.LineSymbol.Color.RGB);
             if (pSymbolShadow != null)
            this.btnShadowColor.BackColor = ColorTranslator.FromOle(pSymbolShadow.FillSymbol.Color.RGB);
        }
Exemplo n.º 19
0
        public override void OnClick()
        {//XZQLocation
            if (_hook == null) return;
            if (_hook.MainUserControl == null) return;
            DevComponents.AdvTree.AdvTree xzqTree = _hook.XZQTree;
            IGeometry xzqGeo = ModGetData.getExtentByXZQ(xzqTree.SelectedNode);
            if (xzqGeo == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到相应的行政区范围!");
                return;
            }
            try
            {
                Plugin.Application.IAppFormRef pAppFormRef = _AppHk as Plugin.Application.IAppFormRef;
                if (this.WriteLog)
                {
                    Plugin.LogTable.Writelog("出" + this._Caption);
                }
                IMap pMap = null;
                bool isSpecial = ModGetData.IsMapSpecial();
                if (isSpecial)
                {
                    pMap = new MapClass();
                    ModGetData.AddMapOfByXZQ(pMap, "ZTGH", "", _hook.ArcGisMapControl.Map, xzqTree.SelectedNode.Text);
                    if (pMap.LayerCount == 0)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到图层。");
                        return;
                    }
                    ModuleMap.LayersComposeEx(pMap);//图层排序
                }
                else
                {
                    IObjectCopy pOC = new ObjectCopyClass();
                    pMap = pOC.Copy(_hook.ArcGisMapControl.Map) as IMap;//复制地图
                }
                if (pMap.LayerCount == 0)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到图层。");
                    return;

                }
                string xzqdmFD = "";
                //构造晕线和渲染图层
                IFeatureClass xzqFC = ModGetData.getFCByXZQ(xzqTree.SelectedNode, ref xzqdmFD);
                if (xzqFC != null && xzqdmFD != null)
                {
                    ILayer hachureLyr = GeoPageLayoutFn.createHachureLyr(xzqFC, xzqdmFD, xzqTree.SelectedNode.Name);
                    if (hachureLyr != null)
                    {
                        IMapLayers pMapLayers = pMap as IMapLayers;
                        IGroupLayer pGroupLayer = pMap.get_Layer(0) as IGroupLayer;
                        if (pGroupLayer != null)
                        {
                            pMapLayers.InsertLayerInGroup(pGroupLayer, hachureLyr, false, 0);
                        }

                    }
                }



                GeoPageLayout pGL = new GeoPageLayout();
                pGL.WriteLog = WriteLog;//ygc 2012-9-12 是否写日志
                pGL.pageLayoutZTGHTXQT(pMap, xzqGeo, xzqTree.SelectedNode.Text);
                
            }
            catch(Exception ex)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", ex.Message);
            }
        }
Exemplo n.º 20
0
        private void bt_ok_Click(object sender, EventArgs e)
        {
            //判断输入路径是否正确
            #region
            try
            {
                if (!File.Exists(tb_nppinput.Text))
                {
                    MessageBox.Show("生态系统净初级生产力平均值数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_preinput.Text))
                {
                    MessageBox.Show("平均年降水量数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_tminput.Text))
                {
                    MessageBox.Show("平均温度数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_altinput.Text))
                {
                    MessageBox.Show("海拔参数数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("设置路径不合法,请检查!");
                return;
            }
            #endregion
            object sev = null;
            tb_state.Text = "正在处理……";
            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rc      = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            ESRI.ArcGIS.SpatialAnalystTools.Float            tofloat = new ESRI.ArcGIS.SpatialAnalystTools.Float();
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            try
            {
                //输入数据类型转换
                #region
                //npp输入数据转化为浮点型
                string floatfilepath_npp = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_float_npp" + System.IO.Path.GetExtension(tb_biooutput.Text);
                tofloat.in_raster_or_constant = tb_nppinput.Text;
                tofloat.out_raster            = floatfilepath_npp;
                gp.Execute(tofloat, null);

                //pre输入数据转化为浮点型
                string floatfilepath_pre = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_float_pre" + System.IO.Path.GetExtension(tb_biooutput.Text);
                tofloat.in_raster_or_constant = tb_preinput.Text;
                tofloat.out_raster            = floatfilepath_pre;
                gp.Execute(tofloat, null);

                //tm输入数据转化为浮点型
                string floatfilepath_tm = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_float_tm" + System.IO.Path.GetExtension(tb_biooutput.Text);
                tofloat.in_raster_or_constant = tb_tminput.Text;
                tofloat.out_raster            = floatfilepath_tm;
                gp.Execute(tofloat, null);

                //alt输入数据转化为浮点型
                string floatfilepath_alt = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_float_alt" + System.IO.Path.GetExtension(tb_biooutput.Text);
                tofloat.in_raster_or_constant = tb_altinput.Text;
                tofloat.out_raster            = floatfilepath_alt;
                gp.Execute(tofloat, null);
                #endregion


                //输入数据进行归一化处理
                #region
                //npp数据归一化处理
                string npp;
                npp              = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_npp" + System.IO.Path.GetExtension(tb_biooutput.Text);
                rc.expression    = "(\"" + floatfilepath_npp + "\" - " + GetMinPixelValue(floatfilepath_npp).ToString() + ") / (" + (GetMaxPixelValue(floatfilepath_npp) - GetMinPixelValue(floatfilepath_npp)).ToString() + ")";
                rc.output_raster = npp;
                tb_state.Text    = "正在对生态系统净初级生产力平均值进行归一化……";
                gp.Execute(rc, null);
                tb_state.Text = "生态系统净初级生产力平均值归一化处理完成!";

                //pre数据归一化处理
                string pre;
                pre              = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_pre" + System.IO.Path.GetExtension(tb_biooutput.Text);
                rc.expression    = "(\"" + floatfilepath_pre + "\" - " + GetMinPixelValue(floatfilepath_pre).ToString() + ") / (" + (GetMaxPixelValue(floatfilepath_pre) - GetMinPixelValue(floatfilepath_pre)).ToString() + ")";
                rc.output_raster = pre;
                tb_state.Text    = "正在对平均年降水量数据进行归一化……";
                gp.Execute(rc, null);
                tb_state.Text = "平均年降水量数据归一化处理完成!";

                //tm数据归一化处理
                string tm;
                tm               = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_tm" + System.IO.Path.GetExtension(tb_biooutput.Text);
                rc.expression    = "(\"" + floatfilepath_tm + "\" - " + GetMinPixelValue(floatfilepath_tm).ToString() + ") / (" + (GetMaxPixelValue(floatfilepath_tm) - GetMinPixelValue(floatfilepath_tm)).ToString() + ")";
                rc.output_raster = tm;
                tb_state.Text    = "正在对平均温度进行归一化……";
                gp.Execute(rc, null);
                tb_state.Text = "平均温度归一化处理完成!";

                //alt数据归一化处理
                string alt;
                alt              = System.IO.Path.GetDirectoryName(tb_biooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "_alt" + System.IO.Path.GetExtension(tb_biooutput.Text);
                rc.expression    = "(\"" + floatfilepath_alt + "\" - " + GetMinPixelValue(floatfilepath_alt).ToString() + ") / (" + (GetMaxPixelValue(floatfilepath_alt) - GetMinPixelValue(floatfilepath_alt)).ToString() + ")";
                rc.output_raster = alt;
                tb_state.Text    = "正在对海拔参数数据进行归一化……";
                gp.Execute(rc, null);
                tb_state.Text = "海拔参数数据归一化处理完成!";
                #endregion


                //计算生物多样性保护服务能力指数
                rc.expression    = "\"" + npp + "\" * \"" + pre + "\" * \"" + tm + "\" * ( 1 - \"" + alt + "\" )";
                rc.output_raster = tb_biooutput.Text;
                tb_state.Text    = "正在计算计算生物多样性保护服务能力指数……";
                gp.Execute(rc, null);
                tb_state.Text = "计算生物多样性保护服务能力指数计算完成!";


                //删除临时文件
                if (tb_state.Text == "计算生物多样性保护服务能力指数计算完成!")
                {
                    string[] files = Directory.GetFiles(System.IO.Path.GetDirectoryName(tb_biooutput.Text), System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) + "*");
                    foreach (string file in files)
                    {
                        if (System.IO.Path.GetFileNameWithoutExtension(tb_biooutput.Text) != System.IO.Path.GetFileNameWithoutExtension(file))
                        {
                            File.Delete(file);
                        }
                    }
                }



                //将结果加载显示
                #region
                string       mxfile       = System.Environment.CurrentDirectory + "\\Data\\EcoRedLine\\生物多样性生态红线划分.mxd";
                IMapDocument pMapDocument = new MapDocumentClass();
                pMapDocument.Open(mxfile); //打开本地的地图文档,用来操作改mxd文件
                IMap              pMap                   = pMapDocument.get_Map(0);
                IMapLayers        pMapLayer              = pMap as IMapLayers;
                IRasterLayer      pRasterLayer           = new RasterLayerClass();
                IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace  rasterWorkspace        = (IRasterWorkspace)rasterWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(tb_biooutput.Text), 0);
                IRasterDataset    pRasterDataset1        = rasterWorkspace.OpenRasterDataset("Biodiversity.tif"); //打开栅格图的文件名
                pRasterLayer.CreateFromDataset(pRasterDataset1);                                                  //创建
                pRasterLayer = pMapLayer.get_Layer(0) as IRasterLayer;
                pRasterLayer.CreateFromDataset(pRasterDataset1);
                pMapDocument.Save(true, true);//保存更改完路径后的mxd文件

                _PageLayoutControl.LoadMxFile(mxfile);
                _PageLayoutControl.Extent = _PageLayoutControl.FullExtent;
                _PageLayoutControl.ZoomToWholePage();


                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(gp.GetMessages(ref sev), "提示", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 21
0
        private void bt_ok_Click(object sender, EventArgs e)
        {
            //判断输入路径是否正确
            #region
            try
            {
                if (!File.Exists(tb_demnput.Text))
                {
                    MessageBox.Show("平均降水量数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (Convert.ToDouble(tb_highinput.Text) < 0)
                {
                    MessageBox.Show("请输入正确的水位高程值!", "提示", MessageBoxButtons.OK);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("设置路径或水位高程值不合法,请检查!");
                return;
            }
            #endregion



            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rc = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            object sev = null;
            try
            {
                tb_state.Text = "正在处理……";
                //判断输入水位数据的单位
                double waterunit = 0;
                if (cb_waterunits.Text == "米(m)")
                {
                    waterunit = 1;
                }
                else
                {
                    waterunit = 0.001;
                }


                //判断输入缓冲距离及缓冲单位
                double bufferunit = 0;
                if (cb_bufferunits.Text == "米(m)")
                {
                    bufferunit = 1;
                }
                else
                {
                    bufferunit = 1000;
                }
                double[] bufferdistance = { Convert.ToDouble(nud_one.Value) * bufferunit, Convert.ToDouble(nud_two.Value) * bufferunit, Convert.ToDouble(nud_three.Value) * bufferunit, Convert.ToDouble(nud_four.Value) * bufferunit };


                //提取高程高于水位的区域
                tb_state.Text = "正在提取未淹没区域……";
                string flood_high = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_high" + System.IO.Path.GetExtension(tb_flooutput.Text);
                rc.output_raster = flood_high;
                rc.expression    = "Con(\"" + tb_demnput.Text + "\" >= (" + tb_highinput.Text + " * " + waterunit.ToString() + "),\"" + tb_demnput.Text + "\")";
                gp.Execute(rc, null);
                tb_state.Text = "未淹没区域提取完成!";


                //水文分析填洼
                tb_state.Text = "正在进行水文分析计算填洼……";
                ESRI.ArcGIS.SpatialAnalystTools.Fill fill = new ESRI.ArcGIS.SpatialAnalystTools.Fill();
                string fill_input, fill_output;
                fill_input              = flood_high;
                fill_output             = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_fill" + System.IO.Path.GetExtension(tb_flooutput.Text);
                fill.in_surface_raster  = fill_input;
                fill.out_surface_raster = fill_output;
                gp.Execute(fill, null);
                tb_state.Text = "水文分析填洼计算完成!";

                //水文分析计算流向
                tb_state.Text = "正在进行水文分析计算流向……";
                ESRI.ArcGIS.SpatialAnalystTools.FlowDirection flowdirection = new ESRI.ArcGIS.SpatialAnalystTools.FlowDirection();
                string flowdirection_input, flowdirection_output;
                flowdirection_input                     = fill_output;
                flowdirection_output                    = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_FlowDir" + System.IO.Path.GetExtension(tb_flooutput.Text);
                flowdirection.in_surface_raster         = flowdirection_input;
                flowdirection.out_flow_direction_raster = flowdirection_output;
                gp.Execute(flowdirection, null);
                tb_state.Text = "水文分析流向计算完成!";



                //水文分析计算流量
                tb_state.Text = "正在进行水文分析计算流量……";
                ESRI.ArcGIS.SpatialAnalystTools.FlowAccumulation flowaccumulation = new ESRI.ArcGIS.SpatialAnalystTools.FlowAccumulation();
                string flowaccumulation_input, flowaccumulation_output;
                flowaccumulation_input  = flowdirection_output;
                flowaccumulation_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_FlowAcc" + System.IO.Path.GetExtension(tb_flooutput.Text);
                flowaccumulation.in_flow_direction_raster = flowaccumulation_input;
                flowaccumulation.out_accumulation_raster  = flowaccumulation_output;
                gp.Execute(flowaccumulation, null);
                tb_state.Text = "水文分析流量计算完成!";

                //盆域分析
                tb_state.Text = "正在进行水文分析盆域分析……";
                ESRI.ArcGIS.SpatialAnalystTools.Basin basin = new ESRI.ArcGIS.SpatialAnalystTools.Basin();
                string basin_input, basin_output;
                basin_input  = flowdirection_output;
                basin_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_Basin" + System.IO.Path.GetExtension(tb_flooutput.Text);
                basin.in_flow_direction_raster = basin_input;
                basin.out_raster = basin_output;
                gp.Execute(basin, null);
                tb_state.Text = "水文分析盆域分析计算完成!";


                //阈值提取河流
                tb_state.Text = "正在阈值提取河流……";
                string flood_rasterriver = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_river" + System.IO.Path.GetExtension(tb_flooutput.Text);
                rc.expression    = "Con(\"" + flowaccumulation_output + "\" >= 800,1)";
                rc.output_raster = flood_rasterriver;
                gp.Execute(rc, null);
                tb_state.Text = "阈值提取河流计算完成!";

                //水文分析栅格河网矢量化
                tb_state.Text = "正在进行水文分析栅格河网矢量化……";
                ESRI.ArcGIS.SpatialAnalystTools.StreamToFeature streamtofeature = new ESRI.ArcGIS.SpatialAnalystTools.StreamToFeature();
                string streamtofeature_output;
                streamtofeature_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_river.shp";
                streamtofeature.in_flow_direction_raster = flowdirection_output;
                streamtofeature.in_stream_raster         = flood_rasterriver;
                streamtofeature.out_polyline_features    = streamtofeature_output;
                gp.Execute(streamtofeature, null);
                tb_state.Text = "水文分析栅格河网矢量化计算完成!";


                //多环缓冲区
                tb_state.Text = "正在计算多环缓冲区……";
                ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer multipleringbuffer = new ESRI.ArcGIS.AnalysisTools.MultipleRingBuffer();
                string multipleringbuffer_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_multbuffer.shp";
                multipleringbuffer.Input_Features = streamtofeature_output;
                multipleringbuffer.Distances      = bufferdistance[0].ToString() + ";" + bufferdistance[1].ToString() + ";" + bufferdistance[2].ToString() + ";" + bufferdistance[3].ToString() + ";";
                ;
                multipleringbuffer.Buffer_Unit          = "meters";
                multipleringbuffer.Output_Feature_class = multipleringbuffer_output;
                gp.Execute(multipleringbuffer, null);
                tb_state.Text = "多环缓冲区计算完成!";


                //多环缓冲区矢量转栅格
                tb_state.Text = "正在进行多环缓冲区矢量转栅格……";
                ESRI.ArcGIS.ConversionTools.FeatureToRaster featuretoraster = new ESRI.ArcGIS.ConversionTools.FeatureToRaster();
                string featuretoraster_output = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_multbuffer" + System.IO.Path.GetExtension(tb_flooutput.Text);
                featuretoraster.in_features = System.IO.Path.GetDirectoryName(tb_flooutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "_multbuffer.shp";
                featuretoraster.field       = "distance";
                featuretoraster.out_raster  = featuretoraster_output;
                gp.Execute(featuretoraster, null);
                tb_state.Text = "多环缓冲区矢量转栅格计算完成!";


                //删除临时文件
                if (tb_state.Text == "多环缓冲区矢量转栅格计算完成!")
                {
                    string[] files = Directory.GetFiles(System.IO.Path.GetDirectoryName(tb_flooutput.Text), System.IO.Path.GetFileNameWithoutExtension(tb_flooutput.Text) + "*");
                    foreach (string file in files)
                    {
                        if (System.IO.Path.GetFileNameWithoutExtension(file) != System.IO.Path.GetFileNameWithoutExtension(basin_output) && System.IO.Path.GetFileNameWithoutExtension(file) != System.IO.Path.GetFileNameWithoutExtension(featuretoraster_output))
                        {
                            File.Delete(file);
                        }
                    }
                }


                //将结果加载显示
                #region
                string       mxfile       = System.Environment.CurrentDirectory + "\\Data\\EcoRedLine\\洪水淹没生态红线划分.mxd";
                IMapDocument pMapDocument = new MapDocumentClass();
                pMapDocument.Open(mxfile); //打开本地的地图文档,用来操作改mxd文件
                IMap              pMap                   = pMapDocument.get_Map(0);
                IMapLayers        pMapLayer              = pMap as IMapLayers;
                IRasterLayer      pRasterLayer           = new RasterLayerClass();
                IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace  rasterWorkspace        = (IRasterWorkspace)rasterWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(tb_flooutput.Text), 0);

                IRasterDataset pRasterDataset1 = rasterWorkspace.OpenRasterDataset("Flood_multbuffer.tif"); //打开栅格图的文件名
                pRasterLayer.CreateFromDataset(pRasterDataset1);                                            //创建
                pRasterLayer = pMapLayer.get_Layer(0) as IRasterLayer;
                pRasterLayer.CreateFromDataset(pRasterDataset1);

                IRasterLayer   pRasterLayer2   = new RasterLayerClass();
                IRasterDataset pRasterDataset2 = rasterWorkspace.OpenRasterDataset("Flood_Basin.tif"); //打开栅格图的文件名
                pRasterLayer2.CreateFromDataset(pRasterDataset2);                                      //创建
                pRasterLayer2 = pMapLayer.get_Layer(1) as IRasterLayer;
                pRasterLayer2.CreateFromDataset(pRasterDataset2);


                pMapDocument.Save(true, true);//保存更改完路径后的mxd文件

                _PageLayoutControl.LoadMxFile(mxfile);
                _PageLayoutControl.Extent = _PageLayoutControl.FullExtent;
                _PageLayoutControl.ZoomToWholePage();


                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(gp.GetMessages(ref sev), "提示", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 22
0
        private static void AddRasterLayer(Raster gRaster, IRasterRenderer rasterRenderer, string sRasterName, IGroupLayer pGrpLyr, string sHeader = null, short fTransparency = -1, bool ExpandLegend = true)
        {
            if (pGrpLyr != null)
            {
                IRasterLayer pResultLayer = ArcMapUtilities.IsRasterLayerInGroupLayer(gRaster.GISFileInfo, pGrpLyr);
                if (pResultLayer is ILayer)
                {
                    return;
                }
            }

            IRasterLayer   rasterLayer = new RasterLayer();
            IRasterDataset pRDS        = ArcMapUtilities.GetRasterDataset(gRaster);

            rasterLayer.CreateFromDataset(pRDS);
            if (rasterRenderer != null)
            {
                rasterLayer.Renderer = rasterRenderer;
            }

            if (rasterLayer != null)
            {
                IMapLayers pMapLayers = (IMapLayers)ArcMap.Document.FocusMap;
                if (!string.IsNullOrEmpty(sRasterName))
                {
                    rasterLayer.Name = sRasterName;
                }

                if (!string.IsNullOrEmpty(sHeader))
                {
                    ESRI.ArcGIS.Carto.ILegendInfo pLegend = (ESRI.ArcGIS.Carto.ILegendInfo)rasterLayer;
                    pLegend.LegendGroup[0].Heading = sHeader;
                }

                if (fTransparency >= 0)
                {
                    ILayerEffects pLayerEffects = (ILayerEffects)rasterLayer;
                    pLayerEffects.Transparency = fTransparency;
                }

                if (pGrpLyr == null)
                {
                    pMapLayers.InsertLayer(rasterLayer, false, 0);
                }
                else
                {
                    pMapLayers.InsertLayerInGroup(pGrpLyr, rasterLayer, false, 0);
                }

                // Collapse or expand the legend in the ToC (e.g. Hillshade should be collapsed)
                ((ILegendGroup)((ILegendInfo)rasterLayer).LegendGroup[0]).Visible = ExpandLegend;
            }

            int refsLeft = 0;

            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(pRDS);
            }while (refsLeft > 0);

            refsLeft = 0;
            do
            {
                refsLeft = System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterLayer);
            }while (refsLeft > 0);
        }
Exemplo n.º 23
0
        private void bt_ok_Click(object sender, EventArgs e)
        {
            //判断输入路径是否正确
            #region
            try
            {
                if (!File.Exists(tb_raininput.Text))
                {
                    MessageBox.Show("平均降水量数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_suninput.Text))
                {
                    MessageBox.Show("平均日照时长数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_tminput.Text))
                {
                    MessageBox.Show("平均温度数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
                if (!File.Exists(tb_luinput.Text))
                {
                    MessageBox.Show("土地利用类型数据输入路径不正确或文件被占用,请重新输入路径!", "提示", MessageBoxButtons.OK);
                    return;
                }
            }
                     catch (Exception ex)
                
            {
                 
                         MessageBox.Show("设置路径不合法,请检查!");

                return;
            }

            #endregion


            //水源涵养生态红线
            #region
            object sev = null;
            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator rc = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            Geoprocessor gp = new Geoprocessor();
            gp.OverwriteOutput = true;
            try
            {
                //计算地表净辐射量(地表净辐射量=日照时长/20)
                string r;
                r                = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_r" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                rc.expression    = "(\"" + tb_suninput.Text + "\")" + " / 20";
                rc.output_raster = r;
                tb_state.Text    = "正在计算地表净辐射量……";
                gp.Execute(rc, null);
                tb_state.Text = "地表净辐射量计算完成!";



                //计算多年平均潜在蒸发量
                string pet, pet1, pet2, pet3, pet4, pet5;
                pet1             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet1" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet2             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet2" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet3             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet3" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet4             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet4" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet5             = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet5" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                pet              = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_pet" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                tb_state.Text    = "正在计算多年平均潜在蒸发量……";
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 1";
                rc.output_raster = pet1;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 2";
                rc.output_raster = pet2;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 3";
                rc.output_raster = pet3;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 4";
                rc.output_raster = pet4;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 5";
                rc.output_raster = pet5;
                gp.Execute(rc, null);
                rc.expression    = "(\"" + pet1 + "\"* 336.30)" + " + (\"" + pet2 + "\"* 314.70)" + " + (\"" + pet3 + "\"* 384.58)" + " + (\"" + pet4 + "\"* 182.81)" + " + (\"" + pet5 + "\"* 219.87)";
                rc.output_raster = pet;
                gp.Execute(rc, null);
                tb_state.Text = "多年平均潜在蒸发量计算完成!";


                //计算下垫面(土地覆盖)影响系数
                string w, w1, w2, w3, w4, w5;
                w1               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w1" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w2               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w2" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w3               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w3" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w4               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w4" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w5               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w5" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                w                = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_w" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                tb_state.Text    = "正在计算下垫面(土地覆盖)影响系数……";
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 1";
                rc.output_raster = w1;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 2";
                rc.output_raster = w2;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 3";
                rc.output_raster = w3;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 4";
                rc.output_raster = w4;
                gp.Execute(rc, null);
                rc.expression    = "\"" + tb_luinput.Text + "\"" + " == 5";
                rc.output_raster = w5;
                gp.Execute(rc, null);
                rc.expression    = "(\"" + pet1 + "\"* 0.5)" + " + (\"" + pet2 + "\"* 0.1)" + " + (\"" + pet3 + "\"* 1.5)" + " + (\"" + pet4 + "\"* 0.1)" + " + (\"" + pet5 + "\"* 0.5)";
                rc.output_raster = w;
                gp.Execute(rc, null);
                tb_state.Text = "下垫面(土地覆盖)影响系数计算完成!";



                //计算蒸散量(蒸散量=0.489+0.289*表净辐射量+0.023*平均温度)
                string et, et1, et2, et2_t;
                et1              = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_et1" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                et2              = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_et2" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                et2_t            = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_et2_t" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                et               = System.IO.Path.GetDirectoryName(tb_wcoutput.Text) + "\\" + System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "_et" + System.IO.Path.GetExtension(tb_wcoutput.Text);
                tb_state.Text    = "正在计算蒸散量……";
                rc.expression    = "\"" + tb_raininput.Text + "\" + " + "\"" + w + "\" *  \"" + pet + "\"";
                rc.output_raster = et1;
                gp.Execute(rc, null);
                rc.expression    = " 1 + " + "(\"" + w + "\" *  \"" + pet + "\" / (\"" + tb_raininput.Text + "\") + \"" + tb_raininput.Text + "\" / \"" + pet + "\")";
                rc.output_raster = et2_t;
                gp.Execute(rc, null);
                rc.expression    = "Con(\"" + et2_t + "\"" + " != 0 ,\"" + et2_t + "\")";
                rc.output_raster = et2;
                gp.Execute(rc, null);
                rc.expression    = "\"" + et1 + "\" / \"" + et2 + "\"";
                rc.output_raster = et;
                gp.Execute(rc, null);
                tb_state.Text = "蒸散量计算完成!";


                //计算水源涵养量(水源涵养量=多年平均降水量-蒸散量)
                rc.expression    = "\"" + tb_raininput.Text + "\" - \"" + et + "\"";
                rc.output_raster = tb_wcoutput.Text;
                tb_state.Text    = "正在计算水源涵养量……";
                gp.Execute(rc, null);
                tb_state.Text = "水源涵养量计算完成!";


                //删除临时文件
                if (tb_state.Text == "水源涵养量计算完成!")
                {
                    string[] files = Directory.GetFiles(System.IO.Path.GetDirectoryName(tb_wcoutput.Text), System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) + "*");
                    foreach (string file in files)
                    {
                        if (System.IO.Path.GetFileNameWithoutExtension(tb_wcoutput.Text) != System.IO.Path.GetFileNameWithoutExtension(file))
                        {
                            File.Delete(file);
                        }
                    }
                }

                #endregion

                //将结果加载显示
                #region
                string       mxfile       = System.Environment.CurrentDirectory + "\\Data\\EcoRedLine\\水源涵养生态红线划分.mxd";
                IMapDocument pMapDocument = new MapDocumentClass();
                pMapDocument.Open(mxfile); //打开本地的地图文档,用来操作改mxd文件
                IMap              pMap                   = pMapDocument.get_Map(0);
                IMapLayers        pMapLayer              = pMap as IMapLayers;
                IRasterLayer      pRasterLayer           = new RasterLayerClass();
                IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
                IRasterWorkspace  rasterWorkspace        = (IRasterWorkspace)rasterWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(tb_wcoutput.Text), 0);
                IRasterDataset    pRasterDataset1        = rasterWorkspace.OpenRasterDataset("waterConervations.tif"); //打开栅格图的文件名
                pRasterLayer.CreateFromDataset(pRasterDataset1);                                                       //创建
                pRasterLayer = pMapLayer.get_Layer(0) as IRasterLayer;
                pRasterLayer.CreateFromDataset(pRasterDataset1);
                pMapDocument.Save(true, true);//保存更改完路径后的mxd文件

                _PageLayoutControl.LoadMxFile(mxfile);
                _PageLayoutControl.Extent = _PageLayoutControl.FullExtent;
                _PageLayoutControl.ZoomToWholePage();


                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(gp.GetMessages(ref sev), "提示", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 24
0
        public override void OnClick()
        {//XZQLocation
            if (_hook == null)
            {
                return;
            }
            if (_hook.MainUserControl == null)
            {
                return;
            }
            DevComponents.AdvTree.AdvTree xzqTree = _hook.XZQTree;
            IGeometry xzqGeo = ModGetData.getExtentByXZQ(xzqTree.SelectedNode);

            if (xzqGeo == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到相应的行政区范围!");
                return;
            }
            try
            {
                Plugin.Application.IAppFormRef pAppFormRef = _AppHk as Plugin.Application.IAppFormRef;
                FrmSheetMapUserSet_ZTbat       batZT       = new FrmSheetMapUserSet_ZTbat(_AppHk.ArcGisMapControl, pAppFormRef.MainForm, xzqTree.SelectedNode.Text);
                batZT.WriteLog = WriteLog;//ygc 2012-9-12 是否写日志
                if (!(batZT.ShowDialog(pAppFormRef.MainForm) == DialogResult.OK))
                {
                    return;
                }
                if (this.WriteLog)
                {
                    Plugin.LogTable.Writelog("出" + this._Caption);
                }
                IMap pMap = batZT.Map;
                if (pMap.LayerCount == 0)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未找到图层。");
                    return;
                }
                string xzqdmFD = "";
                //构造晕线和渲染图层
                IFeatureClass xzqFC = ModGetData.getFCByXZQ(xzqTree.SelectedNode, ref xzqdmFD);
                if (xzqFC != null && xzqdmFD != null)
                {
                    ILayer hachureLyr = GeoPageLayoutFn.createHachureLyr(xzqFC, xzqdmFD, xzqTree.SelectedNode.Name);
                    if (hachureLyr != null)
                    {
                        IMapLayers  pMapLayers  = pMap as IMapLayers;
                        IGroupLayer pGroupLayer = pMap.get_Layer(0) as IGroupLayer;
                        if (pGroupLayer != null)
                        {
                            pMapLayers.InsertLayerInGroup(pGroupLayer, hachureLyr, false, 0);
                        }
                    }
                }
                GeoPageLayout pGL = new GeoPageLayout(pMap, xzqGeo, batZT.GetScale, xzqTree.SelectedNode.Text, 1);
                pGL.WriteLog       = WriteLog;//ygc 2012-9-12 是否写日志
                pGL.typePageLayout = 5;
                pGL.MapOut();
            }
            catch (Exception ex)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", ex.Message);
            }
        }
Exemplo n.º 25
0
        private void btOk_Click(object sender, EventArgs e)
        {
            this.rtxtState.AppendText("正在执行,请您耐心等待...\n");
            this.rtxtState.ScrollToCaret();
            #region 步骤一:接收输入数据的路径
            string sInputFile = this.txtInput.Text;
            if (sInputFile.Equals(""))
            {
                MessageBox.Show("请选择输入DEM数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.rtxtState.AppendText("读取DEM数据...\n");
            this.rtxtState.ScrollToCaret();

            string sOutputFile = this.txtOutput.Text;
            if (sOutputFile.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.rtxtState.AppendText("读取输出路径...\n");
            this.rtxtState.ScrollToCaret();

            #endregion

            //string fileName = "地形地貌.mxd";
            //axMapControl1.LoadMxFile(fileName);
            ////将地图全屏最大化
            //axMapControl1.Extent = axMapControl1.FullExtent;



            IVariantArray parameters = new VarArrayClass();
            Geoprocessor  GP         = new Geoprocessor();
            object        sev        = null;
            this.rtxtState.AppendText("调用GP工具箱功能...\n");
            this.rtxtState.ScrollToCaret();

            ESRI.ArcGIS.SpatialAnalystTools.Slope slo = new ESRI.ArcGIS.SpatialAnalystTools.Slope();//计算坡度

            slo.in_raster          = sInputFile;
            slo.output_measurement = smeasurement;
            slo.z_factor           = sfactor;
            string sRoad1 = sOutputFile + sslope;
            slo.out_raster = sRoad1;
            this.rtxtState.AppendText("利用DEM数据计算坡度信息...\n");
            this.rtxtState.ScrollToCaret();

            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator sCal1 = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator sCal2 = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator sCal3 = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();
            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator sCal4 = new ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator();

            //try
            //{
            GP.Execute(slo, null);//坡度计算
            this.rtxtState.AppendText("计算坡度完成...\n");
            this.rtxtState.ScrollToCaret();
            //坡度<=8°&高程<=2500m
            sOrder1             = "(\"" + sOutputFile + "/slope.tif" + "\"" + "<=8" + ")" + "&" + "(\"" + sInputFile + "\"" + "<=2500" + ")";
            sCal1.expression    = sOrder1;
            sCal1.output_raster = sOutputFile + sSlope08;
            this.rtxtState.AppendText("开始进行建设区分级计算...\n");
            this.rtxtState.ScrollToCaret();
            GP.Execute(sCal1, null);
            this.rtxtState.AppendText("计算出“优化建设区”...\n");
            this.rtxtState.ScrollToCaret();
            //8°<坡度<=15°& 高程<=2500m
            sOrder2             = "(" + "8<" + "\"" + sOutputFile + "/slope.tif" + "\")" + "&" + "(\"" + sOutputFile + "/slope.tif" + "\"" + "<=15" + ")" + "&" + "(\"" + sInputFile + "\"" + "<=2500" + ")";
            sCal2.expression    = sOrder2;
            sCal2.output_raster = sOutputFile + sSlope815;
            GP.Execute(sCal2, null);
            this.rtxtState.AppendText("计算出“允许建设区”...\n");
            this.rtxtState.ScrollToCaret();
            //15°<坡度<=25°&高程<=2500m
            sOrder3             = "(" + "15<" + "\"" + sOutputFile + "/slope.tif" + "\")" + "&" + "(\"" + sOutputFile + "/slope.tif" + "\"" + "<=25" + ")" + "&" + "(\"" + sInputFile + "\"" + "<=2500" + ")";
            sCal3.expression    = sOrder3;
            sCal3.output_raster = sOutputFile + sSlope1525;
            GP.Execute(sCal3, null);
            this.rtxtState.AppendText("计算出“有条件建设区”...\n");
            this.rtxtState.ScrollToCaret();
            //25°<坡度 | 高程<=2500m
            sOrder4             = "(\"" + sOutputFile + "/slope.tif" + "\"" + ">25" + ")" + "|" + "(\"" + sInputFile + "\"" + ">2500" + ")";
            sCal4.expression    = sOrder4;
            sCal4.output_raster = sOutputFile + sSlope25;
            GP.Execute(sCal4, null);
            this.rtxtState.AppendText("计算出禁止建设区...\n");
            this.rtxtState.ScrollToCaret();

            this.rtxtState.AppendText("结果计算完成...\n");
            this.rtxtState.ScrollToCaret();
            //MessageBox.Show(GP.GetMessages(ref sev));


            //修改mxd数据源路径
            this.rtxtState.AppendText("开始将结果用地图输出展示,请稍等...\n");
            this.rtxtState.ScrollToCaret();
            IMapDocument pMapDocument = new MapDocumentClass();
            pMapDocument.Open("模板地形地貌.mxd"); //打开本地的“模板地形地貌.mxd”地图文档,用来操作改mxd文件
            IMap              pMap                   = pMapDocument.get_Map(0);
            IMapLayers        pMapLayer              = pMap as IMapLayers;
            IRasterLayer      pRasterLayer           = new RasterLayerClass();
            IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
            IRasterWorkspace  rasterWorkspace        = (IRasterWorkspace)rasterWorkspaceFactory.OpenFromFile(txtOutput.Text, 0);



            IRasterDataset pRasterDataset1 = rasterWorkspace.OpenRasterDataset("优化建设区.tif"); //打开"优化建设区.tif"为栅格图的文件名
            pRasterLayer.CreateFromDataset(pRasterDataset1);                                 //创建
            pRasterLayer = pMapLayer.get_Layer(1) as IRasterLayer;
            pRasterLayer.CreateFromDataset(pRasterDataset1);

            //更改“允许建设区.tif”数据源路径
            IRasterLayer   pRasterLayer2   = new RasterLayerClass();
            IRasterDataset pRasterDataset2 = rasterWorkspace.OpenRasterDataset("允许建设区.tif"); //打开"允许建设区.tif"为栅格图的文件名
            pRasterLayer2.CreateFromDataset(pRasterDataset2);                                //创建
            pRasterLayer2 = pMapLayer.get_Layer(2) as IRasterLayer;
            pRasterLayer2.CreateFromDataset(pRasterDataset2);

            //更改"有条件建设区.tif"数据源路径
            IRasterLayer   pRasterLayer3   = new RasterLayerClass();
            IRasterDataset pRasterDataset3 = rasterWorkspace.OpenRasterDataset("有条件建设区.tif"); //打开"有条件建设区.tif"为栅格图的文件名
            pRasterLayer3.CreateFromDataset(pRasterDataset3);                                 //创建
            pRasterLayer3 = pMapLayer.get_Layer(3) as IRasterLayer;
            pRasterLayer3.CreateFromDataset(pRasterDataset3);

            //更改"禁止建设区.tif"数据源路径
            IRasterLayer   pRasterLayer4   = new RasterLayerClass();
            IRasterDataset pRasterDataset4 = rasterWorkspace.OpenRasterDataset("禁止建设区.tif"); //打开"禁止建设区.tif"为栅格图的文件名
            pRasterLayer4.CreateFromDataset(pRasterDataset4);                                //创建
            pRasterLayer4 = pMapLayer.get_Layer(4) as IRasterLayer;
            pRasterLayer4.CreateFromDataset(pRasterDataset4);


            pMapDocument.Save(true, true);//保存更改完路径后的mxd文件模板地形地貌2

            //string fileName = "南湖村.mxd";// @"C:\Users\tangmeng\Desktop\农用地籍数据库\实验四\南湖数据\南湖村.mxd";
            //pMap.LoadMxFile(fileName);
            ////将地图全屏最大化
            //pMap.Extent = pMap.FullExtent;



            string MdbFile = "模板地形地貌.mxd";
            _PageLayoutControl.LoadMxFile(MdbFile);
            //将mxd全屏最大化
            _PageLayoutControl.Extent = _PageLayoutControl.FullExtent;


            // tabControl1.SelectedTab = tabPage1;

            this.rtxtState.AppendText("地图输出完成...\n");
            this.rtxtState.ScrollToCaret();
        }
Exemplo n.º 26
0
        private void LegendWizard_Load(object sender, EventArgs e)
        {
            if (m_pageLayoutControl.ActiveView.FocusMap == null)
            {
                MessageBox.Show("请先添加地图");
                return;
            }
            #region                       //点击 添加图例按钮 或在 PageLayoutControl中双击图例时
            if (mapSurroundFrame == null) //当点击 添加图例按钮 或在 PageLayoutControl中双击图例时 先创建图例 或从地图上获得已经添加的图例;
            {
                //Get the GraphicsContainer
                IGraphicsContainer graphicsContainer = m_pageLayoutControl.GraphicsContainer;
                graphicsContainer.Reset();
                IElementProperties pElementPerties = graphicsContainer.Next() as IElementProperties;
                //Get the MapFrame
                IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap);
                if (mapFrame == null)
                {
                    return;
                }
                while (pElementPerties != null) //从地图中获得已有的图例
                {
                    if (pElementPerties.Type == "Map Surround Frame")
                    {
                        pMapSurrounFrame = pElementPerties as IMapSurroundFrame;
                        if (pMapSurrounFrame.MapSurround.Name == "Legend")
                        {
                            m_legend = pMapSurrounFrame.MapSurround as ILegend;
                            break;
                        }
                    }
                    pElementPerties = (IElementProperties)graphicsContainer.Next();
                }
                if (m_legend == null) //当地图中没有添加图例时 创建新图例
                {
                    //Create a legend
                    UID uID = new UIDClass();
                    uID.Value = "esriCarto.Legend";

                    //Create a MapSurroundFrame from the MapFrame
                    mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

                    if (mapSurroundFrame == null)
                    {
                        return;
                    }
                    if (mapSurroundFrame.MapSurround == null)
                    {
                        return;
                    }

                    m_legend = mapSurroundFrame.MapSurround as ILegend;
                }
                else
                {
                    mapSurroundFrame = pMapSurrounFrame;
                }



                UID m_uid = new UIDClass();
                m_uid.Value = "{34C20002-4D3C-11D0-92D8-00805F7C28B0}";
                m_mapLayers = m_mapControl.Map as IMapLayers;
                m_emuLayer  = m_mapLayers.get_Layers(m_uid, true);//获取图层
                if (m_emuLayer != null)
                {
                    m_emuLayer.Reset();
                    ILayer m_layer = null;
                    while ((m_layer = m_emuLayer.Next()) != null)
                    {
                        this.listBox1.Items.Add(m_layer.Name);//将图层名添加到图例备选项中
                    }
                }
            }
            #endregion
            else //在双击任意范围打印框中图例时,获得图例,及图层信息;
            {
                if (m_Map == null)
                {
                    MessageBox.Show("请先添加地图!");
                }
                for (int k = 0; k < m_Map.LayerCount; k++)
                {
                    listBox1.Items.Add(m_Map.get_Layer(k).Name.ToString());
                }
                m_legend = mapSurroundFrame.MapSurround as ILegend;
            }
            //以下设置需要用到的变量 及初始化 对话框
            plegendFormat = m_legend.Format as ILegendFormat; //设置图例格式需要用到的

            pTextSymbol      = new TextSymbolClass();
            pTextSymbol.Size = 10;
            pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; //初始化图例标签的文本格式

            if (m_legend.Title != null)
            {
                textBox1.Text = m_legend.Title.ToString(); //初始化对话框中的文本框 文本
            }
            else
            {
                textBox1.Text = "Legend";
            }

            this.textBoxWidth.Text  = "36";
            this.textBoxHeight.Text = "15";
            IMapSurround mapSurround = m_legend as IMapSurround;
            mapSurroundFrame.MapSurround = mapSurround;
            m_FrameProperties            = (IFrameProperties)mapSurroundFrame;
            ISymbolBackground pSymbolBack   = m_FrameProperties.Background as ISymbolBackground;
            ISymbolBorder     pSymbolBorder = m_FrameProperties.Border as ISymbolBorder;
            ISymbolShadow     pSymbolShadow = m_FrameProperties.Shadow as ISymbolShadow;
            if (pSymbolBack != null)
            {
                this.btnBackGroundColor.BackColor = ColorTranslator.FromOle(pSymbolBack.FillSymbol.Color.RGB);
            }
            if (pSymbolBorder != null)
            {
                this.btnBolderColor.BackColor = ColorTranslator.FromOle(pSymbolBorder.LineSymbol.Color.RGB);
            }
            if (pSymbolShadow != null)
            {
                this.btnShadowColor.BackColor = ColorTranslator.FromOle(pSymbolShadow.FillSymbol.Color.RGB);
            }
        }