示例#1
0
        //新建地图文档
        public void NewMapDoc(AxMapControl axMapControl1)
        {
            DialogResult dialogResult = MessageBox.Show("保存文件?", "关闭文件", MessageBoxButtons.YesNoCancel);

            if (dialogResult == DialogResult.Yes)
            {
                SaveDocument(axMapControl1);
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.Title  = "新建地图文档";
                saveFileDialog1.Filter = "地图文档(*.mxd)|*.mxd";
                saveFileDialog1.ShowDialog();
                string filePath = saveFileDialog1.FileName; //地图文档路径
                mapDocument.New(filePath);                  //新建
                mapDocument.Open(filePath, "");             //打开
                axMapControl1.Map = mapDocument.get_Map(0);
            }
            if (dialogResult == DialogResult.No)
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.Title  = "新建地图文档";
                saveFileDialog1.Filter = "地图文档(*.mxd)|*.mxd";
                saveFileDialog1.ShowDialog();
                string filePath = saveFileDialog1.FileName; //地图文档路径
                mapDocument.New(filePath);                  //新建
                mapDocument.Open(filePath, "");             //打开
                axMapControl1.Map = mapDocument.get_Map(0);
            }
            if (dialogResult == DialogResult.Cancel)
            {
                return;
            }
        }
示例#2
0
 private void RefreshMap()
 {
     //added by jin
     try
     {
         cboActiveMap.Items.Clear();
         //  MessageBox.Show("Map is replaced");
         //Method 1: Open MapDocument file to get information about maps
         // m_mapDocument.Open(m_mapDocuemntName, "");
         //Method 2: Get information about maps from MapControl3
         m_mapDocument.Open(m_mapControl.DocumentFilename, "");
         for (int i = 0; i < m_mapDocument.MapCount; i++)
         {
             string item = m_mapDocument.get_Map(i).Name;
             cboActiveMap.Items.Add(item);
         }
         //Initialization
         cboActiveMap.Text = m_mapDocument.get_Map(0).Name;
         //The exception will be throwed,but it runes successfully in Exercise 5, may be a trouble for thread running
         //axMapControl1.Map = m_mapDocument.get_Map(0);
         //axMapControl1.Map = m_mapDocument.ActiveView.FocusMap;
         m_mapDocument.Close();
         //   axMapControl1.Refresh();
         // axTOCControl1.Update();
         AddLayersToComboBox();
     }
     catch (StackOverflowException se)
     {
         Console.WriteLine(se.Message);
     }
 }
示例#3
0
        /// <summary>
        /// 获取网络数据集
        /// </summary>
        /// <param name="pFeatureClass"></param>
        public void getNetWorkData(ref IFeatureClass pFeatureClass)
        {
            Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml");
            pMapDcument = new MapDocumentClass();
            IFeatureLayer pFeatureLayer;

            try
            {
                string NetWorkData = xml.GetElement("MapDocument", "RoadNetData");
                //将数据载入pMapDocument并与map控件联系起来
                NetWorkData = System.Windows.Forms.Application.StartupPath + NetWorkData;
                pMapDcument.Open(NetWorkData, "");

                for (int index = 0; index < pMapDcument.get_Map(0).LayerCount; index++)
                {
                    if (pMapDcument.get_Map(0).get_Layer(index).Name == "实验区路网数据")
                    {
                        pFeatureLayer = pMapDcument.get_Map(0).get_Layer(index) as IFeatureLayer;
                        pFeatureClass = pFeatureLayer.FeatureClass;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                xml = null;
            }
        }
示例#4
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     m_mapDoc.Open("E:\\Student\\IPAN\\Exercise07\\Rendering.mxd");
     this.cbxActiveMap.Items.Clear();
     for (int i = 0; i < m_mapDoc.MapCount; i++)
     {
         m_map = m_mapDoc.get_Map(i);
         this.cbxActiveMap.Items.Add(m_map.Name);
     }
 }
示例#5
0
 //加载地图文档
 private void loadMapDoc()
 {
     mapDocument = new ESRI.ArcGIS.Carto.MapDocumentClass();
     try
     {
         System.Windows.Forms.OpenFileDialog openFileDialog;
         openFileDialog        = new OpenFileDialog();
         openFileDialog.Title  = "打开地图文档";
         openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             string filePath = openFileDialog.FileName;
             mapDocument.Open(filePath, "");
             for (int i = 0; i < mapDocument.MapCount; i++)
             {
                 axMapControl1.Map = mapDocument.get_Map(i);
             }
             axMapControl1.Refresh();
         }
         else
         {
             mapDocument = null;
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
 }
示例#6
0
        /// <summary>
        /// 加载网络数据集
        /// </summary>
        public void LoadNetWorkDataSet()
        {
            Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml");
            pMapDcument = new MapDocumentClass();
            try
            {
                string NetWorkData = xml.GetElement("MapDocument", "RoadNetData");
                //将数据载入pMapDocument并与map控件联系起来
                NetWorkData = System.Windows.Forms.Application.StartupPath + NetWorkData;
                pMapDcument.Open(NetWorkData, "");

                int i;
                for (i = 0; i <= pMapDcument.MapCount - 1; i++)
                {
                    //一个IMapDocument对象中可能有多个Map对象,遍历每个map对象
                    mapControl.Map = pMapDcument.get_Map(i);
                }
                mapControl.Refresh();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                xml = null;
            }
        }
        public frmAddProjectLayers(IMap map2, esriDatasetType dType)
        {
            InitializeComponent();
            if (map2 == null)
            {
                OpenFileDialog ofdMxd = new OpenFileDialog();
                ofdMxd.Filter = "Map Doc|*.mxd";
                ofdMxd.Multiselect = false;
                DialogResult rslt = ofdMxd.ShowDialog();
                if (rslt == DialogResult.OK)
                {
                    mapDoc = new MapDocumentClass();
                    mapDoc.Open(ofdMxd.FileName, "");
                    map = mapDoc.get_Map(0);
                }
                else
                {
                    MessageBox.Show("A map document must be selected to work. Shutting down");
                    this.Close();
                }
            }
            else
            {
                map = map2;
            }
            if (dType == esriDatasetType.esriDTAny)
            {
                dType = esriDatasetType.esriDTFeatureClass;
            }
            switch (dType)
            {
                case esriDatasetType.esriDTTable:
                    this.Text = "Add Table";
                    label1.Text = "Select Table";
                    break;
                case esriDatasetType.esriDTRasterDataset:
                    this.Text = "Add Raster";
                    label1.Text = "Select Raster";
                    break;
                default:
                    this.Text = "Add Feature";
                    label1.Text = "Select Feature";
                    break;
            }
            mapserviceutility msUtil = new mapserviceutility();

            prjDatabase = msUtil.LcCacheDb;
            if (prjDatabase == "")
            {
                msUtil.changeLocalDatabase();
                prjDatabase = msUtil.LcCacheDb;
            }
            this.cmbLayers.Items.Clear();
            foreach (string s in getNames(dType))
            {
                lyrDic.Add(s, prjDatabase + "\\" + s);
                cmbLayers.Items.Add(s);
            }
            this.Refresh();
        }
示例#8
0
        private ESRI.ArcGIS.Carto.IMap PrivateCreateMxd(string sPathToMXDToSave)
        {
            try
            {
                _pMapDocument = new MapDocumentClass();

                //Copy the MXD
                System.IO.File.Copy(_sMxdTemplate, sPathToMXDToSave, true);

                _sNewDocument = sPathToMXDToSave;

                if (_pMapDocument.get_IsMapDocument(_sNewDocument))
                {
                    _pMapDocument.Open(_sNewDocument, null);
                    IMap pMap;
                    pMap = _pMapDocument.get_Map(0);
                    return(pMap);
                }

                return(null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void Load(IMapControl2 mapControl, XmlDocument xmlDocument)
        {
            try
            {
                XmlNode nodeMap = xmlDocument.SelectSingleNode("/MapDataLoadConfig/Map");
                if (nodeMap == null)
                {
                    return;
                }
                IMapDocument templateDocument = OpenTemplateDocument();
                IMap         templateMap      = templateDocument.get_Map(0);
                IMap         map = new MapClass();
                if (XmlHelper.GetAttributeValue(nodeMap, "Name") != string.Empty)
                {
                    map.Name = XmlHelper.GetAttributeValue(nodeMap, "Name");
                }

                XmlNodeList nodeListLayers = nodeMap.ChildNodes;
                if (nodeListLayers != null && nodeListLayers.Count > 0)
                {
                    for (var i = 0; i < nodeListLayers.Count; i++)
                    {
                        XmlNode nodelayer = nodeListLayers[i];
                    }
                }
            }catch (Exception ex)
            {
            }
        }
示例#10
0
        public void ChangeDataFrame(int DFIndex)
        {
            int cv = 0;

            axMapControl1.Map = Map.get_Map(DFIndex);

            axMapControl1.Refresh();

            checkedListBox1.Items.Clear();
            comboBox3.Items.Clear();
            comboBox2.Items.Clear();
            comboBox8.Items.Clear();

            IEnumLayer AllLayers = axMapControl1.Map.Layers;
            ILayer     OneLayer  = AllLayers.Next();

            while (OneLayer != null)
            {
                checkedListBox1.Items.Add(OneLayer.Name);
                comboBox3.Items.Add(OneLayer.Name);
                comboBox2.Items.Add(OneLayer.Name);
                comboBox8.Items.Add(OneLayer.Name);
                comboBox13.Items.Add(OneLayer.Name);
                comboBox15.Items.Add(OneLayer.Name);
                comboBox18.Items.Add(OneLayer.Name);
                comboBox22.Items.Add(OneLayer.Name);
                comboBox24.Items.Add(OneLayer.Name);
                comboBox28.Items.Add(OneLayer.Name);
                if (Map.get_Map(DFIndex).get_Layer(cv).Visible == true)
                {
                    checkedListBox1.SetItemChecked(cv, true);
                }
                cv++;
                OneLayer = AllLayers.Next();
            }
            comboBox3.Text  = comboBox3.Items[0].ToString();
            comboBox2.Text  = comboBox2.Items[0].ToString();
            comboBox8.Text  = comboBox2.Items[0].ToString();
            comboBox13.Text = comboBox13.Items[0].ToString();
            comboBox15.Text = comboBox15.Items[0].ToString();
            comboBox18.Text = comboBox18.Items[0].ToString();
            comboBox22.Text = comboBox22.Items[0].ToString();
            comboBox24.Text = comboBox24.Items[0].ToString();
            comboBox28.Text = comboBox28.Items[0].ToString();
            DF        = comboBox1.SelectedIndex;
            Dic[Path] = Map;
        }
示例#11
0
        public bool LoadMap()
        {
            try
            {
                openFileDialog1            = new OpenFileDialog();
                openFileDialog1.Title      = "Browse Mxd Files";
                openFileDialog1.DefaultExt = "mxd";
                openFileDialog1.Filter     = "mxd Diles (*.mxd)|*.mxd";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    Path = openFileDialog1.FileName;
                    if (Dic.ContainsKey(Path) == true)
                    {
                        checkedListBox1.Items.Clear();
                        Map = Dic[Path];
                        axMapControl1.Map = Map.get_Map(0);
                        axMapControl1.Refresh();
                    }
                    else
                    {
                        checkedListBox1.Items.Clear();
                        Map.Open(Path);
                        axMapControl1.Map = Map.get_Map(0);
                        axMapControl1.Refresh();
                        Dic.Add(Path, Map);
                    }
                    comboBox1.Items.Clear();
                    for (int i = 0; i < Map.MapCount; i++)
                    {
                        comboBox1.Items.Add(Map.get_Map(i).Name);
                    }
                    comboBox1.Text = comboBox1.Items[0].ToString();

                    toolStripStatusLabel2.Text = "Scale: " + axMapControl1.MapScale.ToString();

                    groupBox1.Enabled = true;
                    groupBox2.Enabled = true;
                    groupBox3.Enabled = true;
                    groupBox6.Enabled = true;
                    groupBox7.Enabled = true;
                    groupBox8.Enabled = true;
                    groupBox4.Enabled = true;
                    groupBox5.Enabled = true;

                    return(true);
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
示例#12
0
 // 加载Mxd地图文档
 private void LoadMxdFromFilename(string filename)
 {
     if (m_pMapC2.CheckMxFile(filename))
     {
         m_pMapDoc.Open(filename);
         m_pMapC2.Map = m_pMapDoc.get_Map(0);
     }
     else
     {
         MessageBox.Show(String.Format("加载【{0}】地图文档失败", filename));
     }
 }
示例#13
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog
            {
                InitialDirectory = @"C:\",
                Title            = "Browse .mxd Files",

                CheckFileExists = true,
                CheckPathExists = true,

                DefaultExt       = "txt",
                Filter           = "mxd files (*.mxd)|*.mxd",
                FilterIndex      = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly    = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;

                mdoc.Open(openFileDialog1.FileName, "");
                for (int i = 0; i < mdoc.MapCount; i++)// loop ageeb el dataframes eli 3ndi w a7otha f combobox
                {
                    comboBox1.Items.Add(mdoc.get_Map(i).Name);
                }
                comboBox1.SelectedItem = comboBox1.Items[0];
                map = mdoc.get_Map(0); //awel map 3ndi

                axMapControl1.Map = map;
                axMapControl1.Refresh(); // sa3at mesh bysht3'al mn 3'erha
            }
        }
示例#14
0
        private void LoadMap(string arcMapPath)
        {
            mapDoc.Open(arcMapPath);

            this.cbxActiveMap.Items.Clear();
            for (int i = 0; i < mapDoc.MapCount; i++)
            {
                this.cbxActiveMap.Items.Add(mapDoc.get_Map(i).Name);
            }
            this.cbxActiveMap.SelectedIndex = 0;
            m_toolbar.AddItem("esriControls.ControlsMapNavigationToolbar");
            //添加行政区划分
            this.districtList.Items.Clear();
            initData();

            // this.districtList.SelectedIndex = 0;

            m_map.Map = mapDoc.get_Map(0);
            m_toc.SetBuddyControl(m_map);
            m_toolbar.SetBuddyControl(m_map);
            m_toolbar.AddItem("esriControls.ControlsMapNavigationToolbar");
        }
示例#15
0
        private void openMap()
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "ArcGIS Files |*.mxd|All Files (*.*)|*.*";
            if (ofd.ShowDialog() != DialogResult.Cancel)
            {
                _mapDoc = new MapDocument();
                _mapDoc.Open(ofd.FileName);
                imap = _mapDoc.get_Map(0);
                MapWorkspace.currentMap.Model.Map = imap;
            }
        }
示例#16
0
        private void setMxd()
        {
            string sMxdPath = String.Format(@"{0}\{1}", WORKDIR, "Map.mxd");

            if (m_pMapC2.CheckMxFile(sMxdPath))
            {
                m_pMapDoc.Open(sMxdPath); //m_pMapC2.LoadMxFile(sMxdPath);
                m_pMapC2.Map = m_pMapDoc.get_Map(0);
            }
            m_pMapC2.AddShapeFile(WORKDIR, "BOUA.shp"); // 添加矢量数据
            m_pMapC2.AddShapeFile(WORKDIR, "RIVER_3J.shp");
            m_pMapC2.AddShapeFile(WORKDIR, "BOUP.shp");
        }
示例#17
0
        private void Save_btn_Click(object sender, EventArgs e)
        {
            if (axMapControl1.DocumentFilename == null)
            {
                SaveMapAs();
            }
            if (m_bDocModified == false)
            {
                return;
            }
            try
            {
                if (axMapControl1.Map.LayerCount == 0)
                {
                    return;
                }
                if (axMapControl1.DocumentFilename != null && axMapControl1.CheckMxFile(axMapControl1.DocumentFilename))
                {
                    if (m_pMapDocument != null)
                    {
                        m_pMapDocument.Close();
                        m_pMapDocument = null;
                    }
                    m_pMapDocument = new MapDocumentClass();                            //实例化
                    m_pMapDocument.Open(axMapControl1.DocumentFilename, "");            //必须的一步,用于将AxMapControl的实例的DocumentFileName传递给pMapDoc的
                    if (m_pMapDocument.get_IsReadOnly(m_pMapDocument.DocumentFilename)) //判断是否只读
                    {
                        MessageBox.Show("文件只读!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        m_pMapDocument.Close();
                        return;
                    }
                    m_pMapDocument.ReplaceContents((IMxdContents)axMapControl1.Map); //重置
                    IObjectCopy lip_ObjCopy = new ObjectCopyClass();                 //使用Copy,避免共享引用
                    axMapControl1.Map = (IMap)lip_ObjCopy.Copy(m_pMapDocument.get_Map(0));
                    lip_ObjCopy       = null;
                    m_pMapDocument.Save(m_pMapDocument.UsesRelativePaths, true);
                    axMapControl1.DocumentFilename = m_pMapDocument.DocumentFilename;
                    this.Text      = this.Text + "  -  " + axMapControl1.DocumentFilename;
                    m_bDocModified = false;

                    FileInfo fi = new FileInfo(m_pMapDocument.DocumentFilename);
                    Global.m_sMxdPath = fi.GetDirectory();
                    MessageBox.Show("保存完成!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#18
0
        public static IMap GetMap(IMapDocument mapDocument, string dataframeName)
        {
            if (mapDocument == null)
            {
                throw new ArgumentNullException("A valid map document [mapDocument] is required.");
            }

            if (dataframeName == null)
            {
                throw new ArgumentNullException("A valid dataframe name [dataframeName] is required.");
            }

            IMap map = null;

            for (int i = 0; i < mapDocument.MapCount; i++)
            {
                if (string.Compare(mapDocument.get_Map(i).Name, dataframeName, true) == 0)
                {
                    map = mapDocument.get_Map(i);
                    break;
                }
            }
            return(map);
        }
示例#19
0
        private void buttonZoom_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(t_gush_num.Text) &&
                !String.IsNullOrEmpty(t_parcel_num.Text))
            {
                IMapDocument  mxd    = CancelParcelEditor10_5.ArcMap.Application.Document as IMapDocument;
                IMap          map    = mxd.get_Map(0);
                IFeatureLayer flayer = AO.getLayerFromMxd(map, "חלקות להכנסה");

                string query = "GUSHNUM = " + Convert.ToInt32(t_gush_num.Text).ToString() +
                               " AND PARCEL_FINAL = " + Convert.ToInt32(t_parcel_num.Text).ToString();

                AO.ZoomToSelection(mxd, flayer, query);
            }
        }
示例#20
0
        private bool SaveMxdSymbolToXML(IMapDocument pMapDoc, string strXMLFile)
        {
            if (pMapDoc == null)
            {
                return(false);
            }
            if (!System.IO.File.Exists(strXMLFile))
            {
                return(false);
            }

            //打开xml文档
            try
            {
                System.Xml.XmlDocument pXmlDoc = new XmlDocument();
                pXmlDoc.Load(strXMLFile);

                IMap pMap = pMapDoc.get_Map(0);
                for (int i = 0; i < pMap.LayerCount; i++)
                {
                    ILayer pLyr = pMap.get_Layer(i);
                    if (pLyr is IGeoFeatureLayer)
                    {
                        IGeoFeatureLayer pGeoFeaLyr = pLyr as IGeoFeatureLayer;
                        string           strLyrName = pLyr.Name;

                        //如果有数据源 就以要素类的名称为准 如果没有就以图层名为准
                        if (pGeoFeaLyr.FeatureClass != null)
                        {
                            IDataset pDataset = pGeoFeaLyr.FeatureClass as IDataset;
                            strLyrName = pDataset.Name;
                        }

                        strLyrName = strLyrName.Substring(strLyrName.IndexOf('.') + 1);
                        IFeatureRenderer pFeaRender = pGeoFeaLyr.Renderer;
                        UpdateSymbolInfo(strLyrName, pXmlDoc, pFeaRender);
                    }
                }

                pXmlDoc.Save(strXMLFile);
            }
            catch
            {
                return(false);
            }

            return(true);
        }
示例#21
0
        private void InitMap()
        {
            m_pMapC2  = axMapControl_main.Object as IMapControl2;
            m_pMapDoc = new MapDocumentClass();

            string sMxdPath = String.Format(@"{0}\{1}", WORKDIR, "Map.mxd");

            if (m_pMapC2.CheckMxFile(sMxdPath))
            {
                m_pMapDoc.Open(sMxdPath); // m_pMapC2.LoadMxFile(sMxdPath);
                m_pMapC2.Map = m_pMapDoc.get_Map(0);
            }
            //m_pMapC2.AddShapeFile(WORKDIR, "BOUA.shp"); // 添加矢量数据
            //m_pMapC2.AddShapeFile(WORKDIR, "RIVER_3J.shp");
            //m_pMapC2.AddShapeFile(WORKDIR, "BOUP.shp");
        }
示例#22
0
 private void barButtonItem101_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     if (this.mainMapControl.LayerCount > 0)
     {
         DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
         if (result == DialogResult.Cancel)
         {
             return;
         }
         //if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null);
     }
     this.openFileDialog.Title            = "请选择地图文件";
     this.openFileDialog.Filter           = "MXD地图文件|*.mxd";
     this.openFileDialog.Multiselect      = false;
     this.openFileDialog.RestoreDirectory = true;
     if (this.openFileDialog.ShowDialog() == DialogResult.OK)
     {
         Application.DoEvents();
         string docName = this.openFileDialog.FileName;
         try
         {
             this.pMapDocument = new MapDocumentClass();
             if (pMapDocument.get_IsPresent(docName) && !pMapDocument.get_IsPasswordProtected(docName))
             {
                 pMapDocument.Open(docName, null);
                 IMap pMap = pMapDocument.get_Map(0);
                 m_controlsSynchronizer.ReplaceMap(pMap);
                 this.mainMapControl.DocumentFilename = docName;
                 this.Text = System.IO.Path.GetFileName(this.openFileDialog.FileName) + " - " + "LinGIS - LinInfo";
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument);
             Application.DoEvents();
             this.pMapDocument = null;
         }
     }
 }
示例#23
0
        private void OpenDoc_btn_Click(object sender, EventArgs e)
        {
            axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerHourglass;
            m_pMapDocument             = new MapDocumentClass();
            try
            {
                OpenFileDialog dlgOpen = new OpenFileDialog();
                dlgOpen.Title  = "打开文档";
                dlgOpen.Filter = "ArcMap Document(*.mxd)|*.mxd";
                string sFilePath = null;
                if (dlgOpen.ShowDialog() == DialogResult.OK)
                {
                    sFilePath = dlgOpen.FileName;
                }
                else
                {
                    return;
                }

                if (sFilePath == "")
                {
                    MessageBox.Show("文件路径错误!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }
                //将数据载入pMapDocument并与map控件联系起来
                m_pMapDocument.Open(sFilePath, "");
                //IMapDocument对象中可能有多个Map对象,遍历每个map对象
                for (int i = 0; i < m_pMapDocument.MapCount; i++)
                {
                    axMapControl1.Map = m_pMapDocument.get_Map(i);
                }
                axMapControl1.DocumentFilename = m_pMapDocument.DocumentFilename;
                this.Text = this.Text + "  -  " + axMapControl1.DocumentFilename;
                axMapControl1.Refresh();
                FileInfo fi = new FileInfo(m_pMapDocument.DocumentFilename);
                Global.m_sMxdPath = fi.GetDirectory();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "失败", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault;
        }
示例#24
0
 public bool LoadMapDocument(ref IMap pMap, string sFileName, string sPassword)
 {
     try
     {
         if (sFileName == null)
         {
             sFileName = "";
         }
         if (sPassword == null)
         {
             sPassword = "";
         }
         if (pMap == null)
         {
             Interaction.MsgBox("地图文档加载失败,Map 加载失败。", MsgBoxStyle.Exclamation, "错误警告");
             return(false);
         }
         IMapDocument document = null;
         document = this.OpenMapDocument(sFileName, sPassword);
         if (document == null)
         {
             return(false);
         }
         pMap = document.get_Map(0);
         document.Close();
         document = null;
         IActiveView view = pMap as IActiveView;
         if (view.GraphicsContainer != null)
         {
             IViewManager manager          = view as IViewManager;
             ISelection   elementSelection = manager.ElementSelection;
             view.Selection = elementSelection;
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "LoadMapDocument", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
 public void RemoveLayer(string sLayerName)
 {
     if (m_axMapControl == null)
     {
         return;
     }
     for (int iMap = 0; iMap < m_pMapDocument.MapCount; iMap++)
     {
         IMap pMap = m_pMapDocument.get_Map(iMap);
         for (int i = 0; i < pMap.LayerCount; i++)
         {
             ILayer pLayer = pMap.get_Layer(i);
             if (pLayer != null && pLayer.Name == sLayerName)
             {
                 pMap.DeleteLayer(pLayer);
                 m_axMapControl.Refresh();
                 return;
             }
         }
     }
 }
示例#26
0
 private void loadMapDoc()
 {
     mapDoc = new MapDocumentClass();
     try
     {
         System.Windows.Forms.OpenFileDialog openFileDialog = new OpenFileDialog();
         openFileDialog.Title  = "打开地图文档";
         openFileDialog.Filter = "map documents (*.mxd)|*.mxd";
         openFileDialog.ShowDialog();
         string filePath = openFileDialog.FileName;
         mapDoc.Open(filePath, "");
         for (int i = 0; i < mapDoc.MapCount; i++)//
         {
             axMapControl1.Map = mapDoc.get_Map(i);
         }
         axMapControl1.Refresh();
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
 }
示例#27
0
        private List <ILayer> getLayerList(UID id)
        {
            List <ILayer> res = new List <ILayer>();

            // try-catch ist nötig, da get_Layers() eine Exception auslöst,
            // wenn es keine passenden Layer findet!
            try
            {
                IEnumLayer lyrs = mxd.get_Map(0).get_Layers(id, true);
                lyrs.Reset();
                ILayer lyr = lyrs.Next();
                while (lyr != null)
                {
                    res.Add(lyr);
                    lyr = lyrs.Next();
                }
            }
            catch
            {
            }
            return(res);
        }
示例#28
0
 /// <summary>
 /// 加载默认MXD文件
 /// </summary>
 /// <param name="axMapControl">axMapControl引用</param>
 /// <param name="strFilePath">地图文件路径</param>
 /// <returns>正常:“”;异常:异常字符串</returns>
 private SystemErrorType LoadMapDoc(ref AxMapControl axMapControl, string strFilePath)
 {
     //文件路径检验
     if (strFilePath == "")
     {
         return(SystemErrorType.enumFilePathIsNull);
     }
     try
     {
         m_MapDocument = new MapDocumentClass();
         m_MapDocument.Open(strFilePath, "");
         for (int i = 0; i <= m_MapDocument.MapCount - 1; i++)
         {
             axMapControl.Map = m_MapDocument.get_Map(i);
         }
         axMapControl.Refresh();
     }
     catch (Exception)
     {
         return(SystemErrorType.enumArcObjectHandleError);
     }
     return(SystemErrorType.enumOK);
 }
示例#29
0
 private void open_Click(object sender, EventArgs e)
 {
     mapDocument = new MapDocumentClass();
     try
     {
         System.Windows.Forms.OpenFileDialog openFileDialog;
         openFileDialog        = new OpenFileDialog();
         openFileDialog.Title  = "打开图层文件";
         openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
         openFileDialog.ShowDialog();
         string filePath = openFileDialog.FileName;
         mapDocument.Open(filePath, "");
         for (int i = 0; i < mapDocument.MapCount; i++)
         {
             mainMapControl.Map = mapDocument.get_Map(i);
         }
         mainMapControl.Refresh();
     }
     catch (Exception ex)
     {
         MessageBox.Show("加载失败" + ex.ToString());
     }
 }
示例#30
0
 //加载地图文档
 private void loadMapDoc()
 {
     mapDocument = new ESRI.ArcGIS.Carto.MapDocumentClass();
     try
     {
         System.Windows.Forms.OpenFileDialog openFileDialog;
         openFileDialog = new OpenFileDialog();
         openFileDialog.Title = "打开地图文档";
         openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             string filePath = openFileDialog.FileName;
             mapDocument.Open(filePath, "");
             for (int i = 0; i < mapDocument.MapCount; i++)
             {
                 axMapControl1.Map = mapDocument.get_Map(i);
             }
             axMapControl1.Refresh();
         }
         else
         {
             mapDocument = null;
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
 }
示例#31
0
 private void btnOpenDoc_Click(object sender, EventArgs e)
 {
     if (this.mainMapControl.LayerCount > 0)
     {
         DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
         if (result == DialogResult.Cancel) return;
         if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null);
     }
     this.openFileDialog.Title = "请选择地图文件";
     this.openFileDialog.Filter = "MXD地图文件|*.mxd";
     this.openFileDialog.Multiselect = false;
     this.openFileDialog.RestoreDirectory = true;
     if (this.openFileDialog.ShowDialog() == DialogResult.OK)
     {
         Application.DoEvents();
         string docName = this.openFileDialog.FileName;
         try
         {
             this.pMapDocument = new MapDocumentClass();
             if (pMapDocument.get_IsPresent(docName) && !pMapDocument.get_IsPasswordProtected(docName))
             {
                 pMapDocument.Open(docName, null);
                 IMap pMap = pMapDocument.get_Map(0);
                 m_controlsSynchronizer.ReplaceMap(pMap);
                 this.mainMapControl.DocumentFilename = docName;
                 this.Text = System.IO.Path.GetFileName(this.openFileDialog.FileName) + " - " + "LinGIS - LinInfo";
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument);
             Application.DoEvents();
             this.pMapDocument = null;
         }
     }
 }
示例#32
0
        private ESRI.ArcGIS.Carto.IMap PrivateCreateMxd(string sPathToMXDToSave)
        {

            try
            {

                _pMapDocument = new MapDocumentClass();

                //Copy the MXD
                System.IO.File.Copy(_sMxdTemplate, sPathToMXDToSave, true);

                _sNewDocument = sPathToMXDToSave;

                if (_pMapDocument.get_IsMapDocument(_sNewDocument))
                {
                    _pMapDocument.Open(_sNewDocument, null);
                    IMap pMap;
                    pMap = _pMapDocument.get_Map(0);
                    return pMap;
                }

                return null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#33
0
    public static void OperateMapDoc(AxMapControl axMapControl1, AxMapControl axMapControl2, string strOperateType)
    {
        OpenFileDialog OpenFileDialog = new OpenFileDialog();
        SaveFileDialog SaveFileDialog = new SaveFileDialog();
        OpenFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd";
        SaveFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd";
        string strDocFileN = string.Empty;
        pMapDocument = new MapDocumentClass();
        switch (strOperateType)
        {
            case "NewDoc":
                {
                    SaveFileDialog.Title = "输入需要新建地图文档的名称";
                    SaveFileDialog.ShowDialog();
                    strDocFileN = SaveFileDialog.FileName;
                    if (strDocFileN == string.Empty)
                        return;
                    pMapDocument.New(strDocFileN);
                    pMapDocument.Open(strDocFileN, "");
                    axMapControl1.Map = pMapDocument.get_Map(0);
                    break;
                }
            case "OpenDoc":
                {
                    OpenFileDialog.Title = "输入需要加载的地图文档";
                    OpenFileDialog.ShowDialog();
                    strDocFileN = OpenFileDialog.FileName;
                    if (strDocFileN == string.Empty)
                        return;
                    pMapDocument.Open(strDocFileN, "");
                    for (int i = 0; i < pMapDocument.MapCount; i++)
                    {
                        axMapControl1.Map = pMapDocument.get_Map(i);
                        //axMapControl2.Map = pMapDocument.get_Map(i);
                    }
                    axMapControl1.Refresh();

                    break;
                }
            case "SaveDoc":
                {
                    if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
                    {
                        MessageBox.Show("此地图为只读文档", "信息提示");
                        return;
                    }
                    pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                    MessageBox.Show("保存成功!", "信息提示");
                    break;
                }
            case "SaveDocAS":
                {
                    SaveFileDialog.Filter = "地图文档另存";
                    SaveFileDialog.ShowDialog();
                    strDocFileN = SaveFileDialog.FileName;
                    if (strDocFileN == string.Empty)
                        return;
                    if (strDocFileN == pMapDocument.DocumentFilename)
                    {
                        pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                        MessageBox.Show("保存成功!", "信息提示");
                        break;
                    }
                    else
                    {
                        pMapDocument.SaveAs(strDocFileN, true, true);
                        MessageBox.Show("保存成功", "信息提示");
                    }
                    break;
                }
            default:
                break;
        }
    }
示例#34
0
        private void cancel_Click(object sender, EventArgs e)
        {
            IMapDocument mxd = CancelParcelEditor10_5.ArcMap.Application.Document as IMapDocument;
            IMap         map = mxd.get_Map(0);
            string       gdb = AO.getLayerPathFromMxd(map, "חלקות לעריכה");

            if (String.IsNullOrEmpty(gdb))
            {
                MessageBox.Show("שכבת חלקות לעריכה אינה קיימת במפה");
            }
            else
            {
                ITable table = AO.open_table(gdb, "CANCEL_PARCEL_EDIT");
                if (table != null)
                {
                    if (!String.IsNullOrEmpty(f_gush_num.Text) &&
                        !String.IsNullOrEmpty(f_parcel_num.Text) &&
                        !String.IsNullOrEmpty(t_gush_num.Text) &&
                        !String.IsNullOrEmpty(t_parcel_num.Text) &&
                        !String.IsNullOrEmpty(f_gush_suffix.Text) &&
                        !String.IsNullOrEmpty(t_gush_suffix.Text))
                    {
                        if (String.IsNullOrEmpty(f_parcel_num_e.Text) && String.IsNullOrEmpty(t_parcel_num_e.Text))
                        {
                            ICursor cursor  = AO.create_table_cursor(table);
                            IRow    row     = cursor.NextRow();
                            bool    deleted = false;
                            while (row != null)
                            {
                                if (!(row.Value[row.Fields.FindField("F_GUSH_NUM")] == null) &&
                                    !(row.Value[row.Fields.FindField("F_PARCEL_NUM")] == null) &&
                                    !(row.Value[row.Fields.FindField("T_GUSH_NUM")] == null) &&
                                    !(row.Value[row.Fields.FindField("T_PARCEL_NUM")] == null))
                                {
                                    if (
                                        row.Value[row.Fields.FindField("F_GUSH_NUM")] == Convert.ToInt32(f_gush_num.Text) &&
                                        row.Value[row.Fields.FindField("F_PARCEL_NUM")] == Convert.ToInt32(f_parcel_num.Text) &&
                                        row.Value[row.Fields.FindField("T_GUSH_NUM")] == Convert.ToInt32(t_gush_num.Text) &&
                                        row.Value[row.Fields.FindField("T_PARCEL_NUM")] == Convert.ToInt32(t_parcel_num.Text)
                                        )
                                    {
                                        row.Delete();
                                        MessageBox.Show("רשומה נמחקה");
                                        deleted = true;
                                    }
                                    row = cursor.NextRow();
                                }
                            }
                            if (deleted == false)
                            {
                                MessageBox.Show("לא נמצאה רשומה למחיקה");
                            }
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(f_parcel_num_e.Text) && String.IsNullOrEmpty(t_parcel_num_e.Text))
                            {
                                int           f_parcel_end   = Convert.ToInt32(f_parcel_num_e.Text);
                                int           f_parcel_start = Convert.ToInt32(f_parcel_num.Text);
                                List <object> parcel_num_in  = new List <object>();
                                while (f_parcel_start <= f_parcel_end)
                                {
                                    parcel_num_in.Add(f_parcel_start.ToString());
                                    f_parcel_start++;
                                }
                                string  query   = "T_PARCEL_NUM =" + t_parcel_num.Text + " AND F_PARCEL_NUM IN (" + AO.ListToString(parcel_num_in) + ")";
                                ICursor cursor  = AO.create_table_cursor_with_query(table, query);
                                IRow    row     = cursor.NextRow();
                                bool    deleted = false;
                                while (row != null)
                                {
                                    row.Delete();
                                    row     = cursor.NextRow();
                                    deleted = true;
                                }
                                if (deleted == false)
                                {
                                    MessageBox.Show("לא נמצאה רשומה למחיקה");
                                }
                            }
                            if (String.IsNullOrEmpty(f_parcel_num_e.Text) && !String.IsNullOrEmpty(t_parcel_num_e.Text))
                            {
                                int           t_parcel_end   = Convert.ToInt32(t_parcel_num_e.Text);
                                int           t_parcel_start = Convert.ToInt32(t_parcel_num.Text);
                                List <object> parcel_num_in  = new List <object>();
                                while (t_parcel_start <= t_parcel_end)
                                {
                                    parcel_num_in.Add(t_parcel_start.ToString());
                                    t_parcel_start++;
                                }
                                string  query   = "F_PARCEL_NUM =" + f_parcel_num.Text + " AND T_PARCEL_NUM IN (" + AO.ListToString(parcel_num_in) + ")";
                                ICursor cursor  = AO.create_table_cursor_with_query(table, query);
                                IRow    row     = cursor.NextRow();
                                bool    deleted = false;
                                while (row != null)
                                {
                                    row.Delete();
                                    row     = cursor.NextRow();
                                    deleted = true;
                                }
                                if (deleted == false)
                                {
                                    MessageBox.Show("לא נמצאה רשומה למחיקה");
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("נא למלא את כל השדות");
                    }
                }
                else
                {
                    MessageBox.Show("טבלת CANCEL_PARCEL_EDIT אינה קיימת ב gdb");
                }
            }
        }
示例#35
0
        private void insert_Click(object sender, EventArgs e)
        {
            IMapDocument mxd = CancelParcelEditor10_5.ArcMap.Application.Document as IMapDocument;
            IMap         map = mxd.get_Map(0);
            string       gdb = AO.getLayerPathFromMxd(map, "חלקות לעריכה");

            if (String.IsNullOrEmpty(gdb))
            {
                MessageBox.Show("שכבת חלקות לעריכה אינה קיימת במפה");
            }
            else
            {
                ITable table = AO.open_table(gdb, "CANCEL_PARCEL_EDIT");
                if (table != null)
                {
                    if (!String.IsNullOrEmpty(f_gush_num.Text) &&
                        !String.IsNullOrEmpty(f_parcel_num.Text) &&
                        !String.IsNullOrEmpty(t_gush_num.Text) &&
                        !String.IsNullOrEmpty(t_parcel_num.Text) &&
                        !String.IsNullOrEmpty(f_gush_suffix.Text) &&
                        !String.IsNullOrEmpty(t_gush_suffix.Text)
                        )
                    {
                        if (String.IsNullOrEmpty(f_parcel_num_e.Text) && String.IsNullOrEmpty(t_parcel_num_e.Text))
                        {
                            IRow row = table.CreateRow();
                            row.Value[row.Fields.FindField("F_GUSH_NUM")]    = Convert.ToInt32(f_gush_num.Text);
                            row.Value[row.Fields.FindField("F_PARCEL_NUM")]  = Convert.ToInt32(f_parcel_num.Text);
                            row.Value[row.Fields.FindField("T_GUSH_NUM")]    = Convert.ToInt32(t_gush_num.Text);
                            row.Value[row.Fields.FindField("T_PARCEL_NUM")]  = Convert.ToInt32(t_parcel_num.Text);
                            row.Value[row.Fields.FindField("F_GUSH_SUFFIX")] = Convert.ToInt32(f_gush_suffix.Text);
                            row.Value[row.Fields.FindField("T_GUSH_SUFFIX")] = Convert.ToInt32(t_gush_suffix.Text);
                            row.Store();
                            MessageBox.Show("רשומה נוספה");
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(f_parcel_num_e.Text) && String.IsNullOrEmpty(t_parcel_num_e.Text))
                            {
                                int f_parcel_end   = Convert.ToInt32(f_parcel_num_e.Text);
                                int f_parcel_start = Convert.ToInt32(f_parcel_num.Text);
                                while (f_parcel_start <= f_parcel_end)
                                {
                                    IRow row = table.CreateRow();
                                    row.Value[row.Fields.FindField("F_GUSH_NUM")]    = Convert.ToInt32(f_gush_num.Text);
                                    row.Value[row.Fields.FindField("F_PARCEL_NUM")]  = f_parcel_start;
                                    row.Value[row.Fields.FindField("T_GUSH_NUM")]    = Convert.ToInt32(t_gush_num.Text);
                                    row.Value[row.Fields.FindField("T_PARCEL_NUM")]  = Convert.ToInt32(t_parcel_num.Text);
                                    row.Value[row.Fields.FindField("F_GUSH_SUFFIX")] = Convert.ToInt32(f_gush_suffix.Text);
                                    row.Value[row.Fields.FindField("T_GUSH_SUFFIX")] = Convert.ToInt32(t_gush_suffix.Text);
                                    row.Store();
                                    f_parcel_start++;
                                }
                                MessageBox.Show("רשומות נוספו (איחוד)");
                            }
                            if (String.IsNullOrEmpty(f_parcel_num_e.Text) && !String.IsNullOrEmpty(t_parcel_num_e.Text))
                            {
                                int t_parcel_end   = Convert.ToInt32(t_parcel_num_e.Text);
                                int t_parcel_start = Convert.ToInt32(t_parcel_num.Text);
                                while (t_parcel_start <= t_parcel_end)
                                {
                                    IRow row = table.CreateRow();
                                    row.Value[row.Fields.FindField("F_GUSH_NUM")]    = Convert.ToInt32(f_gush_num.Text);
                                    row.Value[row.Fields.FindField("F_PARCEL_NUM")]  = Convert.ToInt32(f_parcel_num.Text);
                                    row.Value[row.Fields.FindField("T_GUSH_NUM")]    = Convert.ToInt32(t_gush_num.Text);
                                    row.Value[row.Fields.FindField("T_PARCEL_NUM")]  = t_parcel_start;
                                    row.Value[row.Fields.FindField("F_GUSH_SUFFIX")] = Convert.ToInt32(f_gush_suffix.Text);
                                    row.Value[row.Fields.FindField("T_GUSH_SUFFIX")] = Convert.ToInt32(t_gush_suffix.Text);
                                    row.Store();
                                    t_parcel_start++;
                                }
                                MessageBox.Show("רשומות נוספו (חלוקה)");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("נא למלא את כל השדות");
                    }
                }
                else
                {
                    MessageBox.Show("טבלת CANCEL_PARCEL_EDIT אינה קיימת ב gdb");
                }
            }
        }