private void btnWebMap_Click(object sender, EventArgs e)
 {
     if (!(IsConnected()))
     {
         // Since Web Maps require and internet connection anyways
         // just fail if there isn't one.
         MessageBox.Show("Cannot Connect to ArcGIS.com!", "Failed to open Web Map.", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     try
     {
         IMapDocument mapDocument = new MapDocumentClass();
         string       webMapMxd   = webMapLocation + @"\" + myWebMapName + @"\" + myWebMapName + ".mxd";
         if (File.Exists(webMapMxd))
         {
             mapDocument.Open(webMapMxd, "");
         }
         else
         {
             mapDocument.Open(txtWebMap.Text, "");
         }
         axMapControl1.Map = mapDocument.get_Map(0);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to open Web Map!", ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 //保存地图文档
 public static void SaveMapDocument(ESRI.ArcGIS.Controls.AxMapControl axMapControl)
 {
     if (axMapControl == null)
     {
         return;
     }
     string m_mapDocumentName = axMapControl.DocumentFilename;
     if (axMapControl.CheckMxFile(m_mapDocumentName))
     {
         //新建地图文档接口
         IMapDocument mapDoc = new MapDocumentClass();
         mapDoc.Open(m_mapDocumentName, string.Empty);
         //确定文档非只读文件
         if (mapDoc.get_IsReadOnly(m_mapDocumentName))
         {
             MessageBox.Show("Map document is read only!");
             mapDoc.Close();
             return;
         }
         //用当前地图替换文档内容
         mapDoc.ReplaceContents((IMxdContents)axMapControl.Map);
         //保存文档
         mapDoc.Save(mapDoc.UsesRelativePaths, false);
         //关闭文档
         mapDoc.Close();
     }
 }
Beispiel #3
0
        protected override void Process(Uri uri)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            mapDoc.Open(uri.LocalPath, null);
            try
            {
                var documentInfo = (IDocumentInfo2)mapDoc;

                var title = GetTitle(documentInfo, uri);
                var subject = GetSubject(documentInfo, uri);
                var comments = GetComments(documentInfo, uri);
                var bitmap = GetBitmap(mapDoc);

                var mxdContent = new MxdContent(title, bitmap, uri, subject, comments);

                OnFoundContent(mxdContent);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                mapDoc.Close();
            }
        }
Beispiel #4
0
        private void BtnSaveMXD_Click(object sender, EventArgs e)
        {
            //make sure that the current MapDoc is valid first
            if (m_documentFileName != string.Empty && m_mapControl.CheckMxFile(m_documentFileName))
            {
                //create a new instance of a MapDocument class
                IMapDocument mapDoc = new MapDocumentClass();
                //Open the current document into the MapDocument
                mapDoc.Open(m_documentFileName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_documentFileName))
                {
                    MessageBox.Show("سند فقط خواندنی است");
                    mapDoc.Close();
                    return;
                }

                //Replace the map with the one of the PageLayout
                mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout);

                //save the document
                mapDoc.Save(mapDoc.UsesRelativePaths, false);
                mapDoc.Close();
            }
        }
Beispiel #5
0
        public static void SaveMxd()
        {
            IMapDocument oMapDoc = new MapDocumentClass();

            oMapDoc.Open(AxMapControl.DocumentFilename);

            if (oMapDoc.IsReadOnly[AxMapControl.DocumentFilename])
            {
                throw new InvalidOperationException("Can not save mxd. Is read only.");
            }

            AxMapControl.Update();
            AxTocControl.Update();

            oMapDoc.ReplaceContents((IMxdContents)AxMapControl.Map);
            oMapDoc.Save(true, true);
            oMapDoc.Close();

            if (oMapDoc != null)
            {
                ComReleaser.ReleaseCOMObject(oMapDoc);
                oMapDoc = null;
            }

            if (AxMapControl.Map != null)
            {
                ComReleaser.ReleaseCOMObject(AxMapControl.Map);
                AxMapControl.Map = null;
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Beispiel #6
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_Click(object sender, EventArgs e)
        {
            try
            {
                //空白文档不保存
                if (String.IsNullOrEmpty(m_mapControl.DocumentFilename))
                {
                    return;
                }

                //创建地图文档,调用open方法,调用ReplaceContents方法
                IMapDocument mapDocument = new MapDocumentClass();
                mapDocument.Open(m_mapControl.DocumentFilename);
                mapDocument.ReplaceContents(m_mapControl as IMxdContents);

                IObjectCopy objCopy = new ObjectCopyClass(); //使用Copy,避免共享引用
                m_mapControl.Map = (IMap)objCopy.Copy(mapDocument.get_Map(0));
                objCopy          = null;

                mapDocument.Save(mapDocument.UsesRelativePaths, false);
                mapDocument.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("请联系管理员,错误原因是:" + ex.Message);
            }
        }
Beispiel #7
0
        //保存地图文档
        public static void SaveMapDocument(ESRI.ArcGIS.Controls.AxMapControl axMapControl)
        {
            if (axMapControl == null)
            {
                return;
            }
            string m_mapDocumentName = axMapControl.DocumentFilename;

            if (axMapControl.CheckMxFile(m_mapDocumentName))
            {
                //新建地图文档接口
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);
                //确定文档非只读文件
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }
                //用当前地图替换文档内容
                mapDoc.ReplaceContents((IMxdContents)axMapControl.Map);
                //保存文档
                mapDoc.Save(mapDoc.UsesRelativePaths, false);
                //关闭文档
                mapDoc.Close();
            }
        }
Beispiel #8
0
        private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            checkedListBox1.Items.Clear();
            comboBox2.Items.Clear();
            IMapDocument mdoc = new MapDocumentClass();

            mdoc.Open(textBox1.Text, "");

            for (int i = 0; i < comboBox1.Items.Count; i++)
            {
                if (mdoc.get_Map(i).Name == comboBox1.SelectedItem.ToString())
                {
                    map = mdoc.get_Map(i);
                    axMapControl1.Map = map;
                    axMapControl1.Refresh();

                    IEnumLayer allLayers = map.get_Layers();
                    ILayer     layer     = allLayers.Next();//chosen layer
                    while (layer != null)
                    {
                        checkedListBox1.Items.Add(layer.Name); //to choose layer
                        comboBox2.Items.Add(layer.Name);       //to remove layer or definition query
                        layer = allLayers.Next();
                    }
                }
                //check true for all layers
                for (int d = 0; d < checkedListBox1.Items.Count; d++)
                {
                    checkedListBox1.SetItemChecked(d, true);
                }
            }
        }
Beispiel #9
0
        private void SaveDocument()
        {
            try
            {
                if (mapControl.CheckMxFile(m_mapDocumentName))
                {
                    //使用MapDocument对象保存文件
                    IMapDocument mapDocument = new MapDocumentClass();
                    mapDocument.Open(m_mapDocumentName, string.Empty);

                    //判断文件是不是只读的
                    if (mapDocument.get_IsReadOnly(m_mapDocumentName))
                    {
                        MessageBox.Show("地图文件是只读的!");
                        mapDocument.Close();
                        return;
                    }
                    //替换已有的文件
                    mapDocument.ReplaceContents((IMxdContents)mapControl.Map);
                    //保存文件
                    mapDocument.Save(mapDocument.UsesRelativePaths, false);
                    mapDocument.Close();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            //launch a new OpenFile dialog
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "Map Documents (*.mxd)|*.mxd";
            dlg.Multiselect = false;
            dlg.Title       = "Open Map Document";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string docName = dlg.FileName;

                IMapDocument mapDoc = new MapDocumentClass();
                if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
                {
                    mapDoc.Open(docName, string.Empty);

                    // set the first map as the active view
                    IMap map = mapDoc.get_Map(0);
                    mapDoc.SetActiveView((IActiveView)map);

                    m_controlsSynchronizer.PageLayoutControl.PageLayout = mapDoc.PageLayout;

                    m_controlsSynchronizer.ReplaceMap(map);

                    mapDoc.Close();

                    m_sDocumentPath = docName;
                }
            }
        }
Beispiel #11
0
        public void TransferMapDataWithinExtents_Test(string subDirectory, string mapDocumentFilename, string dataframeName, string outputShapefileDirectory)
        {
            string temp   = System.IO.Path.Combine(_dataDirectory, subDirectory);
            string mapDoc = System.IO.Path.Combine(temp, mapDocumentFilename);

            IMapDocument mapDocument = new MapDocumentClass();

            mapDocument.Open(mapDoc, null);

            IMap map = GeodatabaseUtil.GetMap(mapDocument, dataframeName);
            List <IFeatureLayer> layers     = GeodatabaseUtil.GetFeatureLayers(map);
            IDataset             dataset    = (IDataset)layers[0].FeatureClass;
            IGeoDataset          geoDataset = (IGeoDataset)layers[0].FeatureClass;

            string destination = System.IO.Path.Combine(temp, outputShapefileDirectory);

            if (Directory.Exists(destination))
            {
                Directory.Delete(destination, true);
            }
            Directory.CreateDirectory(destination);

            IWorkspace        outWorkspace        = GeodatabaseUtil.GetShapefileWorkspace(destination);
            IFeatureWorkspace outFeatureWorkspace = (IFeatureWorkspace)outWorkspace;
            IWorkspaceName    outWorkspaceName    = GeodatabaseUtil.GetWorkspaceName(outWorkspace);
            IFeatureClassName outFeatureclassName = GeodatabaseUtil.GetFeatureClassName(outWorkspaceName, dataset.Name);

            //ESRI.ArcGIS.ADF.Web.Geometry.Envelope envelope = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(227884.141, 4167884.377, 602406.528, 4470244.455);
            ESRI.ArcGIS.ADF.Web.Geometry.Envelope envelope = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(445092.693, 4360557.744, 541068.565, 4418287.592);

            Dictionary <int, KeyValuePair <string, IEnumInvalidObject> > invalidObjects = GeodatabaseUtil.TransferMapDataWithinExtents(map, outFeatureWorkspace, null, envelope, geoDataset.SpatialReference);
        }
Beispiel #12
0
        /// <summary>
        /// 保存mxd文档
        /// mapControl为地图控件的名称
        /// 日期2013-12-13
        /// lntu_GISer1
        /// </summary>
        public void SaveMxdFile(AxMapControl mapControl)
        {
            IMxdContents pMxdC;

            pMxdC = mapControl.ActiveView.FocusMap as IMxdContents;
            IMapDocument pMapDocument = new MapDocumentClass();

            if (mapControl.DocumentFilename != null)
            {
                pMapDocument.Open(mapControl.DocumentFilename, "");
                pMapDocument.ReplaceContents(pMxdC);
                if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename))
                {
                    MessageBox.Show("当前地图文档为只读文档!");
                    return;
                }
                try
                {
                    pMapDocument.Save(true, true);
                    MessageBox.Show("地图文档保存成功!");
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }

            //用当前的文件路径设置保存文件
        }
        /// <summary>
        /// 作用:打开TemplateMapDocument
        /// 作者:汪建龙
        /// 编写时间:2016年12月23日11:18:34
        /// </summary>
        /// <returns></returns>
        private IMapDocument OpenTemplateDocument()
        {
            try
            {
                IMapDocument tempMapDocumnet = new MapDocumentClass();
                if (!tempMapDocumnet.get_IsPresent(TemplateMxdFileName) ||
                    !tempMapDocumnet.get_IsMapDocument(TemplateMxdFileName) ||
                    tempMapDocumnet.get_IsPasswordProtected(TemplateMxdFileName) ||
                    tempMapDocumnet.get_IsRestricted(TemplateMxdFileName))
                {
                    var message = string.Format("路径:\"{0}\"下的地图文档不正确,请拷贝该文件到该路径下", _templateMxdFileName);
                    System.Diagnostics.Trace.WriteLine(message);
                    return(null);
                }

                tempMapDocumnet.Open(TemplateMxdFileName, null);

                if (tempMapDocumnet.DocumentVersion == esriMapDocumentVersionInfo.esriMapDocumentVersionInfoFail)
                {
                    var message = string.Format("路径:\"{0}\"下的地图文档版本不正确,请拷贝该文件到该路径下", TemplateMxdFileName);
                    return(null);
                }

                return(tempMapDocumnet);
            }catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex);
                return(null);
            }
        }
Beispiel #14
0
        private void menuSaveDoc_Click(object sender, EventArgs e)
        {
            //execute Save Document command
            if (m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
        }
Beispiel #15
0
        public override void OnClick()
        {
            //获得符号信息 通过mxd
            System.Windows.Forms.OpenFileDialog dir = new System.Windows.Forms.OpenFileDialog();
            dir.FileName    = "";
            dir.Filter      = "ArcGis地图文档(*.mxd)|*.mxd";
            dir.Multiselect = false;
            if (dir.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            string       strMxdPath = dir.FileName;
            IMapDocument pMapDoc    = new MapDocumentClass();

            if (!pMapDoc.get_IsMapDocument(strMxdPath))
            {
                return;
            }

            pMapDoc.Open(strMxdPath, "");

            //获得所有的符号信息 并进行序列化
            if (SaveMxdSymbolToXML(pMapDoc, System.Windows.Forms.Application.StartupPath + "\\..\\Template\\SymbolInfo.xml"))
            {
                Fan.Common.Error.ErrorHandle.ShowInform("提示", "符号信息更新成功!");
            }
            else
            {
                Fan.Common.Error.ErrorHandle.ShowInform("提示", "无法更新符号信息!");
            }
        }
Beispiel #16
0
                private void Save_Click(object sender, EventArgs e)
               
        {
                        //execute Save Document command
                            if (m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                            {
                                    //create a new instance of a MapDocument
                                    IMapDocument mapDoc = new MapDocumentClass();
                                    mapDoc.Open(m_mapDocumentName, string.Empty);

                                    //Make sure that the MapDocument is not readonly
                                        if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                    {
                                        {
                                                MessageBox.Show("Map document is read only!");

                                                mapDoc.Close();

                                                return;

                                           
                        }
                    }

                               
                }
            }

                   
        }
Beispiel #17
0
        /// <summary>
        /// Opens mxd document.
        /// </summary>
        /// <param name="sMxdFilePath">The  MXD file path.</param>
        public static void OpenDocument(string sMxdFilePath)
        {
            IMapDocument mapDocument = new MapDocumentClass();

            if (mapDocument.get_IsPresent(sMxdFilePath) && !mapDocument.get_IsPasswordProtected(sMxdFilePath))
            {
                mapDocument.Open(sMxdFilePath, "");
                try
                {
                    IMap map = mapDocument.get_Map(0);
                    mapDocument.SetActiveView((IActiveView)map);
                    //EnviVars.instance.Synchronizer.PageLayoutControl.PageLayout = mapDocument.PageLayout;
                    //EnviVars.instance.Synchronizer.ReplaceMap(map);
                    EnviVars.instance.MapControl.Map = map;
                    EnviVars.instance.MainForm.Text  = sMxdFilePath;
                }
                catch (Exception ex)
                {
                    //_logger.Log(LogLevel.Error, EventType.UserManagement, null, ex);
                    Log.WriteLog(typeof(MapAPI), ex);
                }
                finally
                {
                    mapDocument.Close();
                }
            }
        }
Beispiel #18
0
        /// <summary>
        /// 地图文档编辑过后进行保存
        /// </summary>
        private void Save_Click(object sender, EventArgs e)
        {
            //获取pMapDocument对象
            IMxdContents pMxdC;

            pMxdC = axMapControl1.Map as IMxdContents;
            IMapDocument pMapDocument = new MapDocumentClass();

            pMapDocument.Open(axMapControl1.DocumentFilename, "");
            IActiveView pActiveView = axMapControl1.Map as IActiveView;

            pMapDocument.ReplaceContents(pMxdC);
            //判断pMapDocument是否为空
            if (pMapDocument == null)
            {
                return;
            }
            //检查地图文档是否是只读
            if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
            {
                MessageBox.Show("本地图文档是只读的,不能保存!");
                return;
            }

            //根据相对的路径保存地图文档
            pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
        }
    private void menuSaveDoc_Click(object sender, EventArgs e)
    {
      //execute Save Document command
      if (m_mapControl.CheckMxFile(m_mapDocumentName))
      {
        //create a new instance of a MapDocument
        IMapDocument mapDoc = new MapDocumentClass();
        mapDoc.Open(m_mapDocumentName, string.Empty);

        //Make sure that the MapDocument is not readonly
        if (mapDoc.get_IsReadOnly(m_mapDocumentName))
        {
          MessageBox.Show("Map document is read only!");
          mapDoc.Close();
          return;
        }

        //Replace its contents with the current map
        mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

        //save the MapDocument in order to persist it
        mapDoc.Save(mapDoc.UsesRelativePaths, false);

        //close the MapDocument
        mapDoc.Close();
      }
    }
Beispiel #20
0
        public static string[] CloneMaps(int numCopies, string mxdPath)
        {
            List <string> maps     = new List <string>();
            string        testPath = Path.Combine(Path.GetDirectoryName(mxdPath), "TestMaps");

            if (System.IO.Directory.Exists(testPath))
            {
                System.IO.Directory.Delete(testPath, true);
            }

            IMapDocument srcMap = new MapDocumentClass();

            srcMap.Open(mxdPath);
            srcMap.Save(false);
            Marshal.FinalReleaseComObject(srcMap);

            System.IO.Directory.CreateDirectory(testPath);
            for (int i = 0; i < numCopies; i++)
            {
                const string fmt     = "_{0:0000}.mxd";
                string       mapName = Path.GetFileNameWithoutExtension(mxdPath) + string.Format(fmt, i + 1);
                string       mapPath = Path.Combine(testPath, mapName);
                System.IO.File.Copy(mxdPath, mapPath);
                maps.Add(mapPath);
            }

            return(maps.ToArray());
        }
Beispiel #21
0
        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)//保存mxd文档
        {
            IMxdContents pMxdC = null;

            try
            {
                pMxdC = axMapControl1.Map as IMxdContents;
                IMapDocument pMapDocument = new MapDocumentClass();
                if (axMapControl1.DocumentFilename == null)
                {
                    XtraMessageBox.Show("地图文档不存在,需新建");
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Filter = "地图文档(*.mxd)|*.mxd";
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        pMapDocument.New(saveFileDialog.FileName);
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    pMapDocument.Open(axMapControl1.DocumentFilename, "");
                }
                pMapDocument.ReplaceContents(pMxdC);
                pMapDocument.Save(true, true);
                XtraMessageBox.Show("保存成功");
            }
            catch {
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenNewMapDocument.OnClick implementation
            //launch a new OpenFile dialog
            System.Windows.Forms.OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter      = "Map Documents (*.mxd)|*.mxd";
            dlg.Multiselect = false;
            dlg.Title       = "Open Map Document";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string       docName = dlg.FileName;
                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {
                    // 以下3.3.3.1代码

                    /* pMapControl.LoadMxFile(dlg.FileName, null, null);
                     * pMapControl.ActiveView.Refresh();
                     * pMapDoc.Close();                     */
                    // 以下3.3.3.5代码
                    pMapDoc.Open(docName, string.Empty);
                    IMap map = pMapDoc.get_Map(0);
                    pMapDoc.SetActiveView((IActiveView)map);
                    pControlsSynchronizer.PageLayoutControl.PageLayout = pMapDoc.PageLayout;
                    pControlsSynchronizer.ReplaceMap(map);
                    pMapDoc.Close();
                }
            }
        }
        private void cmd_SaveDoc(System.Object sender, EventArgs e)
        {
            if (m_MapControl.CheckMxFile(m_MapControl.DocumentFilename))
            {
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_MapControl.DocumentFilename, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_MapControl.DocumentFilename))
                {
                    MessageBox.Show("地图为只读!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
        }
Beispiel #24
0
        //另存为
        public static void SaveDocAs(AxMapControl mapControl, AxPageLayoutControl pageLayoutControl = null)
        {
            IMapDocument pMapDocument = new MapDocumentClass();

            SaveFileDialog saveDlg = new SaveFileDialog();

            saveDlg.Title  = "地图文档另存为";
            saveDlg.Filter = "mxd文件|*.mxd|所有文件(添加后缀名)|*.*";
            saveDlg.ShowDialog();
            string strDocFileN = saveDlg.FileName;

            if (strDocFileN == string.Empty)
            {
                return;
            }
            pMapDocument.Open(mapControl.DocumentFilename);
            if (strDocFileN == mapControl.DocumentFilename)
            {
                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                return;
            }
            else
            {
                pMapDocument.SaveAs(strDocFileN, true, true);
                MessageBox.Show("保存成功!", "信息提示");
            }
        }
Beispiel #25
0
        /// <summary>
        /// 运用MapDocument对象中的Open方法的函数加载mxd文档
        /// </summary>
        private void loadMapDoc2()
        {
            IMapDocument mapDocument = new MapDocumentClass();

            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Title  = "打开地图文档";
                ofd.Filter = "map documents(*.mxd)|*.mxd";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string pFileName = ofd.FileName;
                    //filePath——地图文档的路径, ""——赋予默认密码
                    mapDocument.Open(pFileName, "");
                    for (int i = 0; i < mapDocument.MapCount; i++)
                    {
                        //通过get_Map(i)方法逐个加载
                        axMapControl1.Map = mapDocument.get_Map(i);
                    }
                    axMapControl1.Refresh();
                }
                else
                {
                    mapDocument = null;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Beispiel #26
0
        /// <summary>
        /// 打开本地地图
        /// </summary>
        /// <param name="mapFileName"></param>
        /// <returns></returns>
        public static IMap OpenMap(string mapFileName)
        {
            IMapDocument mapDoc = new MapDocumentClass();

            mapDoc.Open(mapFileName, "");
            return(mapDoc.get_Map(0));
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenDocument.OnClick implementation
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title  = "选择地图文档";
            dlg.Filter = "地图文档(*.mxd)|*.mxd";
            string docName = null;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                docName = dlg.FileName;
                IMapDocument mapDoc = new MapDocumentClass();
                if (mapDoc.get_IsMapDocument(docName))
                {
                    mapDoc.Open(docName, string.Empty);
                    IMap map = mapDoc.get_Map(0);
                    m_ControlsSynchronizer.ReplaceMap(map);
                    mapDoc.Close();

                    RecnetFilesList.Add(docName);
                }
                else
                {
                    MessageBox.Show("不可用的地图文档", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    RecnetFilesList.Remove(docName);
                }
            }
        }
Beispiel #28
0
        internal static IMapDocument OpenMapDocument(string path)
        {
            IMapDocument mapdoc = new MapDocumentClass();

            mapdoc.Open(path);

            return(mapdoc);
        }
Beispiel #29
0
 /// <summary>
 /// 打开地图文档并加载地图到地图控件中
 /// </summary>
 /// <returns></returns>
 public IMapDocument OpenDoc(string filePath)
 {
     MapDoc = new MapDocumentClass();
     MapDoc.Open(filePath);
     MapControl.Map = MapDoc.ActiveView.FocusMap;
     MapControl.ActiveView.Refresh();
     return(MapDoc);
 }
Beispiel #30
0
        /// <summary>
        /// 根据配置复制地图模板到生成目录或临时目录,打开复制后的地图文档
        /// </summary>
        /// <param name="cfg">导出地图配置</param>
        /// <returns></returns>
        protected virtual IMapDocument GetMapDocument(MapExportInfo cfg)
        {
            var newMxdPath = GetMxdPath(cfg);
            var mapDoc     = new MapDocumentClass();

            mapDoc.Open(newMxdPath);
            return(mapDoc);
        }
Beispiel #31
0
        private void barButtonItem25_ItemClick(object sender, ItemClickEventArgs e)
        {
            string m_currentMapDocument = axMapControl1.DocumentFilename;

            //execute Save Document command

            if (axMapControl1.CheckMxFile(m_currentMapDocument))

            {
                //create a new instance of a MapDocument

                IMapDocument mapDoc = new MapDocumentClass();

                mapDoc.Open(m_currentMapDocument, string.Empty);



                //Make sure that the MapDocument is not readonly

                if (mapDoc.get_IsReadOnly(m_currentMapDocument))

                {
                    MessageBox.Show("Map document is read only!");

                    mapDoc.Close();

                    return;
                }



                //Replace its contents with the current map

                mapDoc.ReplaceContents((IMxdContents)axMapControl1.Map);



                //save the MapDocument in order to persist it

                mapDoc.Save(mapDoc.UsesRelativePaths, false);



                //close the MapDocument

                mapDoc.Close();



                MessageBox.Show("保存地图文档成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }

            else

            {
                MessageBox.Show(m_currentMapDocument + "不是有效的地图文档!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            if (!ModMxd._MxdPath.Equals(""))
            {
                DialogResult pResult = MessageBox.Show("是否保存当前的地图文档?", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                switch (pResult)
                {
                case DialogResult.Cancel:
                    return;

                case DialogResult.Yes:
                {
                    IMxdContents pMxdC;

                    pMxdC = m_hookHelper.FocusMap as IMxdContents;

                    IMapDocument pMapDocument = new MapDocumentClass();
                    //打开地图文档
                    if (File.Exists(ModMxd._MxdPath))
                    {
                        pMapDocument.Open(ModMxd._MxdPath, "");
                    }
                    else
                    {
                        pMapDocument.New(ModMxd._MxdPath);
                    }
                    //保存信息
                    IActiveView pActiveView = m_hookHelper.ActiveView;

                    pMapDocument.ReplaceContents(pMxdC);

                    pMapDocument.Save(true, true);

                    break;
                }

                case DialogResult.No:
                    break;
                }
            }
            OpenFileDialog pOpendlg = new OpenFileDialog();

            pOpendlg.Title = "打开地图文档";

            pOpendlg.Filter = "(*.mxd)|*.mxd";
            if (pOpendlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string strMxdName = pOpendlg.FileName;

            if (m_AxMapControl.CheckMxFile(strMxdName))
            {
                m_AxMapControl.LoadMxFile(strMxdName, "", "");
            }

            ModMxd._MxdPath = strMxdName;
        }
Beispiel #33
0
        public static void CreateNewMapDocument()
        {
            IMapDocument pMapDocument   = new MapDocumentClass();
            string       sDefaultMxFile = @"D:\untitled.mxd"; pMapDocument.New(sDefaultMxFile);

            pMapDocument.Open(sDefaultMxFile);
            Form1.form1.axMapControl1.Map      = pMapDocument.get_Map(0);
            Form1.form1.axMapControl1.Map.Name = "Map";
            Form1.form1.axTOCControl1.Update();
        }
Beispiel #34
0
 /// <summary>
 /// 确定之后将文档进行默认保存
 /// </summary>
 /// <param name="mapControlDefault">当前视图mapcontrol</param>
 /// <returns></returns>
 public static bool SaveInMxd(IMapControlDefault mapControlDefault)
 {
     IMxdContents pMxdContents;
     pMxdContents = mapControlDefault.Map as IMxdContents;
     IMapDocument pMapDocument = new MapDocumentClass();
     pMapDocument.Open(mapControlDefault.DocumentFilename, "");
     pMapDocument.ReplaceContents(pMxdContents);
     try
     {
         pMapDocument.Save(true, true);
         return true;
     }
     catch
     {
         //MessageBox.Show("当前的文档文件发生共享冲突!请关闭其他打开该文档的应用。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return false;
     }
 }
        /// <summary>
        /// Called when a step of this type is executed in the workflow.
        /// </summary>
        /// <param name="JobID">ID of the job being executed</param>
        /// <param name="StepID">ID of the step being executed</param>
        /// <param name="argv">Array of arguments passed into the step's execution</param>
        /// <param name="ipFeedback">Feedback object to return status messages and files</param>
        /// <returns>Return code of execution for workflow path traversal</returns>
        public int Execute(int JobID, int stepID, ref object[] argv, ref IJTXCustomStepFeedback ipFeedback)
        {
            if (JobID <= 0)
            {
                throw new ArgumentOutOfRangeException("JobID", JobID, "Job ID must be a positive value");
            }

            try
            {
                string strTemp = "";
                bool bAttach = false;
                if (StepUtilities.GetArgument(ref argv, m_expectedArgs[1], false, out strTemp))
                {
                    bAttach = true;
                }

                string strResolution;
                if (!StepUtilities.GetArgument(ref argv, m_expectedArgs[2], false, out strResolution))
                {
                    strResolution = "1200";
                }

                int iResolution = 1200;
                if (!Int32.TryParse(strResolution, out iResolution))
                {
                    iResolution = 1200;
                }

                string outputPath = "";
                if (!bAttach)
                {
                    SaveFileDialog pSaveFileDialog = new SaveFileDialog();
                    pSaveFileDialog.Filter = "PDF files (*.pdf)|*.pdf";
                    pSaveFileDialog.Title = "Choose output location...";

                    string strInitDir = "";
                    if (StepUtilities.GetArgument(ref argv, m_expectedArgs[0], true, out strInitDir))
                    {
                        if (System.IO.Directory.Exists(strInitDir))
                        {
                            pSaveFileDialog.InitialDirectory = strInitDir;
                        }
                    }

                    if (pSaveFileDialog.ShowDialog() != DialogResult.OK)
                    {
                        return -1;
                    }

                    outputPath = pSaveFileDialog.FileName;
                }

                string inputPath = JTXUtilities.SaveJobMXD(JobID);

                if (bAttach)
                {
                    outputPath = SystemUtilities.GetTemporaryFileLocation(inputPath, "pdf");
                }

                // delete output file if it already exists
                System.IO.FileInfo fi = new System.IO.FileInfo(outputPath);
                if (fi.Exists)
                {
                    fi.Delete();
                }

                MapDocumentClass map = new MapDocumentClass();

                if (!map.get_IsMapDocument(inputPath)) throw new ApplicationException("Invalid map or specified map not found.");

                map.Open(inputPath, null);

                IActiveView pActiveView = (IActiveView)map.PageLayout;
                IExport pExport = new ExportPDFClass();

                pExport.ExportFileName = outputPath;

                tagRECT deviceFrameRect;
                deviceFrameRect.left = 0;
                deviceFrameRect.right = 800;
                deviceFrameRect.top = 0;
                deviceFrameRect.bottom = 600;

                pActiveView.ScreenDisplay.DisplayTransformation.set_DeviceFrame(ref deviceFrameRect);

                int iOutputResolution = iResolution;
                int iScreenResolution = 96;
                pExport.Resolution = iOutputResolution;
                IOutputRasterSettings pOutputRasterSettings = (IOutputRasterSettings)pExport;
                pOutputRasterSettings.ResampleRatio = 1;

                tagRECT exportRect;

                exportRect.left = pActiveView.ExportFrame.left * (iOutputResolution / iScreenResolution);
                exportRect.top = pActiveView.ExportFrame.top * (iOutputResolution / iScreenResolution);
                exportRect.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution);
                exportRect.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution);

                IEnvelope pPixelBoundsEnv = new EnvelopeClass();

                pPixelBoundsEnv.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom);
                pExport.PixelBounds = pPixelBoundsEnv;

                int hdc = pExport.StartExporting();
                pActiveView.Output(hdc, iOutputResolution, ref exportRect, null, null);
                pExport.FinishExporting();
                pExport.Cleanup();

                if (bAttach)
                {
                    JTXUtilities.AddAttachmentToJob(JobID, outputPath, jtxFileStorageType.jtxStoreInDB);
                }

                return 0;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 private void btnWebMap_Click(object sender, EventArgs e)
 {
   if (!(IsConnected()))
   {
     // Since Web Maps require and internet connection anyways
     // just fail if there isn't one.
     MessageBox.Show("Cannot Connect to ArcGIS.com!", "Failed to open Web Map.", MessageBoxButtons.OK, MessageBoxIcon.Error);
     return;
   }
   try
   {
     IMapDocument mapDocument = new MapDocumentClass();
     string webMapMxd = webMapLocation + @"\" + myWebMapName + @"\" + myWebMapName + ".mxd";
     if (File.Exists(webMapMxd))
       mapDocument.Open(webMapMxd, "");
     else
       mapDocument.Open(txtWebMap.Text, "");
     axMapControl1.Map = mapDocument.get_Map(0);
   }
   catch (Exception ex)
   {
     MessageBox.Show("Failed to open Web Map!", ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
   }
 }
Beispiel #37
0
        void IGMap.SaveMxd()
        {
            if (this._mapHook.CheckMxFile(this._mapHook.DocumentFilename))
            {
                //string a=((IMapDocument)this._mapHook).DocumentFilename;
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(this._mapHook.DocumentFilename, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(this._mapHook.DocumentFilename))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)this._mapHook.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
        }
Beispiel #38
0
        protected void OpenPastureMapDoc(Pasture pasture)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(pasture.strMapDoc) &&
                !mapDoc.get_IsPasswordProtected(pasture.strMapDoc))
            {
                mapDoc.Open(pasture.strMapDoc, string.Empty);

                // set the first map as the active view
                m_pastureMap = mapDoc.get_Map(0);
                mapDoc.SetActiveView((IActiveView)m_pastureMap);
                mapDoc.Close();
            }
        }
Beispiel #39
0
        static void Main(string[] args)
        {
            bool showHelp = false;
            bool gzip = false;
            bool overwrite = false;
            bool verbose = false;
            string destination = ".";
            int[] levels = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
            HashSet<string> fields = null;
            int threadCount = System.Environment.ProcessorCount;

            OptionSet p = new OptionSet() {
                { "d|dir=", "destination directory (defaults to current directory)", d => destination = d },
                { "l|levels=",
                  "list of scale levels [0-19], separated by commas",
                  l => levels = l.Split(new char[] { ',' }).Select(s => Convert.ToInt32(s)).ToArray() },
                { "f|fields=",
                  "list of field names to include in UTFGrid data",
                  f => fields = new HashSet<string>(f.Split(new char[] { ',' })) },
                { "t|threads=",
                  "number of threads to use (defaults to number of processors)",
                  t => threadCount = Convert.ToInt32(t) },
                { "z|zip",  "zip the json files using gzip compression before saving", z => gzip = z != null },
                { "o|overwrite", "overwrite existing files", o => overwrite = o != null },
                { "v|verbose", "verbose output", v => verbose = v != null },
                { "h|help",  "show this message and exit", h => showHelp = h != null }
            };
            List<string> extra;
            try {
                extra = p.Parse(args);
            } catch (OptionException e) {
                Console.Write("utfgrid");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `utfgrid --help' for more information.");
                return;
            }
            if (showHelp) {
                Console.WriteLine("Usage: utfgrid [OPTIONS]+ mxd_document");
                Console.WriteLine("Generate UTFGrid files from the given map document");
                Console.WriteLine();
                Console.WriteLine("Options:");
                p.WriteOptionDescriptions(Console.Out);
                return;
            } else if (extra.Count < 1) {
                Console.WriteLine("utfgrid: no map document specified");
                Console.WriteLine("Try `utfgrid --help' for more information.");
                return;
            }
            RuntimeManager.BindLicense(ProductCode.EngineOrDesktop);

            IMap map = null;
            try {
                IMapDocument mapDocument = new MapDocumentClass();
                mapDocument.Open(extra[0], null);
                map = mapDocument.ActiveView as IMap;
                if (map == null) {
                    map = mapDocument.get_Map(0);
                }
                mapDocument.Close();
            } catch (Exception) { }
            if (map == null) {
                Console.WriteLine("Unable to open map at " + extra[0]);
                return;
            }
            if ((map.SpatialReference.FactoryCode != 102113) &&
                (map.SpatialReference.FactoryCode != 102100) &&
                (map.SpatialReference.FactoryCode != 3785)) {
                Console.WriteLine("Spatial reference of map must be Web Mercator (is " + map.SpatialReference.FactoryCode + ")");
                return;
            }

            IActiveView activeView = map as IActiveView;
            // get the extent from the active view
            IEnvelope fullExtent = activeView.FullExtent;

            Console.WriteLine("starting utfgrid generator with " + threadCount + " threads");

            UTFGridGeneratorConfig config = new UTFGridGeneratorConfig(extra[0], DescribeTiles(levels, activeView.FullExtent));
            config.GZip = gzip;
            config.Overwrite = overwrite;
            config.Verbose = verbose;
            config.Destination = destination;

            Thread[] workerThreads = new Thread[threadCount];

            for (int i = 0; i < threadCount; i++) {
                workerThreads[i] = new Thread(new ParameterizedThreadStart(UTFGridGenerator.Execute));
                workerThreads[i].SetApartmentState(ApartmentState.STA);
                workerThreads[i].IsBackground = true;
                workerThreads[i].Priority = ThreadPriority.BelowNormal;
                workerThreads[i].Name = "UTFGridGenerator " + (i + 1).ToString();
                workerThreads[i].Start(config);
            }

            foreach (Thread t in workerThreads) {
                t.Join();
            }
            workerThreads = null;
        }
Beispiel #40
0
        /// <summary>
        /// 保存mxd文档
        /// mapControl为地图控件的名称
        /// 日期2013-12-13
        /// lntu_GISer1
        /// </summary>
        public void SaveMxdFile(AxMapControl mapControl)
        {
            IMxdContents pMxdC;
             pMxdC = mapControl.ActiveView.FocusMap as IMxdContents;
             IMapDocument pMapDocument = new MapDocumentClass();
             if (mapControl.DocumentFilename != null)
             {
                 pMapDocument.Open(mapControl.DocumentFilename, "");
                 pMapDocument.ReplaceContents(pMxdC);
                 if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename))
                 {

                     MessageBox.Show("当前地图文档为只读文档!");
                     return;
                 }
                 try
                 {
                     pMapDocument.Save(true, true);
                     MessageBox.Show("地图文档保存成功!");
                 }
                 catch (Exception e)
                 {
                     MessageBox.Show(e.Message);
                 }
             }

             //用当前的文件路径设置保存文件
        }
Beispiel #41
0
        /// <summary>
        /// 新建mxd文档
        /// 参数path为创建mxd文件的路径+名称
        /// 参数mapControl为调用该dll项目的地图控件
        /// 日期2013-12-13
        /// lntu_GISer1
        /// </summary>
        public string NewMxdFile(string path,AxMapControl mapControl)
        {
            try
            {
                string filename =newfileDialog(path);
                if (filename != "")
                {
                        MapDocument pMapDocument = new MapDocumentClass();
                        pMapDocument.New(filename);
                        pMapDocument.Open(filename, "");

                }
                return filename;
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message);
                return "";
            }
        }
Beispiel #42
0
        public static void SaveDocument2(AxMapControl axMapControl1)
        {
            try
            {

                //判断pMapDocument是否为空,

                //获取pMapDocument对象

                IMxdContents pMxdC;

                pMxdC = axMapControl1.Map as IMxdContents;

                IMapDocument pMapDocument = new MapDocumentClass();

                pMapDocument.Open(axMapControl1.DocumentFilename, "");

                IActiveView pActiveView = axMapControl1.Map as IActiveView;

                pMapDocument.ReplaceContents(pMxdC);

                if (pMapDocument == null) return;

                //检查地图文档是否是只读

                if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
                {

                    MessageBox.Show("本地图文档是只读的,不能保存!");

                    return;

                }

                //根据相对的路径保存地图文档

                pMapDocument.Save(pMapDocument.UsesRelativePaths, true);

                MessageBox.Show("地图文档保存成功!");

            }

            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);

            }
        }
Beispiel #43
0
 /// <summary>
 /// 
 /// </summary>
 private void saveMapDocument(AxMapControl pAxMapControl)
 {
     IMxdContents pMxdC;
     pMxdC = pAxMapControl.Map as IMxdContents;
     IMapDocument pMapDocument = new MapDocumentClass();
     pMapDocument.Open(pAxMapControl.DocumentFilename, "");
     IActiveView pActiveView = pAxMapControl.Map as IActiveView;
     pMapDocument.ReplaceContents(pMxdC);
     if (pMapDocument == null) return;
     //检查地图文档是否是只读
     if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true)
     {
         MessageBox.Show("本地图文档是只读的,不能保存!");
         return;
     }
     //根据相对的路径保存地图文档
     pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
     MessageBox.Show("地图文档保存成功!");
 }
Beispiel #44
0
        protected void OpenAdministrativeMapDoc(string adminMapDoc)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(adminMapDoc) &&
                !mapDoc.get_IsPasswordProtected(adminMapDoc))
            {
                mapDoc.Open(adminMapDoc, string.Empty);

                // set the first map as the active view
                m_adminMap = mapDoc.get_Map(0);
                mapDoc.SetActiveView((IActiveView)m_adminMap);
                mapDoc.Close();

                m_mapcontrol.Map = m_adminMap;
            }
        }
    /// <summary>
    /// Occurs when this command is clicked
    /// </summary>
    public override void OnClick()
    {
      //launch a new OpenFile dialog
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Filter = "Map Documents (*.mxd)|*.mxd";
      dlg.Multiselect = false;
      dlg.Title = "Open Map Document";
      if (dlg.ShowDialog() == DialogResult.OK)
      {
        string docName = dlg.FileName;

        IMapDocument mapDoc = new MapDocumentClass();
        if (mapDoc.get_IsPresent(docName) && !mapDoc.get_IsPasswordProtected(docName))
        {
          mapDoc.Open(docName, string.Empty);

          // set the first map as the active view
          IMap map = mapDoc.get_Map(0);
          mapDoc.SetActiveView((IActiveView)map);

          m_controlsSynchronizer.PageLayoutControl.PageLayout = mapDoc.PageLayout;

          m_controlsSynchronizer.ReplaceMap(map);

          mapDoc.Close();

          m_sDocumentPath = docName;
        }
      }
    }
    /// <summary>
    /// Save document menu event handler
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <remarks>Save the current MapDocument</remarks>
    private void menuSaveDoc_Click(object sender, System.EventArgs e)
    {
      //make sure that the current MapDoc is valid first
      if (m_documentFileName != string.Empty && m_mapControl.CheckMxFile(m_documentFileName))
      {
        //create a new instance of a MapDocument class
        IMapDocument mapDoc = new MapDocumentClass();
        //Open the current document into the MapDocument
        mapDoc.Open(m_documentFileName, string.Empty);

        //Replace the map with the one of the PageLayout
        mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout);

        //save the document
        mapDoc.Save(mapDoc.UsesRelativePaths, false);
        mapDoc.Close();
      }
    }
        private void MainForm_OP_Load(object sender, EventArgs e)
        {
            IMapDocument pMapDocument = new MapDocumentClass();
            pMapDocument.Open(ConfigHelper.get_attribute("mxd_path"));
            mapControl_OP.LoadMxFile(ConfigHelper.get_attribute("mxd_path"));

            statusStrip1.AxMap = mapControl_OP;
            m_FileMenu.AxMapControl = mapControl_OP; //传入MapControl控件
            var mapControl = (IMapControl3)mapControl_OP.Object;
            var toolbarControl = (IToolbarControl)toolbar_OP.Object;
            //绑定控件
            toolbar_OP.SetBuddyControl(mapControl);
            tocControl_OP.SetBuddyControl(mapControl);
            //给全局变量赋值
            DataEditCommon.g_tbCtlEdit = toolbarControl;
            DataEditCommon.g_pAxMapControl = mapControl_OP;
            DataEditCommon.g_axTocControl = tocControl_OP;
            DataEditCommon.load(ConfigHelper.current_seam.gis_name);

            IEnumDataset pEnumDataSet =
             DataEditCommon.g_pCurrentWorkSpace.Datasets[esriDatasetType.esriDTFeatureDataset];
            IDataset pDataSet = pEnumDataSet.Next();
            ISpatialReference pRef = (pDataSet as IGeoDataset).SpatialReference;
            string sDistrictCode = string.Empty;
            string sScale = string.Empty;

            //if (pDataSet != null)
            //{
            //    UID uid = new UIDClass();
            //    uid.Value = "{" + typeof(IFeatureLayer).GUID.ToString() + "}";
            //    IEnumLayer pEnumLayer = mapControl_OP.Map.Layers[uid];
            //    IFeatureLayer pFeaLyr = pEnumLayer.Next() as IFeatureLayer;
            //    IFeatureWorkspace pFeaClsWks = DataEditCommon.g_pCurrentWorkSpace as IFeatureWorkspace;
            //    while (pFeaLyr != null)
            //    {
            //        string sDsName = ((pFeaLyr as IDataLayer).DataSourceName as IDatasetName).Name;
            //        if ((DataEditCommon.g_pCurrentWorkSpace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, sDsName))
            //        {
            //            pFeaLyr.FeatureClass = pFeaClsWks.OpenFeatureClass(sDsName);
            //            pFeaLyr.Name = pFeaLyr.Name;
            //        }

            //        pFeaLyr = pEnumLayer.Next() as IFeatureLayer;
            //    }
            //    ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(DataEditCommon.g_pCurrentWorkSpace);
            //    ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pFeaClsWks);
            //    mapControl_OP.Map.SpatialReference = pRef;
            //    IMxdContents pMxdC;
            //    pMxdC = mapControl_OP.Map as IMxdContents;
            //    pMapDocument.Open(ConfigHelper.GetAttribute("mxd_path"));
            //    pMapDocument.ReplaceContents(pMxdC);
            //    pMapDocument.Save(true, true);
            //}

            AddToolBar.Addtool(mapControl_OP, mapControl, toolbarControl, DataEditCommon.g_pCurrentWorkSpace);
        }
Beispiel #48
0
        // File menu items
        void fileToolStripMenuItems_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = sender as ToolStripMenuItem;
            if (menuItem == null)
                return;
            ICommand command = null;
            string itemName = menuItem.Name;
            switch (itemName)
            {
                case "newDocToolStripMenuItem":
                    command = new CreateNewDocCmd();
                    command.OnCreate(m_MapControl.Object);
                    command.OnClick();
                    break;
                case "openDocToolStripMenuItem":
                    command = new ControlsOpenDocCommandClass();
                    command.OnCreate(m_MapControl.Object);
                    command.OnClick();
                    break;
                case "saveasStripMenuItem":
                    command = new ControlsSaveAsDocCommandClass();
                    command.OnCreate(m_MapControl.Object);
                    command.OnClick();
                    break;
                case "saveDocToolStripMenuItem":
                    if (m_MapControl.CheckMxFile(m_DocmentFileName))
                    {
                        IMapDocument mapDoc = new MapDocumentClass();
                        mapDoc.Open(m_DocmentFileName, string.Empty);
                        if (!mapDoc.get_IsReadOnly(m_DocmentFileName))
                        {
                            mapDoc.ReplaceContents((IMxdContents)m_MapControl.Map);
                            mapDoc.Save(mapDoc.UsesRelativePaths, false);
                            mapDoc.Close();
                        }
                        else
                            MessageBox.Show("Cann't be save because of read-only document");
                    }
                    break;
                case "exitDocToolStripMenuItem":
                    DialogResult res = MessageBox.Show("Whether to save the current document?", "AOView", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    if (res == DialogResult.Yes)
                    {
                        command = new ControlsSaveAsDocCommandClass();
                        command.OnCreate(axMapControl1.Object);
                        command.OnClick();
                    }
                    Application.Exit();
                    break;

                default:
                    break;
            }
        }
Beispiel #49
0
        /// <summary>
        /// 生成MXD,并将数据库重置
        /// </summary>
        /// <returns></returns>
        public bool CreateMXD()
        {
            try
            {
                string strMxdFile = GetMXDFile();
                File.Copy(System.Windows.Forms.Application.StartupPath + "\\" + COMMONCONST.RelativePath_MXD +"\\"+ this.StandardName + ".MXD", strMxdFile);
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(strMxdFile, null);

                // 重定向数据库
                IMap mapTarget = mapDoc.get_Map(0);
                Hy.Common.Utility.Esri.AEAccessFactory.ResetMapWorkspace(this.BaseWorkspace, mapTarget);
                // 修改空间参考及范围
                IEnumDataset enDataset = this.BaseWorkspace.get_Datasets(esriDatasetType.esriDTAny);
                IDataset dataset = enDataset.Next();
                double xMin=double.MaxValue, xMax=double.MinValue, yMin=double.MaxValue, yMax=double.MinValue;
                IEnvelope envExtent = null;
                ISpatialReference spatialRef = null;
                while (dataset != null)
                {
                    IGeoDataset geoDataset = dataset as IGeoDataset;
                    if (geoDataset != null)
                    {
                        //mapTarget.SpatialReference = geoDataset.SpatialReference;
                        //mapDoc.ActiveView.Extent.SpatialReference = geoDataset.SpatialReference;
                        //mapDoc.ActiveView.Extent = geoDataset.Extent;
                        //mapDoc.ActiveView.FullExtent.SpatialReference = geoDataset.SpatialReference;
                        //mapDoc.ActiveView.FullExtent = geoDataset.Extent;

                        spatialRef = geoDataset.SpatialReference;
                        envExtent = geoDataset.Extent;
                        if (!envExtent.IsEmpty)
                        {

                            if (xMin > envExtent.XMin) xMin = envExtent.XMin;
                            if (yMin > envExtent.YMin) yMin = envExtent.YMin;
                            if (xMax < envExtent.XMax) xMax = envExtent.XMax;
                            if (yMax < envExtent.YMax) yMax = envExtent.YMax;
                        }
                        //break;
                    }
                    dataset = enDataset.Next();
                }
                mapTarget.SpatialReference = spatialRef;
                envExtent.PutCoords(xMin, yMin, xMax, yMax);
                //mapTarget.RecalcFullExtent();
                mapDoc.ActiveView.Extent = envExtent;
                mapDoc.ActiveView.FullExtent = envExtent;
                (mapTarget as IActiveView).FullExtent = envExtent;

                mapDoc.Save(true, false);
                mapDoc.Close();

                // 再复制 “任务执行格式验证.xsd”文件
                File.Copy(System.Windows.Forms.Application.StartupPath + "\\" + COMMONCONST.RelativePath_MXD + "\\" + COMMONCONST.File_Name_XSD, GetTaskFolder() + "\\" + COMMONCONST.File_Name_XSD);
                return true;
            }
            catch (Exception exp)
            {
                SendMessage(enumMessageType.Exception, "生成MXD失败,错误信息:" + exp.Message);
                return false;
            }
        }
Beispiel #50
0
        public override bool LoadMap(string filePath)
        {
            IMapDocument mapDoc = new MapDocumentClass();
            if (mapDoc.get_IsPresent(filePath) && !mapDoc.get_IsPasswordProtected(filePath))
            {
                mapDoc.Open(filePath, string.Empty);
                // set the first map as the active view
                IMap map = mapDoc.get_Map(0);
                mapDoc.SetActiveView((IActiveView)map);
                this._axLayoutCtrl.PageLayout = mapDoc.PageLayout;
                this._mapAndLayoutSync.ReplaceMap(map);
                mapDoc.Close();
                this._mapFile = filePath;
                return true;
            }
            else
            {
                return false;
            }

            /*
            if (this._axMapCtrl.CheckMxFile(filePath))
            {
                


                this._axMapCtrl.LoadMxFile(filePath, Type.Missing, Type.Missing);
                this._axMapCtrl.Enabled = true;
                this._mapFile = filePath;
                return true;
            }
            else
            {
                return false;
            }
            */ 
        }
        public void OnClick()
        {
            //// 首先确认当前地图文档是否有效
            //if (null != m_pageLayoutControl.DocumentFilename && m_mapControl.CheckMxFile(m_pageLayoutControl.DocumentFilename))
            //{
            //// 创建一个新的地图文档实例
            //IMapDocument mapDoc = new MapDocumentClass();  // 打开当前地图文档
            //mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty);  // 用 PageLayout 中的文档替换当前文档中的 PageLayout 部分
            //mapDoc.ReplaceContents((IMxdContents)m_pageLayoutControl.PageLayout);  // 保存地图文档
            //mapDoc.Save(mapDoc.UsesRelativePaths, false);
            //mapDoc.Close();

            //m_mapDocument = this.hk.Document;
            //if (m_mapDocument.get_IsReadOnly(m_mapDocument.DocumentFilename))
            //{
            //    MessageBox.Show("This map document is read only!");
            //    return;
            //}
            //m_mapDocument.Save(m_mapDocument.UsesRelativePaths, true);
            //MessageBox.Show("Changes saved successfully!");

            //execute Save Document command
            //m_mapDocumentName = m_mapControl.DocumentFilename;
            if (m_mapControl.DocumentFilename != null && m_mapControl.CheckMxFile(m_mapDocumentName))
            {
                //m_mapControl.CheckMxFile(m_mapDocumentName);
                //create a new instance of a MapDocument
                IMapDocument mapDoc = new MapDocumentClass();
                mapDoc.Open(m_mapDocumentName, string.Empty);

                //Make sure that the MapDocument is not readonly
                if (mapDoc.get_IsReadOnly(m_mapDocumentName))
                {
                    MessageBox.Show("Map document is read only!");
                    mapDoc.Close();
                    return;
                }

                //Replace its contents with the current map
                mapDoc.ReplaceContents((IMxdContents)m_mapControl.Map);

                //save the MapDocument in order to persist it
                mapDoc.Save(mapDoc.UsesRelativePaths, false);

                //close the MapDocument
                mapDoc.Close();
            }
            else {
                cmd = new ControlsSaveAsDocCommandClass();
                cmd.OnCreate(this.m_mapControl);
                cmd.OnClick();
            }
        }
 private void Form1_Load(object sender, EventArgs e)
 {
     IMapDocument imapDocument = new MapDocumentClass();
     imapDocument.Open(@"C:\Users\huty\Desktop\武汉实习数据\wuhan.mxd", "");
     for (int i = 0; i <= imapDocument.MapCount - 1; i++)
     {
         axMapControl1.Map = imapDocument.get_Map(i);//axMapControl1为MapControl的自动对象
     }
     IGraphicsContainer pgraghicscontainer = axMapControl1.Map as IGraphicsContainer;
     IActiveView pactiveview = pgraghicscontainer as IActiveView;
     axMapControl1.Extent = pactiveview.FullExtent;
     pactiveview.Refresh();
     axMapControl2.AddLayer(mainroadlayer);
     axMapControl2.AddLayer(secondroadlayer);
     axMapControl2.AddLayer(waterregionlayer);
     double scale = axMapControl1.ActiveView.FocusMap.MapScale;
     string a = scale.ToString("#0.00");
     this.scaletextbox.Text = "1:" + a;
     clsload();
     this.select.Checked = true;
 }
Beispiel #53
0
 void IGMap.CloseMxd()
 {
     IMapDocument mapDoc = new MapDocumentClass();
     mapDoc.Open(this._mapHook.DocumentFilename, string.Empty);
     mapDoc.Close();
 }
        private void MainForm_GM_Load(object sender, EventArgs e)
        {
            IMapDocument pMapDocument = new MapDocumentClass();
            pMapDocument.Open(ConfigHelper.current_seam.mxd_name);
            mapControl_GM.LoadMxFile(ConfigHelper.current_seam.mxd_name);
            //this.mapControl_GM.LoadMxFile(Application.StartupPath + "\\local.mxd");
            Log.Debug("[GM]....Finished to load MXD file.....");
            statusStrip1.AxMap = mapControl_GM;
            m_FileMenu.AxMapControl = mapControl_GM; //传入MapControl控件

            //加载数据
            var mapControl = (IMapControl3)mapControl_GM.Object;
            var toolbarControl = (IToolbarControl)toolBar_GM.Object;

            //绑定控件
            toolBar_GM.SetBuddyControl(mapControl);
            tocControl_GM.SetBuddyControl(mapControl);

            //给全局变量赋值
            DataEditCommon.g_tbCtlEdit = toolbarControl;
            DataEditCommon.g_pAxMapControl = mapControl_GM;
            DataEditCommon.g_axTocControl = tocControl_GM;
            DataEditCommon.load(ConfigHelper.current_seam.gis_name);

            IEnumDataset pEnumDataSet =
                DataEditCommon.g_pCurrentWorkSpace.Datasets[esriDatasetType.esriDTFeatureDataset];
            IDataset pDataSet = pEnumDataSet.Next();
            ISpatialReference pRef = (pDataSet as IGeoDataset).SpatialReference;
            string sDistrictCode = string.Empty;
            string sScale = string.Empty;

            //if (pDataSet != null)
            //{
            //    UID uid = new UIDClass();
            //    uid.Value = "{" + typeof(IFeatureLayer).GUID.ToString() + "}";
            //    IEnumLayer pEnumLayer = mapControl_GM.Map.Layers[uid];
            //    IFeatureLayer pFeaLyr = pEnumLayer.Next() as IFeatureLayer;
            //    IFeatureWorkspace pFeaClsWks = DataEditCommon.g_pCurrentWorkSpace as IFeatureWorkspace;
            //    while (pFeaLyr != null)
            //    {
            //        string sDsName = ((pFeaLyr as IDataLayer).DataSourceName as IDatasetName).Name;
            //        if ((DataEditCommon.g_pCurrentWorkSpace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, sDsName))
            //        {
            //            pFeaLyr.FeatureClass = pFeaClsWks.OpenFeatureClass(sDsName);
            //            pFeaLyr.Name = pFeaLyr.Name;
            //        }

            //        pFeaLyr = pEnumLayer.Next() as IFeatureLayer;
            //    }
            //    ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(DataEditCommon.g_pCurrentWorkSpace);
            //    ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(pFeaClsWks);
            //    mapControl_GM.Map.SpatialReference = pRef;
            //    IMxdContents pMxdC;
            //    pMxdC = mapControl_GM.Map as IMxdContents;
            //    pMapDocument.Open(ConfigHelper.current_seam.mxd_name);
            //    pMapDocument.ReplaceContents(pMxdC);
            //    pMapDocument.Save(true, true);
            //}

            AddToolBar.Addtool(mapControl_GM, mapControl, toolbarControl, DataEditCommon.g_pCurrentWorkSpace);

            //给GIS工程的全局变量赋值
            Global.SetInitialParams(mapControl_GM.ActiveView);
        }
Beispiel #55
0
        public void FetchLayers(object a)
        {
            Status = "Fetching...";
            IMapDocument pMapDoc = new MapDocumentClass();
            try
            {
                pMapDoc.Open(MxdInfo.FullName);
                IDocumentInfo2 pDocInfo = (IDocumentInfo2)pMapDoc;
                var map = pMapDoc.get_Map(0);
                var count = map.LayerCount;
                for (int i = 0; i < map.LayerCount; i++)
                {
                    ILayer layer = (ILayer)map.get_Layer(i);
                    try
                    {
                        IDataLayer2 dataLayer = (IDataLayer2)layer;
                        IDatasetName name = (IDatasetName)dataLayer.DataSourceName;
                        IWorkspaceName workspace = name.WorkspaceName;
                        IPropertySet propSet = workspace.ConnectionProperties;
                        object obj1 = new object[1];
                        object obj2 = new object[1];
                        propSet.GetAllProperties(out obj1, out obj2);

                        object[] array1 = (object[])obj1;
                        object[] array2 = (object[])obj2;

                        _knownLayers.Add(new LayerEntry(layer.Name, array2[0].ToString(), MxdInfo.Name));
                        Status = string.Format("Found {0}/{1}", (i + 1), count);
                        FetchLayersEvent();
                    }
                    catch (Exception e)
                    {
                        _knownLayers.Add(new LayerEntry(layer.Name, "Unknown - not a feature layer", MxdInfo.Name));
                        Status = string.Format("Found {0}/{1}", (i + 1), count);
                        FetchLayersEvent();
                    }
                }
            }
            catch (Exception e)
            {
                Status = "An error occurred";
            }
            finally
            {
                pMapDoc.Close();
                FetchLayersEvent();
            }
        }
    private void btnLoadmpk_Click(object sender, EventArgs e)
    {
      try
      {
        IMapDocument mapDocument = new MapDocumentClass();
        if (IsConnected())
        {
          mapDocument.Open(txtMapPackage.Text, "");
        }
        else
        {
          if (DoesPackageExist(PackageType.MapPackage))
          {
            mapDocument.Open(packageLocation, "");
          }

        }
        axMapControl1.Map = mapDocument.get_Map(0);
      }
      catch (Exception ex)
      {
        MessageBox.Show("Failed to open Map Package!", ex.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
    }