码迷,mamicode.com
首页 > 其他好文 > 详细

不同数据的导入

时间:2017-06-23 13:09:21      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:金字塔   空间   view   保存   ram   store   cad   file   文件   

MXD文档导入

 1 private void btnLoadMxFile_Click(object sender, EventArgs e)
 2         {
 3             OpenFileDialog pOpenFile = new OpenFileDialog();
 4             pOpenFile.CheckFileExists = true;
 5             pOpenFile.Filter = "ArcMap文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt;|发布文件地图(*.pmf)|*.pmf";
 6             pOpenFile.Title = "打开地图文档";
 7             pOpenFile.Multiselect = false;
 8             pOpenFile.RestoreDirectory = true;                              //保存打开路径
 9             if (pOpenFile.ShowDialog() == DialogResult.OK)
10             {
11                 string fileName = pOpenFile.FileName;
12                 if (fileName == "") return;
13                 if (mainMapControl.CheckMxFile(fileName))
14                 {
15                     mainMapControl.ClearLayers();
16                     mainMapControl.LoadMxFile(fileName);                    //采用AxMapControl控件的LoadMxFile()方法添加MXD文档
17                 }
18                 else
19                 {
20                     MessageBox.Show(fileName + "是无效的地图文档!", "信息提示");
21                     return;
22                 }
23             }
24         }
 1  private void btnImapDocument_Click(object sender, EventArgs e)
 2         {
 3             OpenFileDialog pOpenFile = new OpenFileDialog();
 4             pOpenFile.CheckFileExists = true;
 5             pOpenFile.Filter = "ArcMap文档(*.mxd)|*.mxd;|ArcMap模板(*.mxt)|*.mxt;|发布文件地图(*.pmf)|*.pmf";
 6             pOpenFile.Title = "打开地图文档";
 7             pOpenFile.Multiselect = false;
 8             pOpenFile.RestoreDirectory = true;
 9             if (pOpenFile.ShowDialog() == DialogResult.OK)
10             {
11                 string fileName = pOpenFile.FileName;
12                 if (fileName == "") return;
13                 if (mainMapControl.CheckMxFile(fileName))
14                 {
15                     IMapDocument pMapDoc = new MapDocument();              //采用IMapDocument接口实例的Open()方法打开MXD文档
16                     pMapDoc.Open(fileName);
17                     mainMapControl.Map = pMapDoc.ActiveView.FocusMap;
18                     mainMapControl.ActiveView.Refresh();
19                 }
20                 else
21                 {
22                     MessageBox.Show(fileName + "是无效的地图文档!", "信息提示");
23                     return;
24                 }
25             }
26         }

Shp文档格式导入

 1 private void btnAddShapeFile_Click(object sender, EventArgs e)
 2         {
 3             OpenFileDialog pOpenFile = new OpenFileDialog();
 4             pOpenFile.CheckFileExists = true;
 5             pOpenFile.Filter = "Shape文件(*.shp)|*.shp";
 6             pOpenFile.Title = "打开shape文件";
 7             pOpenFile.Multiselect = false;
 8             pOpenFile.RestoreDirectory = true;
 9             if (pOpenFile.ShowDialog() == DialogResult.OK)
10             {
11                 string FullPath = pOpenFile.FileName;
12                 int pIndex = FullPath.LastIndexOf("\\");
13                 string pFilePath = FullPath.Substring(0, pIndex);//文件路径
14                 string pFileName = FullPath.Substring(pIndex + 1);//文件名
15                 mainMapControl.AddShapeFile(pFilePath, pFileName);            //AddShapeFile(文件路径,文件名)
16                 mainMapControl.ActiveView.Refresh();
17             }
18         }

栅格数据导入

 1  private void btnAddRasterFile_Click(object sender, EventArgs e)
 2         {
 3                 OpenFileDialog pFileDialog = new OpenFileDialog();
 4                 pFileDialog.Title = "打开栅格数据";
 5                 pFileDialog.Filter = "栅格数据(*.*)|*.img;*.bmp;*tif;*img|(*.img)|*.img|(*.tif)|*.tif;|(*.bmp)|*.bmp|(*.img)|*.img";
 6                 pFileDialog.Multiselect = true;//对选
 7                 pFileDialog.CheckFileExists = true;//判断是否存在文件,返回bool
 8                 if (pFileDialog.ShowDialog() == DialogResult.OK)
 9                 {
10                     //获取文件基本信息
11                     string fullPath = pFileDialog.FileName;
12                     int pIndex = fullPath.LastIndexOf("\\");
13                     string pFilePath = fullPath.Substring(0, pIndex);
14                     string pFileName = fullPath.Substring(pIndex + 1);
15                     //获取一个工作空间并转化为Raster栅格空间
16                     IWorkspaceFactory pWorkspaceFac = new RasterWorkspaceFactoryClass();
17                     IWorkspace pWorkspace = pWorkspaceFac.OpenFromFile(pFilePath, 0);//打开的是路径
18                     IRasterWorkspace pRasterWorkspace = pWorkspace as IRasterWorkspace;
19                     IRasterDataset pRasterDataset = pRasterWorkspace.OpenRasterDataset(pFileName);
20                     //金字塔判断与创建
21                     IRasterPyramid3 pRasterPyramid;
22                     pRasterPyramid = pRasterDataset as IRasterPyramid3;
23                     if (pRasterPyramid != null)//判断文件是否存在
24                     {
25                         if (!pRasterPyramid.Present)
26                         { pRasterPyramid.Create(); }
27                     }
28                     IRaster pRaster;
29                     pRaster = pRasterDataset.CreateDefaultRaster();
30                     IRasterLayer pRasterLayer;
31                     pRasterLayer = new RasterLayerClass();
32                     //pRasterLayer.CreateFromRaster(pRaster);
33                     pRasterLayer.CreateFromDataset(pRasterDataset);
34                     ILayer pLayer = pRasterLayer as ILayer;
35                     mainMapControl.AddLayer(pLayer);
36                     EagleEyeMapControl.AddLayer(pLayer);
37                     mainMapControl.ActiveView.Refresh();
38                     EagleEyeMapControl.ActiveView.Refresh();
39                 }
40             }

 

 CAD格式导入

 1 private void btnAddCadByLayer_Click(object sender, EventArgs e)
 2         {
 3             OpenFileDialog pOpenFileDia = new OpenFileDialog();
 4             pOpenFileDia.Title = "打开CAD数据文件";
 5             pOpenFileDia.Multiselect = true;
 6             pOpenFileDia.Filter = "CAD(*.dwg)|*.dwg";
 7             pOpenFileDia.CheckFileExists = true;
 8             if (pOpenFileDia.ShowDialog() == DialogResult.OK)
 9             {
10                 mainMapControl.ClearLayers();
11                 //string FullName=pOpenFileDia.FileName;
12                 //int pIndex=FullName.LastIndexOf("\\");
13                 //string filePath=FullName.Substring(0,pIndex);
14                 //string fileName=FullName.Substring(pIndex+1);
15 
16                 string filePath = System.IO.Path.GetDirectoryName(pOpenFileDia.FileName);    //使用System.IO.Path直接获取路径名称和文件名
17                 string fileName = System.IO.Path.GetFileName(pOpenFileDia.FileName);
18 
19                 IWorkspaceFactory pWorkspaceFac = new CadWorkspaceFactoryClass();
20                 IWorkspace pWorkspace = pWorkspaceFac.OpenFromFile(filePath, 0);
21                 IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
22 
23                 IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(fileName + ":Annotation"); //fileName是文件名,后面加上:Annotation/point/polyline/polygon是打开对应的注记、点、线、面文件
24                 IFeatureLayer pFeatureLayer = new FeatureLayerClass();   //featureLayer可以实例化,它是要素类的表现形式
25                 pFeatureLayer.FeatureClass = pFeatureClass;              //featureClass是存储数据,通过直接获取无法实例化,每一个featureClass都有一个Geometry模型 
26                 pFeatureLayer.Name = fileName;
27                 mainMapControl.AddLayer(pFeatureLayer);
28                 mainMapControl.ActiveView.Refresh();
29                 EagleEyeMapControl.AddLayer(pFeatureLayer);
30                 EagleEyeMapControl.ActiveView.Refresh();
31             }
32         }

 

不同数据的导入

标签:金字塔   空间   view   保存   ram   store   cad   file   文件   

原文地址:http://www.cnblogs.com/Ronaldo2011/p/7069213.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!