public static void LoadGeoData(AxMapControl axMapControl1, AxMapControl axMapControl2, string strFileN) { string strFExtenN = System.IO.Path.GetExtension(strFileN); switch (strFExtenN) { case ".shp": { string strPath = System.IO.Path.GetDirectoryName(strFileN); string strFile = System.IO.Path.GetFileNameWithoutExtension(strFileN); axMapControl1.AddShapeFile(strPath, strFile); axMapControl2.ClearLayers(); axMapControl2.AddShapeFile(strPath, strFile); axMapControl2.Extent = axMapControl2.FullExtent; break; } case ".bmp": case ".tif": case ".jpg": case ".img": { IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass(); string pathName = System.IO.Path.GetDirectoryName(strFileN); string fileName = System.IO.Path.GetFileName(strFileN); IWorkspace pWS = pWSF.OpenFromFile(pathName, 0); IRasterWorkspace pRWS = pWS as IRasterWorkspace; IRasterDataset pRasterDataSet = pRWS.OpenRasterDataset(fileName); IRasterPyramid pRasPyramid = pRasterDataSet as IRasterPyramid; if (pRasPyramid != null) { if (!(pRasPyramid.Present)) { pRasPyramid.Create(); } } IRaster pRaster = pRasterDataSet.CreateDefaultRaster(); IRasterLayer pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromRaster(pRaster); ILayer pLayer = pRasterLayer as ILayer; axMapControl1.AddLayer(pLayer, 0); axMapControl2.ClearLayers(); axMapControl2.AddLayer(pLayer, 0); axMapControl2.Extent = axMapControl2.FullExtent; break; } case ".mxd": { if (axMapControl1.CheckMxFile(strFExtenN)) { axMapControl1.LoadMxFile(strFExtenN); } else MessageBox.Show("所选择的文件不是Mxd文件!", "提示信息"); break; } default: break; } }
/// <summary> /// 控件的加载地图文档 /// </summary> /// <param name="mapControl">要加载的地图控件</param> public void LoadMxFile(AxMapControl mapControl) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开MXD"; openFileDialog.Filter = "ArcMap文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt|发布地图文件(*.pmf)|*.pmf|所有地图格式(*.mxd;*.mxt;*.pmf)|*.mxd;*.mxt;*.pmf"; openFileDialog.Multiselect = false; openFileDialog.CheckFileExists = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { string fileName = openFileDialog.FileName; if (fileName == "") { return; } if (mapControl.CheckMxFile(fileName)) { mapControl.LoadMxFile(fileName); } else { MessageBox.Show(fileName + "是无效的地图文档,请检查后重新加载"); return; } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { m_map.LoadMxFile("C:\\IPAN\\Exercise02\\SouthAmerica.mxd", 0, null); m_toc.SetBuddyControl(m_map); m_toolbar.SetBuddyControl(m_map); m_toolbar.AddItem("esriControls.ControlsMapNavigationToolbar"); }
/// <summary> /// 打开地图文档 /// </summary> /// <param name="axMapControl"></param> public void loadMapDoc(AxMapControl axMapControl) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Title = "打开地图文档"; openFileDialog1.Filter = "地图文档(*.mxd)|*.mxd";//设置过滤属性 if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; //未选择文件return } string filePath = openFileDialog1.FileName; //获取到文件路径 if (axMapControl.CheckMxFile(filePath)) //检查路径是否合法 { try { axMapControl.LoadMxFile(filePath, 0, Type.Missing); } catch (Exception e) { MessageBox.Show("该地图已损坏或者受保护不能被打开"); } } else { MessageBox.Show(filePath + "不是有效的地图文档路径"); return; } axMapControl.Refresh(); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { if (!ModMxd._MxdPath.Equals("")) { DialogResult pResult = MessageBox.Show("是否保存当前的地图文档?", "询问", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (pResult) { case DialogResult.Cancel: return; case DialogResult.Yes: { IMxdContents pMxdC; pMxdC = m_hookHelper.FocusMap as IMxdContents; IMapDocument pMapDocument = new MapDocumentClass(); //打开地图文档 if (File.Exists(ModMxd._MxdPath)) { pMapDocument.Open(ModMxd._MxdPath, ""); } else { pMapDocument.New(ModMxd._MxdPath); } //保存信息 IActiveView pActiveView = m_hookHelper.ActiveView; pMapDocument.ReplaceContents(pMxdC); pMapDocument.Save(true, true); break; } case DialogResult.No: break; } } OpenFileDialog pOpendlg = new OpenFileDialog(); pOpendlg.Title = "打开地图文档"; pOpendlg.Filter = "(*.mxd)|*.mxd"; if (pOpendlg.ShowDialog() != DialogResult.OK) { return; } string strMxdName = pOpendlg.FileName; if (m_AxMapControl.CheckMxFile(strMxdName)) { m_AxMapControl.LoadMxFile(strMxdName, "", ""); } ModMxd._MxdPath = strMxdName; }
/// <summary> /// 加载地图mxd /// </summary> /// <param name="mapControl"></param> /// <param name="mapFileName"></param> /// <returns></returns> public static bool LoadMxd(AxMapControl mapControl, string mapFileName) { if (mapControl.CheckMxFile(mapFileName)) { mapControl.LoadMxFile(mapFileName); return(true); } return(false); }
private string LoadMapFileInPreviewControl(string fileName) { string msg = string.Empty; if (File.Exists(fileName)) { string ext = Path.GetExtension(fileName).ToLower(); if (ext == ".mxd") { if (mapControl.CheckMxFile(fileName)) { try { mapControl.LoadMxFile(fileName); mapControl.Extent = mapControl.FullExtent; } catch (Exception ex) { msg = "ESRI Map Control generated an error.\nFile: " + fileName + "\nError: " + ex; } } else { msg = "Map document not valid: " + fileName; } } else if (ext == ".lyr") { try { mapControl.ClearLayers(); mapControl.SpatialReference = null; mapControl.AddLayerFromFile(fileName); mapControl.get_Layer(0).Visible = true; //Make sure the layer is visible //Set the Spatial Ref to match the current layer, not the previous layer. //mapControl.SpatialReference = mapControl.get_Layer(0).SpatialReference; mapControl.Extent = mapControl.FullExtent; } catch (Exception ex) { msg = "ESRI Map Control generated an error.\nFile: " + fileName + "\nError: " + ex; } } else { msg = "File must be a map document (.mxd) or a layer file (.lyr): " + fileName; } } else { msg = "File not found: " + fileName; } return(msg); }
public void outPut(string mxdPath, string shpName, string destPath, List <string> labelItems, int fontsize, AxMapControl axMapControl1, object locker, int width = 400, int height = 400) { /* mxdPath表示mxd文件,包括绝对路径 * shpName表示要截图的shapefile文件,包括绝对路径 * destPath表示保存文件的目录 * labelItems表示图片标注哪些文字 * fontsize表示标注字体大小 * axMapControll表示map控件,必须要的 * width和height表示生成图片的大小 */ //打开mxd文件 axMapControl1.LoadMxFile(mxdPath); #region 打开shapefile文件 string[] shp = new string[2]; shp[0] = System.IO.Path.GetDirectoryName(shpName); shp[1] = System.IO.Path.GetFileName(shpName); if (shp[0] == null) { return; } IFeatureClass pFC = openShapefile(shp[0], shp[1]); IFeatureCursor pFeatureCur = pFC.Search(null, false); IFeature pFeature = pFeatureCur.NextFeature(); #endregion //获取各字段的索引值 Hashtable i = Index(pFC); IEnvelope In_Envelope = new EnvelopeClass(); In_Envelope.PutCoords(0, 0, width, height); //若生成缩小图则设100,大图为400 while (pFeature != null) { ResultItem value = new ResultItem(); value = getFields(i, pFeature); string SaveFile = null; SaveFile = destPath + @"\" + Convert.ToString(value.Figure) + ".jpg"; number += 1; string names = labelName(labelItems, value); In_Envelope.CenterAt(value.Project_XY); Label(axMapControl1, In_Envelope, value, names, fontsize); screenShot(In_Envelope, SaveFile, axMapControl1, 4); //ratio = 1/Resolution 像素范围(单位:pixels) = 矩形框长宽(In_Envelope单位:米)*ratio pFeature = pFeatureCur.NextFeature(); } }
private void bGalleryOpenMap_ItemClick(object sender, ItemClickEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = false; //单选 ofd.Title = "选择地图文件"; ofd.Filter = "mxd文件|*.mxd"; ofd.InitialDirectory = Environment.SpecialFolder.Desktop.ToString(); if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.Yes) { FileInfo fi = new FileInfo(ofd.FileName); if (fi.Exists) { curAxMapControl.LoadMxFile(fi.FullName); curAxMapControl.ActiveView.Refresh(); } } }
/// <summary> /// 打开mxd文档 /// path为打开mxd文件的路径,mapControl加载该地图文档的地图控件名称 /// 日期2013-12-13 /// lntu_GISer1 /// </summary> public string OpenMxdFile(string path, AxMapControl mapControl) { string filename = openfileDialog(path); try { if (filename != "") { mapControl.LoadMxFile(filename); mapControl.Extent = mapControl.FullExtent; } return(filename); } catch (Exception e) { MessageBox.Show(e.Message); return(""); } }
public void outPut() { //打开mxd文件 axMapControl1.LoadMxFile(mxdPath); #region 打开shapefile文件 string[] shp = new string[2]; shp[0] = System.IO.Path.GetDirectoryName(shpName); shp[1] = System.IO.Path.GetFileName(shpName); if (shp[0] == null) { return; } IFeatureClass pFC = openShapefile(shp[0], shp[1]); IFeatureCursor pFeatureCur = pFC.Search(null, false); IFeature pFeature = pFeatureCur.NextFeature(); #endregion //获取各字段的索引值 Hashtable i = Index(pFC); IEnvelope In_Envelope = new EnvelopeClass(); In_Envelope.PutCoords(0, 0, width, height); //若生成缩小图则设100,大图为400 while (pFeature != null) { ResultItem value = new ResultItem(); value = getFields(i, pFeature); if ((int)i["垃圾类别"] == -1 || (value.Category.Contains("建筑垃圾") || value.Category.Contains("生活垃圾") || value.Category.Contains("疑似垃圾"))) { string SaveFile = null; SaveFile = destPath + @"\" + Convert.ToString(value.Figure) + ".jpg"; string names = labelName(labelItems, value); In_Envelope.CenterAt(value.Project_XY); Label(axMapControl1, In_Envelope, value, names, fontsize); screenShot(In_Envelope, SaveFile, axMapControl1, 4); //ratio = 1/Resolution 像素范围(单位:pixels) = 矩形框长宽(In_Envelope单位:米)*ratio } pFeature = pFeatureCur.NextFeature(); } }
//打开地图文档 public void OpenMapDocument(AxMapControl axMapControl1) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开地图文档"; openFileDialog.Filter = "地图文档(*.mxd)|*.mxd"; openFileDialog.ShowDialog(); string sFilePath = openFileDialog.FileName; if (axMapControl1.CheckMxFile(sFilePath)) { axMapControl1.LoadMxFile(sFilePath, 0, Type.Missing); } else { MessageBox.Show(sFilePath + "不是有效的地图文档路径"); return; } axMapControl1.Refresh(); }
//加载地图文档 private void loadMapDocument() { System.Windows.Forms.OpenFileDialog openFileDialog; openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开地图文档"; openFileDialog.Filter = "map documents(*.mxd)|*.mxd"; openFileDialog.ShowDialog(); string filePath = openFileDialog.FileName; if (axMapControl1.CheckMxFile(filePath)) { axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass; axMapControl1.LoadMxFile(filePath, 0, Type.Missing); axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; } else { MessageBox.Show(filePath + "不是有效的地图文档"); } }
//加载Mxd文件函数 private void addmxdfile(string fullfilepath, AxMapControl axMapControl1) { if (fullfilepath == "") { return; } if (axMapControl1.CheckMxFile(fullfilepath)) { axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass; axMapControl1.LoadMxFile(fullfilepath, 0, Type.Missing); IActiveView activeViw = axMapControl1.Map as IActiveView; activeViw.Extent = axMapControl1.FullExtent; axMapControl1.Refresh(); axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault; } else if (fullfilepath != "") { MessageBox.Show(fullfilepath + "是无效的地图文档"); } }
public static bool LoadMapData2(string mdbPath, AxMapControl mapControl, XmlNode configNode) { var factory = new AccessWorkspaceFactory(); try { mapControl.LoadMxFile(string.Format("{0}\\Map2.mxd", Application.StartupPath)); var ws = factory.OpenFromFile(mdbPath, 0) as IFeatureWorkspace; var node = configNode.SelectSingleNode("Layers"); var nodes = node.SelectNodes("Layer"); foreach (XmlNode layerNode in nodes) { ReplaceDataSource(layerNode.Attributes["NameInMap"].Value, layerNode.Attributes["Name"].Value, ws, mapControl); } mapControl.Refresh(); return(true); } catch { return(false); } }
public static void OpenMxd(string mxdPath) { AxMapControl.LoadMxFile(mxdPath); }
private void mapHost_Loaded(object sender, RoutedEventArgs e) { m_map.LoadMxFile("C:\\IPAN\\Exercise02\\SouthAmerica.mxd"); }
//文件数据导航栏双击事件 private void ucNaviFiles_TreeList_DoubleClick(object sender, EventArgs e) { TreeList tree = sender as TreeList; TreeListHitInfo hi = tree.CalcHitInfo(tree.PointToClient(Control.MousePosition)); if (hi.Node == null) { return; } string nodeName = (string)hi.Node["name"]; Control openFileTool = null; try { //如果已经有这个tabPage XtraTabPage ifTabPage = ComponentOperator.IfHasTabPage(nodeName, this.xtraTabControl_Main); if (ifTabPage != null) { this.xtraTabControl_Main.SelectedTabPage = ifTabPage; return; } //如果是文件夹,则返回 string type = (string)hi.Node["type"]; if (type == "Folder") { return; } //如果文件不存在 string path = (string)hi.Node["path"]; if (!File.Exists(path)) { MessageBox.Show("文件已丢失,请刷新文件目录后再尝试打开。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //如果不包含该TabPage,则新建 string extension = (string)hi.Node["ext"]; string fileType = ComponentOperator.GetFileTypeByExtension(extension); switch (fileType) { case "": if (MessageBox.Show("本系统暂不支持该格式[" + extension + "]的文件,是否尝试使用系统默认程序打开?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { System.Diagnostics.Process.Start(path); } return; case "RichTextEdit": RichEditControl rec = new RichEditControl(); rec.LoadDocument(path); openFileTool = rec; break; case "SpreadSheet": //表格控件 SpreadsheetControl ssc = new SpreadsheetControl(); ssc.LoadDocument(path); openFileTool = ssc; break; case "MapControl": AxMapControl mapControl = new AxMapControl(); mapControl.BeginInit(); //必须有begin和end mapControl.Location = new System.Drawing.Point(0, 0); mapControl.Name = "mapControl"; mapControl.Dock = DockStyle.Fill; //MapControl不支持先声明,后设置,故而直接设置 XtraTabPage xtp = new XtraTabPage(); xtp.Text = nodeName; xtp.Controls.Add(mapControl); mapControl.Dock = DockStyle.Fill; this.xtraTabControl_Main.TabPages.Add(xtp); this.xtraTabControl_Main.SelectedTabPage = xtp; mapControl.EndInit(); //必须有begin和end mapControl.Refresh(); xtp.Refresh(); this.xtraTabControl_Main.Refresh(); this.Refresh(); mapControl.LoadMxFile(path); break; default: return; } } catch (Exception ex) { Console.Write(ex.Message); } finally { if (openFileTool != null) { //TabPage XtraTabPage xtp = new XtraTabPage(); xtp.Text = nodeName; xtp.Controls.Add(openFileTool); openFileTool.Dock = DockStyle.Fill; this.xtraTabControl_Main.TabPages.Add(xtp); this.xtraTabControl_Main.SelectedTabPage = xtp; openFileTool.Refresh(); xtp.Refresh(); this.xtraTabControl_Main.Refresh(); this.Refresh(); } } }
public static void LoadGeoData(AxMapControl axMapControl1, AxMapControl axMapControl2, string strFileN) { string strFExtenN = System.IO.Path.GetExtension(strFileN); switch (strFExtenN) { case ".shp": { string strPath = System.IO.Path.GetDirectoryName(strFileN); string strFile = System.IO.Path.GetFileNameWithoutExtension(strFileN); axMapControl1.AddShapeFile(strPath, strFile); axMapControl2.ClearLayers(); axMapControl2.AddShapeFile(strPath, strFile); axMapControl2.Extent = axMapControl2.FullExtent; break; } case ".bmp": case ".tif": case ".jpg": case ".img": { IWorkspaceFactory pWSF = new RasterWorkspaceFactoryClass(); string pathName = System.IO.Path.GetDirectoryName(strFileN); string fileName = System.IO.Path.GetFileName(strFileN); IWorkspace pWS = pWSF.OpenFromFile(pathName, 0); IRasterWorkspace pRWS = pWS as IRasterWorkspace; IRasterDataset pRasterDataSet = pRWS.OpenRasterDataset(fileName); IRasterPyramid pRasPyramid = pRasterDataSet as IRasterPyramid; if (pRasPyramid != null) { if (!(pRasPyramid.Present)) { pRasPyramid.Create(); } } IRaster pRaster = pRasterDataSet.CreateDefaultRaster(); IRasterLayer pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromRaster(pRaster); ILayer pLayer = pRasterLayer as ILayer; axMapControl1.AddLayer(pLayer, 0); axMapControl2.ClearLayers(); axMapControl2.AddLayer(pLayer, 0); axMapControl2.Extent = axMapControl2.FullExtent; break; } case ".mxd": { if (axMapControl1.CheckMxFile(strFExtenN)) { axMapControl1.LoadMxFile(strFExtenN); } else { MessageBox.Show("所选择的文件不是Mxd文件!", "提示信息"); } break; } default: break; } }
//打开文件函数 public static void OpenFile(AxMapControl mapControl, AxMapControl mapControl2, AxPageLayoutControl pageLayoutControl) { OpenFileDialog OpenFdlg = new OpenFileDialog(); OpenFdlg.Title = "选择需要打开的文件"; OpenFdlg.Filter = "mxd文件|*.mxd|Shape文件|*.shp|IMG文件|*.img|TIF文件|*.tif|所有文件|*.*"; OpenFdlg.RestoreDirectory = true; if (OpenFdlg.ShowDialog() == DialogResult.OK) { string strFileName = OpenFdlg.FileName;//完全名 if (strFileName == string.Empty) { return; } string pathName = System.IO.Path.GetDirectoryName(strFileName); //位置 string strFExtendN = System.IO.Path.GetExtension(strFileName); //后缀名 string fileName = System.IO.Path.GetFileNameWithoutExtension(strFileName); //单独的文件名 string fileNameE = System.IO.Path.GetFileName(strFileName); //文件名和扩展名 switch (strFExtendN) { case ".shp": mapControl.AddShapeFile(pathName, fileName); OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl); break; case ".mxd": if (mapControl.CheckMxFile(strFileName)) { mapControl.MousePointer = esriControlsMousePointer.esriPointerHourglass; mapControl.LoadMxFile(strFileName, 0, Type.Missing); mapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl); } else { MessageBox.Show("所选文件不是地图文档文件!", "信息提示"); return; } break; case ".bmp": case ".BMP": case ".tif": case ".TIF": case ".jpg": case ".JPG": case ".img": case ".IMG": case ".png": case ".PNG": IWorkspaceFactory pWSF; pWSF = new RasterWorkspaceFactory(); IWorkspace pWS; pWS = pWSF.OpenFromFile(pathName, 0); IRasterWorkspace pRWS; pRWS = pWS as IRasterWorkspace; IRasterDataset pRasterDataset; pRasterDataset = pRWS.OpenRasterDataset(fileNameE); //影像金字塔判断与创建 IRasterPyramid pRasPyrmid; pRasPyrmid = pRasterDataset as IRasterDataset as IRasterPyramid; if (pRasPyrmid != null) { if (!(pRasPyrmid.Present)) { pRasPyrmid.Create(); //在进度条中说明正在创建金字塔 } } IRaster pRaster; pRaster = pRasterDataset.CreateDefaultRaster(); IRasterLayer pRasterLayer; pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromRaster(pRaster); ILayer pLayer = pRasterLayer as ILayer; mapControl.AddLayer(pLayer, 0); OperateFile.CopyAndOverwriteMap(mapControl, pageLayoutControl); OperateFile.ArchieveEagleEyeWhenAddRaster(mapControl2, strFileName); break; } } }
/// <summary> /// 打开mxd文档 /// path为打开mxd文件的路径,mapControl加载该地图文档的地图控件名称 /// 日期2013-12-13 /// lntu_GISer1 /// </summary> public string OpenMxdFile(string path,AxMapControl mapControl) { string filename = openfileDialog(path); try { if (filename != "") { mapControl.LoadMxFile(filename); mapControl.Extent = mapControl.FullExtent; } return filename; } catch(Exception e) { MessageBox.Show(e.Message); return ""; } }
//IMapDocument pMapDocument; /// <summary> /// 打开工程文档 /// </summary> /// <param name="pAxMapControl">axMapControl</param> private void loadMapDocument(AxMapControl pAxMapControl) { OpenFileDialog openFileDialog; openFileDialog = new OpenFileDialog(); openFileDialog.Title = "打开工程"; openFileDialog.Filter = "工程文档(*.mxd)|*.mxd"; if (openFileDialog.ShowDialog() == DialogResult.OK) { string sFilePath = openFileDialog.FileName; //需要添加 判断原来的AxMapControl中是不是有地图 if (pAxMapControl.CheckMxFile(sFilePath)) { pAxMapControl.MousePointer = esriControlsMousePointer.esriPointerHourglass; pAxMapControl.LoadMxFile(sFilePath, 0, Type.Missing); pAxMapControl.MousePointer = esriControlsMousePointer.esriPointerDefault; //加载鹰眼地图 //loadEagleEyeDocument(filePath); //pAxMapControl.Extent = pAxMapControl.FullExtent; } else { MessageBox.Show(sFilePath + "不是有效的工程文档!"); } } }
public void LoadFile(string filename) { AxMapControlMainMap.LoadMxFile(filename); }