Example #1
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();
            }
        }
Example #2
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);
        }
Example #3
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);
                }
            }
        }
Example #4
0
 private void 保存SToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (axMapControl1.DocumentMap == null)
     {
         MessageBox.Show("地图文档不能为空", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
     else
     {
         try
         {
             IMapDocument pMapDocument = new MapDocumentClass();
             string       saveFileName = axMapControl1.DocumentFilename;
             IMxdContents pMxdcontents = axMapControl1.Map as IMxdContents;
             pMapDocument.New(saveFileName);
             pMapDocument.ReplaceContents(pMxdcontents);
             if (pMapDocument.get_IsReadOnly(saveFileName))
             {
                 MessageBox.Show("本地图文档只读的,不能保存!");
             }
             else
             {
                 pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                 MessageBox.Show("保存地图文档成功!");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Example #5
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;
                }
            }
        }
Example #6
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();
                }
            }
        }
Example #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();
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenMxdCommand.OnClick implementation

            //launch a new OpenFile dialog
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();

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

                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {
                    pMapControl.LoadMxFile(pOpenFileDialog.FileName, null, null);

                    // set the first map as the active view

                    pMapControl.ActiveView.Refresh();

                    pMapDoc.Close();
                }
            }
        }
 //保存地图文档
 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();
     }
 }
Example #10
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;

                                           
                        }
                    }

                               
                }
            }

                   
        }
Example #11
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();
            }
        }
Example #12
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();
        }
        /// <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);
                }
            }
        }
Example #14
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);
        }
Example #15
0
        private void SaveDoc_Click(object sender, EventArgs e)
        {
            string       sMxdFileName = axMapControl1.DocumentFilename;
            IMapDocument pMapDocument = new MapDocumentClass();

            if (axMapControl1.LayerCount == 0)
            {
                MessageBox.Show("地图文档为空,请先加载地图文档!");
            }
            else
            {
                try
                {
                    pMapDocument.New(sMxdFileName);
                    pMapDocument.ReplaceContents((IMxdContents)axMapControl1.Map as IMxdContents);
                    pMapDocument.Save(pMapDocument.UsesRelativePaths, true);
                    pMapDocument.Close();
                    MessageBox.Show("保存地图文档成功!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("保存地图文档失败!" + ex.ToString());
                }
            }
        }
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add OpenMxdCommand.OnClick implementation

            //launch a new OpenFile dialog
            OpenFileDialog pOpenFileDialog = new OpenFileDialog();
            pOpenFileDialog.Filter = "Map Documents (*.mxd)|*.mxd";
            pOpenFileDialog.Multiselect = false;
            pOpenFileDialog.Title = "Open Map Document";
            if (pOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string docName = pOpenFileDialog.FileName;

                IMapDocument pMapDoc = new MapDocumentClass();
                if (pMapDoc.get_IsPresent(docName) && !pMapDoc.get_IsPasswordProtected(docName))
                {

                    pMapControl.LoadMxFile(pOpenFileDialog.FileName, null, null);

                    // set the first map as the active view

                    pMapControl.ActiveView.Refresh();

                    pMapDoc.Close();

                }
            }
        }
Example #17
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);
            }
        }
Example #18
0
        /// <summary>
        /// 工程另存为
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void iSaveProjectAs_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //ESRI.ArcGIS.SystemUI.ICommand saveCommand = new ControlsSaveAsDocCommand();
            //saveCommand.OnCreate(m_mapControl.Object);
            //saveCommand.OnClick();

            IMapDocument   pMapDocument = new MapDocumentClass();
            SaveFileDialog opensavemxd  = new SaveFileDialog();

            opensavemxd.Filter = "地图文档(*.mxd)|*.mxd"; //对话框的过滤器
            if (opensavemxd.ShowDialog() == DialogResult.OK)
            {
                string filePath = opensavemxd.FileName; //获取文件全路径
                pMapDocument.New(filePath);
                IMxdContents pMxdC = m_mapControl.Map as IMxdContents;
                pMapDocument.ReplaceContents(pMxdC);
                pMapDocument.Save(true, false);
                m_mapControl.LoadMxFile(filePath, 0, Type.Missing);
                //循环遍历所有的地图
                for (int i = 0; i < pMapDocument.MapCount; i++)
                {
                    m_mapControl.Map = pMapDocument.get_Map(i); //绑定地图控件
                }
                pMapDocument.Close();
            }
        }
 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);
     }
 }
        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();
            }
        }
Example #21
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);
            }
        }
        //另存为地图文档
        private void barButtonItem27_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                SaveFileDialog pSaveFileDialog = new SaveFileDialog();
                pSaveFileDialog.Title            = "另存为";
                pSaveFileDialog.OverwritePrompt  = true;
                pSaveFileDialog.Filter           = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt";
                pSaveFileDialog.RestoreDirectory = true;
                if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string sFilePath = pSaveFileDialog.FileName;

                    IMapDocument pMapDocument = new MapDocumentClass();
                    pMapDocument.New(sFilePath);
                    pMapDocument.ReplaceContents(Variable.pMapFrm.mainMapControl.Map as IMxdContents);
                    pMapDocument.Save(true, true);
                    pMapDocument.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "/n" + ex.ToString(), "异常");
            }
        }
Example #23
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());
        }
    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();
      }
    }
Example #25
0
        private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog pSaveFileDialog = new SaveFileDialog();
                pSaveFileDialog.Title            = "另存为";
                pSaveFileDialog.OverwritePrompt  = true;
                pSaveFileDialog.Filter           = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt";
                pSaveFileDialog.RestoreDirectory = true;
                if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string sFilePath = pSaveFileDialog.FileName;

                    IMapDocument pMapDocument = new MapDocumentClass();
                    pMapDocument.New(sFilePath);
                    pMapDocument.ReplaceContents(axMapControl1.Map as IMxdContents);
                    pMapDocument.Save(true, true);
                    pMapDocument.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #26
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("保存成功!", "信息提示");
            }
        }
Example #27
0
 private void SaveAsItem_Click(object sender, EventArgs e)
 {
     try
     {
         SaveFileDialog dlg = new SaveFileDialog();
         dlg.RestoreDirectory = true;
         dlg.Filter           = "地图文档(*.mxd)|*.mxd";
         dlg.AddExtension     = true;
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             string mxdpath = dlg.FileName;
             if (string.IsNullOrEmpty(mxdpath))
             {
                 return;
             }
             IMapDocument mapDoc = new MapDocumentClass();
             mapDoc.New(mxdpath);
             mapDoc.ReplaceContents(this.axMapcontrol.Map as IMxdContents);
             mapDoc.Save(true, true);
             mapDoc.Close();
             MessageBox.Show("保存成功");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("保存失败" + ex.Message);
     }
 }
Example #28
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 {
            }
        }
Example #29
0
        public static void SaveDocumentAs()
        {
            try
            {
                SaveFileDialog pSaveFileDialog = new SaveFileDialog
                {
                    Title            = "另存为",
                    OverwritePrompt  = true,
                    Filter           = "ArcMap文档(*.mxd)|*.mxd|ArcMap模板(*.mxt)|*.mxt",
                    RestoreDirectory = true
                };
                if (pSaveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    string sFilePath = pSaveFileDialog.FileName;

                    IMapDocument pMapDocument = new MapDocumentClass();
                    pMapDocument.New(sFilePath);
                    pMapDocument.ReplaceContents(Form1.form1.axMapControl1.Map as IMxdContents);
                    pMapDocument.Save(true, true);
                    pMapDocument.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #30
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());
            }
        }
        /// <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();
                }
            }
        }
Example #32
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));
        }
Example #33
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("提示", "无法更新符号信息!");
            }
        }
Example #34
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();
            }
        }
Example #35
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>
    /// 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();
      }
    }
Example #37
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);
                 }
             }

             //用当前的文件路径设置保存文件
        }
Example #38
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 "";
            }
        }
 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;
 }
 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);
   }
 }
Example #41
0
        public MainFrm()
        {
            //
            // Required for Windows Form Designer support
            //
            SAoption = new SpatialAnalysisOption("c:\\temp");
            IMapDocument pMapDocument = new MapDocumentClass();

            modPublicClass = new ModPublicClass(pMapDocument, @"D:\PPT\��ѵPPT\CSHARPDEMO\CSharp\data", "data.mxd");
            InitializeComponent();
            m_AOI = new RectangleElementClass();
            IElementProperties property = m_AOI as IElementProperties;
            property.Name = "Map_AOI";

            ResetFillSymbol();
            //���ƹ�����
            _toolBarManager = new ToolBarManager(this, this);

            // The control Text property is used to draw the bar name while floating
            // and on view/hide menu.

            toolBar1.Text = "��������";
            toolBar2.Text = "�������������";

            // Add toolbar (default position)
            _toolBarManager.AddControl(toolBar1, DockStyle.Top);

            _toolBarManager.AddControl(toolBar2, DockStyle.None);
            _toolBarManager.AddControl(axToolbarControl1, DockStyle.None);
            pNetFlagArray = new ArrayClass();
        }
Example #42
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();
            }
        }
Example #43
0
        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);
        }
Example #44
0
 public override bool SaveMap(string filePath)
 {
     IMapDocument mapDocument = new MapDocumentClass();
     if (System.IO.File.Exists(filePath))
     {
         System.IO.File.Delete(filePath);
     }
     mapDocument.New(filePath);
     mapDocument.ReplaceContents((IMxdContents)this._axMapCtrl.Map);
     mapDocument.Save(mapDocument.UsesRelativePaths, true);
     mapDocument.Close();
     
     return true;
 }
Example #45
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);

            }
        }
Example #46
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;
            }
        }
    /// <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;
        }
      }
    }
Example #48
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        public List<IElement> discrimaDatosLayer(string n_municipio, string n_plano, string t_plano, IMxDocument pMxDoc, ILayer municipios, ILayer seleccion, ILayer zona, ILayer calles)
        {
            // clsGeoTools arcpy =new clsGeoTools();
            //IElement[] functionReturnValue = null;
            ILayer MANZANAS;
            List<IElement> pElem = new List<IElement>();
            List<IElement> pElemU = new List<IElement>();
            ArrayList nom_plano = null;
            IMap pMap = pMxDoc.FocusMap;
             //  ILayer municipio = default(ILayer);
            ILayer zonasValor = default(ILayer);
            ILayer seleccionZona = default(ILayer);
            ILayer manzana;
            string p;
            int n = 17;
            MANZANAS = B.returnLayerByName(ArcMap.Document, "MANZANAS");
            try {
                nom_plano = (B.returnFieldData( B.returnFeatureLayerByName(ArcMap.Document, "municipio").FeatureClass, "nombre"));
                foreach (string itm in funcAux.StatUnique(nom_plano)){
                    nomPlano = itm;
                    p = funcAux.checaPalabra(nomPlano,n);
                    //MessageBox.Show(p, nomPlano);
                    if (p.Length >n)
                        pElem.Add( addTitleToLayout(pMxDoc, 9/*10*/, 74, 47.2, (IGraphicsContainer)pMxDoc.PageLayout, true, p.ToUpper())) ;
                    else
                        pElem.Add(addTitleToLayout(pMxDoc, 9/*10*/, 74, 48, (IGraphicsContainer)pMxDoc.PageLayout, true, p.ToUpper()));
                    break;
                }

                G.selectLayerByAttribute(seleccion, "municipio = " + n_municipio + " AND n_plano = " + n_plano, true);
                G.copyFeatures(seleccion, globales.gdb + "seleccionZona");
               // G.selectClip(seleccion, municipio, globales.gdb + "seleccionZona");
               /*Inserta el numero del plano*/
                pElem.Add( addTitleToLayout(pMxDoc, 6.0, 74.3, 9, (IGraphicsContainer)pMxDoc.PageLayout, false, n_plano + "   de   " + t_plano));
                seleccionZona = B.returnLayerByName(ArcMap.Document, "seleccionZona");

                G.selectClip(zona, seleccionZona, globales.gdb + "zonasValor");
                //B.limpiarZonasTmp(ArcMap.Document, "municipio");
                zonasValor = B.returnLayerByName(ArcMap.Document, "zonasValor");
                // estilado ZonaValor
                G.applySymbologyFromLayer(zonasValor, zona);
                /*Inserta los valores de las zonas*/
               // addMapSurroundM(pMxDoc, "zonasValor", "clave_zona", "Valor", 72.299, 76.00,ref pElem);
               	pMap.ClearSelection();
                G.selectClip(MANZANAS, zonasValor, globales.gdb + "manzana");
                //G.selectClip(calles, seleccionZona, globales.gdb + "calle");
                manzana = B.returnLayerByName(ArcMap.Document, "manzana");
                G.applySymbologyFromLayer(manzana, MANZANAS);
                pMap.ClearSelection();
                B.limpiarZonasTmp(ArcMap.Document, "seleccionZona");
                /******************************************Genera el macro mapa******************************************************/
                IMapDocument pMapDoc = new MapDocumentClass();
                IMap pMap2 = pMxDoc.Maps.get_Item(1);

                pMxDoc.ActiveView = (IActiveView)pMap2;
                string mun = "municipio";
                ILayer SELECCION = B.returnLayerByName(ArcMap.Document, mun);
                G.selectLayerByAttribute(SELECCION, "municipio = " + n_municipio, true);

                B.zoomToSeleccion(pMxDoc, mun);
                pMap2.MapScale *= (1.12);
                pMap2.ClearSelection();

                pMxDoc.ActiveView.Refresh();
                pMap = pMxDoc.Maps.get_Item(0);
                pMxDoc.ActiveView = (IActiveView)pMap;
                pMxDoc.ActiveView = (IActiveView)pMxDoc.PageLayout;
                /******************************************Fin de el macro mapa******************************************************/
                return pElem;
            } catch (System.Exception ex) {
                MessageBox.Show("Error: " + ex.Message, "clsMapTools.discrimaDatosLayer");
                MessageBox.Show("Error: " + ex.StackTrace);
                return null;
            }
        }
Example #49
0
        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);
        }
Example #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;
            }
            */ 
        }
Example #51
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("地图文档保存成功!");
 }
Example #52
0
        /// <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;
            }
        }
Example #53
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();
            }
        }
Example #54
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;
            }
        }
    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);
      }
    }
		private void cmdLoadDoc_Click(object sender, System.EventArgs e)
		{
			//Open a file dialog for selecting map documents
			openFileDialog1.Title = "Browse Map Document";
			openFileDialog1.Filter = "Map Documents (*.mxd, *.mxt, *.pmf)|*.pmf; *.mxt; *.mxd";
			openFileDialog1.ShowDialog();

			//Exit if no map document is selected
			string sFilePath = openFileDialog1.FileName;
			if (sFilePath == "") return;

			bool bPass, bIsMapDoc;
			IMapDocument ipMapDoc;
			ipMapDoc = new MapDocumentClass();

			//Check if the map document is password protected
			bPass = ipMapDoc.get_IsPasswordProtected(sFilePath);

			if(bPass)
			{
				//Disable the main form
				this.Enabled = false;

				//Show the password dialog
				frmPassword Form2 = new frmPassword();
				Form2.ShowDialog (this);
				int check = Form2.Check; 
					
				//OK button pressed					
				if (check == 1)
				{
					try
					{
						//Set a waiting cursor
						Cursor.Current = Cursors.WaitCursor;
								
						//Load the password protected map
						axPageLayoutControl1.LoadMxFile(sFilePath, Form2.Password); 
						txtPath.Text = sFilePath;
						this.Enabled = true;

						//Set a default cursor
						Cursor.Current = Cursors.Default; 
					}
					catch
					{
						this.Enabled = true;
						MessageBox.Show("The Password was incorrect!");
					}
				}
				else
				{
					this.Enabled = true;
				}
			}
			else  
			{
				//Check whether the file is a map document
				bIsMapDoc = axPageLayoutControl1.CheckMxFile(sFilePath);
				
				if(bIsMapDoc)
				{
					Cursor.Current = Cursors.WaitCursor;
					
					//Load the Mx document	
					axPageLayoutControl1.LoadMxFile(sFilePath, Type.Missing); 
					txtPath.Text = sFilePath;
					//Set a default cursor
					Cursor.Current = Cursors.Default; 
				}
				else
				{
					MessageBox.Show(sFilePath + " is not a valid ArcMap document");
					sFilePath = "";
				}
			}
		}
Example #57
0
 void IGMap.CloseMxd()
 {
     IMapDocument mapDoc = new MapDocumentClass();
     mapDoc.Open(this._mapHook.DocumentFilename, string.Empty);
     mapDoc.Close();
 }
Example #58
0
        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();
            }
        }
Example #59
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();
            }
        }
Example #60
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;
        }