private void Load(IMapControl2 mapControl, XmlDocument xmlDocument) { try { XmlNode nodeMap = xmlDocument.SelectSingleNode("/MapDataLoadConfig/Map"); if (nodeMap == null) { return; } IMapDocument templateDocument = OpenTemplateDocument(); IMap templateMap = templateDocument.get_Map(0); IMap map = new MapClass(); if (XmlHelper.GetAttributeValue(nodeMap, "Name") != string.Empty) { map.Name = XmlHelper.GetAttributeValue(nodeMap, "Name"); } XmlNodeList nodeListLayers = nodeMap.ChildNodes; if (nodeListLayers != null && nodeListLayers.Count > 0) { for (var i = 0; i < nodeListLayers.Count; i++) { XmlNode nodelayer = nodeListLayers[i]; } } }catch (Exception ex) { } }
/// <summary> /// 根据地图出图配置,设置地图文档并导出地图 /// </summary> /// <param name="cfg"></param> /// <param name="mapDoc"></param> protected virtual void ExportMapMainOperation(MapExportInfo cfg, IMapDocument mapDoc) { //设置数据源、定义查询、比例尺、显示范围 var graphicsContainer = mapDoc.PageLayout as IGraphicsContainer; foreach (var mapFrameInfo in cfg.MapFrames) { SetMapFrame(graphicsContainer, mapFrameInfo); } //设置元素的值 foreach (var elementInfo in cfg.Elements) { var elements = graphicsContainer.GetElementsByKeyword(elementInfo.Name); SetElementsValue(elements, elementInfo.ValueType, elementInfo.Value); } //保存地图,导出图片 mapDoc.Save(); foreach (var exportPicture in cfg.ExportPictures) { var outputPath = Path.Combine(cfg.ExportDirectory, cfg.ExportFileName + exportPicture.PicExtension); mapDoc.PageLayout.ExportToPicture(outputPath, exportPicture.Dpi); } //关闭文档,释放资源 mapDoc.Close(); Marshal.ReleaseComObject(mapDoc); }
/// <summary> /// 加载网络数据集 /// </summary> public void LoadNetWorkDataSet() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pMapDcument = new MapDocumentClass(); try { string NetWorkData = xml.GetElement("MapDocument", "RoadNetData"); //将数据载入pMapDocument并与map控件联系起来 NetWorkData = System.Windows.Forms.Application.StartupPath + NetWorkData; pMapDcument.Open(NetWorkData, ""); int i; for (i = 0; i <= pMapDcument.MapCount - 1; i++) { //一个IMapDocument对象中可能有多个Map对象,遍历每个map对象 mapControl.Map = pMapDcument.get_Map(i); } mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
public void OnCreate(object hook) { if (hook is IMapDocument) { _doc = hook as IMapDocument; } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { IPageLayoutControl3 pPageLayoutControl = null; if (m_hookHelper.Hook is IToolbarControl) { pPageLayoutControl = (IPageLayoutControl3)((IToolbarControl)m_hookHelper.Hook).Buddy; } //In case the container is MapControl else if (m_hookHelper.Hook is IPageLayoutControl3) { pPageLayoutControl = (IPageLayoutControl3)m_hookHelper.Hook; } else { MessageBox.Show("µ±Ç°½çÃæ±ØÐëÊÇPageLayoutControl½çÃæ!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } SaveFileDialog dlgFile = new SaveFileDialog();//ÒÔ¶Ô»°¿òÑ¡ÔñÎĵµÂ·¾¶ dlgFile.Title = "Áí´æµØͼÎĵµ"; dlgFile.Filter = "Map Documents(*.mxd)|*.mxd"; string sFilePath = string.Empty; if (dlgFile.ShowDialog() == DialogResult.OK) { sFilePath = dlgFile.FileName; ClsGDBDataCommon cls = new ClsGDBDataCommon(); m_pDoc = cls.SaveAsDocument(pPageLayoutControl, sFilePath); } }
//加载地图文档 private void loadMapDoc() { mapDocument = new ESRI.ArcGIS.Carto.MapDocumentClass(); try { System.Windows.Forms.OpenFileDialog openFileDialog; openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开地图文档"; openFileDialog.Filter = "map documents(*.mxd)|*.mxd"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string filePath = openFileDialog.FileName; mapDocument.Open(filePath, ""); for (int i = 0; i < mapDocument.MapCount; i++) { axMapControl1.Map = mapDocument.get_Map(i); } axMapControl1.Refresh(); } else { mapDocument = null; } } catch (Exception e) { MessageBox.Show(e.ToString()); } }
public frmAddProjectLayers(IMap map2, esriDatasetType dType) { InitializeComponent(); if (map2 == null) { OpenFileDialog ofdMxd = new OpenFileDialog(); ofdMxd.Filter = "Map Doc|*.mxd"; ofdMxd.Multiselect = false; DialogResult rslt = ofdMxd.ShowDialog(); if (rslt == DialogResult.OK) { mapDoc = new MapDocumentClass(); mapDoc.Open(ofdMxd.FileName, ""); map = mapDoc.get_Map(0); } else { MessageBox.Show("A map document must be selected to work. Shutting down"); this.Close(); } } else { map = map2; } if (dType == esriDatasetType.esriDTAny) { dType = esriDatasetType.esriDTFeatureClass; } switch (dType) { case esriDatasetType.esriDTTable: this.Text = "Add Table"; label1.Text = "Select Table"; break; case esriDatasetType.esriDTRasterDataset: this.Text = "Add Raster"; label1.Text = "Select Raster"; break; default: this.Text = "Add Feature"; label1.Text = "Select Feature"; break; } mapserviceutility msUtil = new mapserviceutility(); prjDatabase = msUtil.LcCacheDb; if (prjDatabase == "") { msUtil.changeLocalDatabase(); prjDatabase = msUtil.LcCacheDb; } this.cmbLayers.Items.Clear(); foreach (string s in getNames(dType)) { lyrDic.Add(s, prjDatabase + "\\" + s); cmbLayers.Items.Add(s); } this.Refresh(); }
private ESRI.ArcGIS.Carto.IMap PrivateCreateMxd(string sPathToMXDToSave) { try { _pMapDocument = new MapDocumentClass(); //Copy the MXD System.IO.File.Copy(_sMxdTemplate, sPathToMXDToSave, true); _sNewDocument = sPathToMXDToSave; if (_pMapDocument.get_IsMapDocument(_sNewDocument)) { _pMapDocument.Open(_sNewDocument, null); IMap pMap; pMap = _pMapDocument.get_Map(0); return(pMap); } return(null); } catch (Exception ex) { throw ex; } }
public AddJoinDialog(IMapDocument mapDocument, IFeatureLayer layer) { _mapDocument = mapDocument; InitializeComponent(); foreach (IField field in layer.Fields.ToEnumerable()) { cmbFeatureLayerField.Items.Add(field.name); } PlugInManager pm = new PlugInManager(); foreach (IFeatureLayerJoin join in pm.GetPluginInstances(typeof(IFeatureLayerJoin))) { if (join == null) { continue; } cmbJoinClasses.Items.Add(new FeatureLayerJoinItem() { FeatureLayerJoin = join }); } cmbJoinClasses.SelectedIndex = 0; }
public FormExplorerOptions(IMapDocument document) { InitializeComponent(); _document = document; PlugInManager compMan = new PlugInManager(); foreach (XmlNode pageNode in compMan.GetPluginNodes(Plugins.Type.IExplorerOptionPage)) { IExplorerOptionPage page = compMan.CreateInstance(pageNode) as IExplorerOptionPage; if (page == null) { continue; } Panel pagePanel = page.OptionPage(); if (pagePanel == null) { continue; } TabPage tabPage = new TabPage(page.Title); tabPage.Controls.Add(pagePanel); if (page.Image != null) { imageList1.Images.Add(page.Image); tabPage.ImageIndex = imageList1.Images.Count - 1; } tabControl.TabPages.Add(tabPage); _optionPages.Add(page); } }
public AddTableRelationDialog(IMapDocument mapDocument, IFeatureLayer layer) { InitializeComponent(); _mapDocument = mapDocument; foreach (IMap map in _mapDocument.Maps) { foreach (IDatasetElement element in map.MapElements) { if (element == null || !(element.Class is ITableClass)) { continue; } cmbLeftTable.Items.Add(new DatasetElementItem() { Map = map, DatasetElement = element }); cmbRightTable.Items.Add(new DatasetElementItem() { Map = map, DatasetElement = element }); } } this.LeftTable = layer; cmbLogicalOperator.SelectedIndex = 0; }
/// <summary> /// 根据地图出图配置,设置地图文档并出图 /// </summary> /// <param name="cfg">对地图进行各项配置和出图的信息</param> /// <param name="mapDoc">要设置并出图的地图文档,若值为null则根据<see cref="cfg"/>参数指定的信息 /// 复制地图模板到生成目录或临时目录,打开复制后的地图文档进行设置和出图</param> public virtual void ExportMap(MapExportInfo cfg, IMapDocument mapDoc = null) { //是否在完成出图后关闭地图文档,地图文档来自外部传参(mapDoc != null)则不关闭,来自内部打开则应关闭 bool closeMapDoc = mapDoc == null; try { if (!ValidateConfig(cfg, out var message)) { throw new Exception(message); } if (mapDoc == null) { mapDoc = GetMapDocument(cfg); } ExportMapMainOperation(cfg, mapDoc); } catch (Exception ex) { if (closeMapDoc && mapDoc != null) { mapDoc.Close(); Marshal.ReleaseComObject(mapDoc); } throw ex; } }
/// <summary> /// 打开mxd地图文档 /// </summary> public void LoadMapDocument() { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pDcument = new MapDocumentClass(); try { string mxdData = xml.GetElement("MapDocument", "mxd"); //将数据载入pDocument并与map控件联系起来 mxdData = System.Windows.Forms.Application.StartupPath + mxdData; pDcument.Open(mxdData, ""); //Load the same pre-authored map document into the MapControl. mapControl.LoadMxFile(mxdData, null, null); //Set the extent of the MapControl to the full extent of the data. mapControl.Extent = mapControl.FullExtent; //int i; //for (i = 0; i <= pDcument.MapCount - 1; i++) //{ // //一个IMapDocument对象中可能有多个Map对象,遍历每个map对象 // mapControl.Map = pDcument.get_Map(i); //} mapControl.Refresh(); } catch (Exception ex) { throw (ex); } finally { xml = null; } }
private void method_0(IMapDocument imapDocument_0) { if (this.object_0 is IPageLayoutControl2) { imapDocument_0.ReplaceContents(((IPageLayoutControl2)this.object_0).PageLayout as IMxdContents); try { imapDocument_0.Save(true, true); } catch (Exception) { } } else if (this.object_0 is IMapControl2) { imapDocument_0.ReplaceContents(((IMapControl2)this.object_0).Map as IMxdContents); try { imapDocument_0.Save(true, true); } catch (Exception) { } } else if (this.object_0 is MapAndPageLayoutControls) { imapDocument_0.ReplaceContents( (this.object_0 as MapAndPageLayoutControls).PageLayoutControl.PageLayout as IMxdContents); imapDocument_0.Save(true, true); } }
public void OnCreate(object hook) { if (hook is IMapDocument) { if (_doc != null) { _doc.LayerAdded -= new LayerAddedEvent(_doc_LayerAdded); _doc.LayerRemoved -= new LayerRemovedEvent(_doc_LayerRemoved); _doc.MapAdded -= new MapAddedEvent(_doc_MapAdded); _doc.MapDeleted -= new MapDeletedEvent(_doc_MapDeleted); if (_doc.Application is IMapApplication) { ((IMapApplication)_doc.Application).AfterLoadMapDocument -= new AfterLoadMapDocumentEvent(Module_AfterLoadMapDocument); } } _doc = (IMapDocument)hook; _doc.LayerAdded += new LayerAddedEvent(_doc_LayerAdded); _doc.LayerRemoved += new LayerRemovedEvent(_doc_LayerRemoved); _doc.MapAdded += new MapAddedEvent(_doc_MapAdded); _doc.MapDeleted += new MapDeletedEvent(_doc_MapDeleted); if (_doc.Application is IMapApplication) { ((IMapApplication)_doc.Application).AfterLoadMapDocument += new AfterLoadMapDocumentEvent(Module_AfterLoadMapDocument); } } }
public MigrateMapToFeatureDatabaseDialog(IMapDocument doc, IMap map) { InitializeComponent(); _doc = doc; _map = map; #region Filter //All Features //Selected Features //Features in actual extent cmbExport.Items.Add(new ExportMethodItem("All Features", null)); if (map.Display.Envelope != null) { SpatialFilter dispFilter = new SpatialFilter(); dispFilter.SubFields = "*"; dispFilter.FilterSpatialReference = map.Display.SpatialReference; dispFilter.Geometry = map.Display.Envelope; dispFilter.SpatialRelation = spatialRelation.SpatialRelationIntersects; cmbExport.Items.Add(new ExportMethodItem("Features in actual extent", dispFilter)); } if (cmbExport.SelectedIndex == -1) { cmbExport.SelectedIndex = 0; } #endregion }
private void btnOK_Click(object sender, EventArgs e) { if (m_pPageLayoutCtl == null) { return; } string strFullpath = txtFolder.Text; if (strFullpath[strFullpath.Length - 1] != System.IO.Path.DirectorySeparatorChar) { strFullpath += System.IO.Path.DirectorySeparatorChar; } string strDocName = CreateMxdFolderAndGDB(strFullpath, m_pPageLayoutCtl.DocumentFilename); string strFullGdbName = strFullpath + strDocName + ".gdb"; string strFullDocName = strFullpath + strDocName + ".mxd"; //另存地图文档 ClsGDBDataCommon cls = new ClsGDBDataCommon(); m_pMapDoc = cls.SaveAsDocument(m_pPageLayoutCtl, strFullDocName); //n if (ExportLayers(m_pMapDoc, strFullGdbName, radioLayer.Checked)) { m_pMapDoc.Save(true, false); m_strDocNameNew = m_pMapDoc.DocumentFilename; m_pMapDoc.Close(); MessageBox.Show("导出成功!"); } }
public void ConstructMouseUp(IMapDocument doc, System.Windows.Forms.MouseEventArgs e) { _mousePressed = false; if (ActiveDisplay(doc) == null || _addContainer == null || _addContainer.Elements.Count == 0) { return; } Freehand element = _addContainer.Elements[0] as Freehand; if (element == null) { return; } element.Symbol = _symbol.Clone() as ISymbol; element.Template = element._pLine; IEnvelope env = element._pLine.Envelope; element.Scale(env.Width, env.Height); element.Translation(env.minx, env.miny); element._pLine = null; GraphicShape.AddElementToContainer(doc, element); _addContainer = null; }
public void ConstructMouseClick(IMapDocument doc, System.Windows.Forms.MouseEventArgs e) { if (ActiveDisplay(doc) == null) { return; } if (_addContainer == null) { GraphicPolygon element = new GraphicPolygon(); _addContainer = new GraphicsContainer(); _addContainer.Elements.Add(element); } double x = e.X; double y = e.Y; ActiveDisplay(doc).Image2World(ref x, ref y); if (_moveable == null) { ((GraphicPolygon)_addContainer.Elements[0]).AddPoint(x, y); } else { _moveable.X = x; _moveable.Y = y; _moveable = null; } ActiveDisplay(doc).DrawOverlay(_addContainer, true); }
public void ConstructMouseDoubleClick(IMapDocument doc, System.Windows.Forms.MouseEventArgs e) { if (ActiveDisplay(doc) == null || _addContainer == null || _addContainer.Elements.Count == 0) { return; } GraphicPolygon element = _addContainer.Elements[0] as GraphicPolygon; if (element == null) { return; } // Remove the last 1 Points... element._polygon[0].RemovePoint(element._polygon[0].PointCount - 1); //element._polygon[0].ReomvePoint(element._polygon[0].PointCount - 1); element.Symbol = _symbol.Clone() as ISymbol; element.Template = element._polygon; IEnvelope env = element._polygon.Envelope; element.Scale(env.Width, env.Height); element.Translation(env.minx, env.miny); element._polygon = null; GraphicShape.AddElementToContainer(doc, element); _addContainer = null; _moveable = null; }
public FormMain() { InitializeComponent(); m_pMapC2 = axMapControl_main.Object as IMapControl2; m_pMapDoc = new MapDocumentClass(); m_pSceneCtl = axSceneControl_main.Object as ISceneControl; }
public FormMain() { InitializeComponent(); m_pMapC2 = axMapControl_Main.Object as IMapControl2; m_pMapDoc = new MapDocumentClass(); m_pToolbarMenu = new ToolbarMenu(); }
private void LoadMxdFile(string filename) { if (axPageLayoutControl1.CheckMxFile(filename)) { //ESRI.ArcGIS.Framework.IDocument doc = new ESRI.ArcGIS.ArcMapUI.MxDocumentClass(); //m_application = doc.Parent; //m_application.Visible = false; //mxdocument = m_application.Document as IMxDocument; mapdocument = new MapDocument(); mapdocument.Open(filename); map = mapdocument.Map[0]; mapdocument.SetActiveView((IActiveView)map); m_pageLayoutControl = (IPageLayoutControl2)axPageLayoutControl1.Object; m_pageLayoutControl.PageLayout = mapdocument.PageLayout; //axPageLayoutControl1.LoadMxFile(filename); this.Text = mapdocument.DocumentFilename; saveAsToolStripMenuItem.Enabled = true; saveToolStripMenuItem.Enabled = true; printToolStripMenuItem.Enabled = true; } else { MessageBox.Show("The Selected file is not suppoted !!!"); } }
static public void TemporaryRestore(this IMapDocument doc) { if (doc is IPersistableTemporaryRestore) { ((IPersistableTemporaryRestore)doc).TemporaryRestore(); } }
/// <summary> /// 获取网络数据集 /// </summary> /// <param name="pFeatureClass"></param> public void getNetWorkData(ref IFeatureClass pFeatureClass) { Core.Generic.myXML xml = new Core.Generic.myXML(System.Windows.Forms.Application.StartupPath + "\\Setting.xml"); pMapDcument = new MapDocumentClass(); IFeatureLayer pFeatureLayer; try { string NetWorkData = xml.GetElement("MapDocument", "RoadNetData"); //将数据载入pMapDocument并与map控件联系起来 NetWorkData = System.Windows.Forms.Application.StartupPath + NetWorkData; pMapDcument.Open(NetWorkData, ""); for (int index = 0; index < pMapDcument.get_Map(0).LayerCount; index++) { if (pMapDcument.get_Map(0).get_Layer(index).Name == "实验区路网数据") { pFeatureLayer = pMapDcument.get_Map(0).get_Layer(index) as IFeatureLayer; pFeatureClass = pFeatureLayer.FeatureClass; } else { continue; } } } catch (Exception ex) { throw (ex); } finally { xml = null; } }
static public IMap MapFromLayer(this IMapDocument doc, ILayer layer) { if (doc?.Maps == null) { return(null); } foreach (var map in doc.Maps) { if (map?.TOC?.Elements == null) { continue; } foreach (var element in map.TOC.Elements) { if (element.Layers.Contains(layer)) { return(map); } } } return(null); }
void Module_AfterLoadMapDocument(IMapDocument mapDocument) { if (_doc != mapDocument) { OnCreate(mapDocument); } if (_doc == null) { return; } _afterLoadMapDocument = true; foreach (IMap map in _doc.Maps) { foreach (IDatasetElement element in map.MapElements) { if (!(element is IFeatureLayer)) { continue; } if (EditLayerByFeatureLayer(element as IFeatureLayer) == null) { _editLayers.Add(new EditLayer(element as IFeatureLayer, EditStatements.NONE)); } } } if (OnEditLayerCollectionChanged != null) { OnEditLayerCollectionChanged(this); } _afterLoadMapDocument = false; }
public void OnCreate(object hook) { if (hook is IMapDocument) { _mapDocument = (IMapDocument)hook; } }
public static void ZoomToSelection(IMapDocument pMxDoc, IFeatureLayer pFeatureLayer, string where_clause) { IMap pMap = (IMap)pMxDoc.ActiveView; pMap.ClearSelection(); ILayer pLayer = pFeatureLayer as ILayer; IFeatureSelection pFeatureSelection = pLayer as IFeatureSelection; IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; IQueryFilter pFilter = new QueryFilter(); IEnvelope pEnv = new Envelope() as IEnvelope; pFilter.WhereClause = where_clause; IFeatureCursor pFeatureCursor = pFeatureClass.Search(pFilter, false); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { pFeatureSelection.Add(pFeature); pEnv.Union(pFeature.ShapeCopy.Envelope); IGeometry pgeom = (IGeometry)pFeature.Shape; //pMap.SelectByShape(pgeom, null, false); pFeature = pFeatureCursor.NextFeature(); } pMxDoc.ActiveView.Extent = pEnv; pMxDoc.ActiveView.Refresh(); }
public TableRelationsDialog(IMapDocument mapDocument, IFeatureLayer layer) { InitializeComponent(); _mapDocument = mapDocument; _layer = layer; FillList(); }
public GPSTrack(IMapDocument doc) : this() { _doc = doc; _map = doc.FocusMap; Connect(); }
public ModPublicClass(IMapDocument pDocument,string mxdFilePath,string mxdFileName) { // // TODO: �ڴ˴���ӹ��캯���� m_pDocument=new MapDocumentClass(); m_MxdPath=mxdFilePath; m_MxdFileName=mxdFileName; // }
public LayerInfo(IMapDocument mapDoc) { /* Diese Eigenschaften sind für jeden Layer identisch */ mxd = mapDoc; mxdname = mxd.DocumentFilename; UID pID = new UIDClass(); pID.Value = "{EDAD6644-1810-11D1-86AE-0000F8751720}"; groupLayerList = getLayerList(pID); }
private static Bitmap GetBitmap(IMapDocument mapDoc) { Bitmap bitmap; if (!TryGetBitmap(mapDoc, out bitmap)) { bitmap = GetDefaultBitmap(); } return bitmap; }
public frmTileImageServiceLayer(IActiveView acV) { InitializeComponent(); if (acV == null) { OpenFileDialog oFd = new OpenFileDialog(); oFd.Filter = "Map Document|*.mxd"; oFd.Multiselect = false; DialogResult dR = oFd.ShowDialog(); if (dR == System.Windows.Forms.DialogResult.OK) { mapDoc = new MapDocumentClass(); mapDoc.Open(oFd.FileName); acV = mapDoc.ActiveView; } } av = acV; }
private void SaveDocAsToolStripMenuItem_Click(object sender, EventArgs e) { try { this.pMapDocument = new MapDocumentClass(); this.saveFileDialog.Filter = "MXD文件|*.mxd"; if (this.saveFileDialog.ShowDialog() == DialogResult.OK) { this.pMapDocument.New(this.saveFileDialog.FileName); IMxdContents pMxdContents = this.m_controlsSynchronizer as IMxdContents; this.pMapDocument.ReplaceContents(pMxdContents); this.pMapDocument.Save(true, true); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public MXD(string mxdPath) { path = mxdPath; // GUIDs finden: http://support.esri.com/index.cfm?fa=knowledgebase.techarticles.articleShow&d=31115 LayerTypeUIDs[0] = "{EDAD6644-1810-11D1-86AE-0000F8751720}"; LayerTypeUIDs[1] = "{5CEAE408-4C0A-437F-9DB3-054D83919850}"; LayerTypeUIDs[2] = "{DBCA59AC-6771-4408-8F48-C7D53389440C}"; LayerTypeUIDs[3] = "{D02371C7-35F7-11D2-B1F2-00C04F8EDEFF}"; LayerTypeUIDs[4] = "{605BC37A-15E9-40A0-90FB-DE4CC376838C}"; LayerTypeUIDs[5] = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; LayerTypeUIDs[6] = ""; if (InitializeLicense() == esriLicenseStatus.esriLicenseCheckedOut) { mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(path)) { if (mapDoc.get_IsMapDocument(path)) { mapDoc.Open(path, null); if (mapDoc.DocumentType == esriMapDocumentType.esriMapDocumentTypeMxd) { activateMapDocument(); // alle Layer holen layerList = getLayerList(null); // alle GroupLayer holen processLayer(LayerTypes.GroupLayer); // alle AnnotationLayer holen processLayer(LayerTypes.AnnotationLayer); // alle AnnotationSubLayer holen processLayer(LayerTypes.AnnotationSubLayer); // alle RasterLayer holen processLayer(LayerTypes.RasterLayer); // alle RasterCatalogLayer holen processLayer(LayerTypes.RasterCatalogLayer); // alle FeatureLayer holen processLayer(LayerTypes.FeatureLayer); // übrige Layer holen foreach (ILayer lyr in layerList) { if (!processedLayers.Contains(lyr)) { LayerInfo lyrInfo = new LayerInfo(mapDoc); lyrInfo.processOtherLayer(lyr); lyrInfos.Add(lyrInfo); processedLayers.Add(lyr); } } // Resultate ausgeben foreach (LayerInfo info in lyrInfos) { Console.WriteLine(info.writeCSV()); } // Dokument schliessen mapDoc.Close(); } else { Console.Error.WriteLine("FEHLER: kein gültiges MXD-File"); } } else { Console.Error.WriteLine("FEHLER: kein gültiges MXD-File"); } } else { Console.Error.WriteLine("FEHLER: Angegebenes File nicht gefunden"); } } else { Console.Error.WriteLine("FEHLER: Keine ArcView-Lizenz verfügbar"); } // Lizenz zurückgeben TerminateLicense(); }
private void btnSaveDocAs_Click(object sender, EventArgs e) { this.saveFileDialog.Filter = "MXD地图文档(*.mxd)|*.mxd"; if (this.saveFileDialog.ShowDialog() == DialogResult.OK) { try { this.pMapDocument = new MapDocumentClass(); this.pMapDocument.New(this.saveFileDialog.FileName); this.pMapDocument.ReplaceContents((IMxdContents)this.mainMapControl.Map); this.pMapDocument.ReplaceContents((IMxdContents)this.axPageLayoutControl.PageLayout); this.pMapDocument.Save(true, false); this.mainMapControl.DocumentFilename = this.saveFileDialog.FileName; this.Text = System.IO.Path.GetFileName(this.saveFileDialog.FileName) + " - " + "LinGIS - LinInfo"; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument); Application.DoEvents(); this.pMapDocument = null; } } }
private void btnOpenDoc_Click(object sender, EventArgs e) { if (this.mainMapControl.LayerCount > 0) { DialogResult result = MessageBox.Show("是否保存当前地图?", "警告", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Cancel) return; if (result == DialogResult.Yes) this.btnSaveDoc_Click(null, null); } this.openFileDialog.Title = "请选择地图文件"; this.openFileDialog.Filter = "MXD地图文件|*.mxd"; this.openFileDialog.Multiselect = false; this.openFileDialog.RestoreDirectory = true; if (this.openFileDialog.ShowDialog() == DialogResult.OK) { Application.DoEvents(); string docName = this.openFileDialog.FileName; try { this.pMapDocument = new MapDocumentClass(); if (pMapDocument.get_IsPresent(docName) && !pMapDocument.get_IsPasswordProtected(docName)) { pMapDocument.Open(docName, null); IMap pMap = pMapDocument.get_Map(0); m_controlsSynchronizer.ReplaceMap(pMap); this.mainMapControl.DocumentFilename = docName; this.Text = System.IO.Path.GetFileName(this.openFileDialog.FileName) + " - " + "LinGIS - LinInfo"; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument); Application.DoEvents(); this.pMapDocument = null; } } }
private void btnSaveDoc_Click(object sender, EventArgs e) { if (this.mainMapControl.DocumentFilename != "") { try { this.pMapDocument = new MapDocumentClass(); this.pMapDocument.Open(this.mainMapControl.DocumentFilename,""); this.pMapDocument.ReplaceContents((IMxdContents)this.mainMapControl.Map); this.pMapDocument.ReplaceContents((IMxdContents)this.axPageLayoutControl.PageLayout); this.pMapDocument.Save(true, false); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { System.Runtime.InteropServices.Marshal.ReleaseComObject(this.pMapDocument); Application.DoEvents(); this.pMapDocument = null; } } else { this.btnSaveDocAs_Click(null, null); } }
private ESRI.ArcGIS.Carto.IMap PrivateCreateMxd(string sPathToMXDToSave) { try { _pMapDocument = new MapDocumentClass(); //Copy the MXD System.IO.File.Copy(_sMxdTemplate, sPathToMXDToSave, true); _sNewDocument = sPathToMXDToSave; if (_pMapDocument.get_IsMapDocument(_sNewDocument)) { _pMapDocument.Open(_sNewDocument, null); IMap pMap; pMap = _pMapDocument.get_Map(0); return pMap; } return null; } catch (Exception ex) { throw ex; } }
public bool CreateMxd(string sMxdTemplate, string sPathToMXD, string ArcGISServer, string sMxdFile, string sDBConn, string sDataSet, bool bSde) { if (sMxdTemplate.Length > 0) _sMxdTemplate = sMxdTemplate; _sPathToMXD = sPathToMXD; _ArcGISServer = ArcGISServer; ESRI.ArcGIS.Carto.IMap pMap = null; IFeatureClass pOldFC = null; string fcName = String.Empty; string sSuffix = String.Empty; IWorkspaceFactory2 wsf = null; IWorkspace2 ws2 = null; IFeatureWorkspace fws = null; IWorkspace ws = null; try { if (bSde) { // Get WS for SDE ws = ArcSdeWorkspaceFromFile(sDBConn); } else { // Get WS from file GDB. wsf = new FileGDBWorkspaceFactoryClass() as IWorkspaceFactory2; //if locks on gdb only path is passed in string fileGdb = sDBConn.Contains(".gdb") ? sDBConn : sDBConn; if (wsf.IsWorkspace(fileGdb)) { ws = wsf.OpenFromFile(fileGdb, 0); } } if (ws == null) { return false; } // Check if Mxd already exists if (File.Exists(sMxdFile)) { return false; } // Create a Mxd from Overlays Template pMap = PrivateCreateMxd(sMxdFile); ws2 = (IWorkspace2)ws; fws = (IFeatureWorkspace)ws; // Loop through all layers in MXD and repoint data source to OverlayGDB Features IEnumLayer pEnumLayer = pMap.get_Layers(null, true); pEnumLayer.Reset(); ILayer pLayer = pEnumLayer.Next(); while (pLayer != null) { if (!(pLayer is IFeatureLayer)) { pLayer = pEnumLayer.Next(); continue; } // Cast pLayer to featurelayer IFeatureLayer pMapFeatureLayer = (IFeatureLayer)pLayer; pOldFC = pMapFeatureLayer.FeatureClass; if (pOldFC == null) { pLayer = pEnumLayer.Next(); continue; } // Get FC name IDataset pDS = (IDataset)pOldFC; fcName = pDS.Name; // Feature Class: <Dataset>_osm_pt, <Dataset>_osm_ln, <Dataset>_osm_ply sSuffix = fcName.Substring(fcName.IndexOf("_osm_")); if (String.IsNullOrEmpty(sSuffix)) continue; // Check if feature class exists in GDB if (ws2.get_NameExists(esriDatasetType.esriDTFeatureClass, sDataSet + sSuffix)) { // Get feature class IFeatureClass ipFC = fws.OpenFeatureClass(sDataSet + sSuffix); IFeatureLayer ipFL = (IFeatureLayer)pLayer; // Create IMapAdmin2 from pMap IMapAdmin2 pMapAdmin2 = (IMapAdmin2)pMap; // Change FeatureClass of layer to FC in FGDB ipFL.FeatureClass = ipFC; pMapAdmin2.FireChangeFeatureClass(pOldFC, ipFC); COMUtil.ReleaseObject(ipFC); ipFC = null; COMUtil.ReleaseObject(ipFL); ipFL = null; } else { // Remove layer from map pMap.DeleteLayer(pLayer); } pLayer = pEnumLayer.Next(); } SaveMXD(sMxdFile, pMap); return true; } catch (System.Runtime.InteropServices.COMException cx) { throw cx; } catch (Exception ex) { throw ex; } finally { COMUtil.ReleaseObject(pOldFC); COMUtil.ReleaseObject(fws); COMUtil.ReleaseObject(ws2); COMUtil.ReleaseObject(ws); COMUtil.ReleaseObject(pMap); COMUtil.ReleaseObject(wsf); pOldFC = null; fws = null; ws2 = null; ws = null; wsf = null; pMap = null; _pMapDocument = null; //Do not make any call to ArcObjects after ShutDownApplication() if (m_AOLicenseInitializer != null) m_AOLicenseInitializer.ShutdownApplication(); m_AOLicenseInitializer = null; } }
public static void OperateMapDoc(AxMapControl axMapControl1, AxMapControl axMapControl2, string strOperateType) { OpenFileDialog OpenFileDialog = new OpenFileDialog(); SaveFileDialog SaveFileDialog = new SaveFileDialog(); OpenFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd"; SaveFileDialog.Filter = "地图文档文件(*.mxd)|*.mxd"; string strDocFileN = string.Empty; pMapDocument = new MapDocumentClass(); switch (strOperateType) { case "NewDoc": { SaveFileDialog.Title = "输入需要新建地图文档的名称"; SaveFileDialog.ShowDialog(); strDocFileN = SaveFileDialog.FileName; if (strDocFileN == string.Empty) return; pMapDocument.New(strDocFileN); pMapDocument.Open(strDocFileN, ""); axMapControl1.Map = pMapDocument.get_Map(0); break; } case "OpenDoc": { OpenFileDialog.Title = "输入需要加载的地图文档"; OpenFileDialog.ShowDialog(); strDocFileN = OpenFileDialog.FileName; if (strDocFileN == string.Empty) return; pMapDocument.Open(strDocFileN, ""); for (int i = 0; i < pMapDocument.MapCount; i++) { axMapControl1.Map = pMapDocument.get_Map(i); //axMapControl2.Map = pMapDocument.get_Map(i); } axMapControl1.Refresh(); break; } case "SaveDoc": { if (pMapDocument.get_IsReadOnly(pMapDocument.DocumentFilename) == true) { MessageBox.Show("此地图为只读文档", "信息提示"); return; } pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("保存成功!", "信息提示"); break; } case "SaveDocAS": { SaveFileDialog.Filter = "地图文档另存"; SaveFileDialog.ShowDialog(); strDocFileN = SaveFileDialog.FileName; if (strDocFileN == string.Empty) return; if (strDocFileN == pMapDocument.DocumentFilename) { pMapDocument.Save(pMapDocument.UsesRelativePaths, true); MessageBox.Show("保存成功!", "信息提示"); break; } else { pMapDocument.SaveAs(strDocFileN, true, true); MessageBox.Show("保存成功", "信息提示"); } break; } default: break; } }
private static bool TryGetBitmap(IMapDocument mapDoc, out Bitmap bitmap) { try { if (null == mapDoc.Thumbnail) { bitmap = null; return false; } var picture = mapDoc.Thumbnail; bitmap = GetBitmap(picture); return true; } catch (Exception exception) { Console.WriteLine(exception); bitmap = null; return false; } }