GIS二次开发实验报告 下载本文

private void miStatistic_Click(object sender, EventArgs e) {

MapAnalysis mapAnalysis = new MapAnalysis(); string sMsg;

sMsg = mapAnalysis.Statistic(\ MessageBox.Show(sMsg); }

14.实验运行结果如下

24

6 实验六:栅格数据处理

6.1 实验目的

? 了解栅格数据的结构 ? 掌握创建栅格数据集的方法 ? 掌握栅格数据格式转换与镶嵌的方法 ? 掌握栅格数据的统计方法

6.2 实验内容

? 实现创建栅格数据集程序 ? 实现栅格数据格式转换程序 ? 实现栅格数据镶嵌程序 ? 实现栅格数据统计程序

6.3 实验步骤与结果

1.首先利用ArcCatalog在D:\\raster目录中创建一个文件数据库Raster,和个人数据库RasterDatabase,在个人数据库下新建栅格目录,并在栅格目录中加载栅格数据集C00000001.png与C00000000.png。

2.在主窗体添加“栅格管理”菜单项,添加下拉菜单项:文本“创建栅格数据集”,控件名“miCreateRaster”

3.添加类库“RasterUtil”并添加类库的引用。引用如下 using ESRI.ArcGIS.Geodatabase;

using ESRI.ArcGIS.DataSourcesRaster; using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.DataSourcesGDB; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Output; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.ADF;

using ESRI.ArcGIS.SystemUI; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Display;

25

4.添加“创建栅格数据集”函数,代码如下

public bool CreateRaster(string filePath, string rasterName) {

IRasterWorkspaceEx rasterWorksapceEx; //打开工作空间

rasterWorksapceEx = OpenRasterWorkspaceFromFileGDB(filePath); //设置储存参数

IRasterStorageDef storageDef = new RasterStorageDef(); storageDef.CompressionType = esriRasterCompressionType.esriRasterCompressionJPEG; IRasterDef rasterDef = new RasterDef(); ISpatialReferenceFactory2 srFactotry = new SpatialReferenceEnvironmentClass();

int gcsType = (int)esriSRGeoCSType.esriSRGeoCS_WGS1984; IGeographicCoordinateSystem geoCoordSystem = srFactotry.CreateGeographicCoordinateSystem(gcsType);

ISpatialReference spatialRef = (ISpatialReference)geoCoordSystem; rasterDef.SpatialReference = spatialRef; IRasterDataset rasterDataset;

rasterDataset = rasterWorksapceEx.CreateRasterDataset(rasterName, 3, rstPixelType.PT_FLOAT, storageDef, null, rasterDef, null); return true; }

5.添加“创建栅格数据集”点击事件响应函数,代码如下

private void miCreateRaster_Click(object sender, EventArgs e) {

RasterUtil rastUtil = new RasterUtil();

rastUtil.CreateRaster(\ } 6.运行结果

7.在“栅格管理”下新建下拉菜单项,文本“格式转换”,控件名“miRasterConvert” 8.添加“格式转换”函数,代码如下 ////栅格数据格式转换

public bool RasterConvert(string fileGDB, string oldRasterName, string filePath, string newRasterName) {

IWorkspace workspace;

26

IRasterWorkspaceEx rasterWorkspaceEx;

//打开输入工作空间

rasterWorkspaceEx = OpenRasterWorkspaceFromFileGDB(fileGDB); IRasterDataset rasterDataset rasterWorkspaceEx.OpenRasterDataset(oldRasterName);

IRasterBandCollection rasterBands = (IRasterBandCollection)rasterDataset; //打开输出工作空间

workspace = OpenRasterWorkspaceFromFile(filePath) as IWorkspace; //另存

rasterBands.SaveAs(newRasterName, workspace, \ return true; }

9.添加“格式转换”点击事件响应函数,代码如下

private void miRasterConvert_Click(object sender, EventArgs e) {

RasterUtil rastUtil = new RasterUtil();

rastUtil.RasterConvert(\\ } 10.运行结果

=

\\

11.在“栅格管理”菜单项添加下拉菜单,文本“影像镶嵌”,控件名“miRasterMosaic” 12.添加“影像镶嵌”函数,代码如下 //////影像镶嵌

public void Mosaic(string GDBName, string catalogName, string outputFolder, string outputName) {

//打开个人数据库

IWorkspaceFactory workspaceGDBFactory = new AccessWorkspaceFactoryClass(); IWorkspace GDBworkspace = workspaceGDBFactory.OpenFromFile(GDBName, 0); //打开栅格目录

IRasterWorkspaceEx rasterWorkspaceEx = (IRasterWorkspaceEx)GDBworkspace; IRasterCatalog rasterCatalog;

rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(catalogName); //定义

IMosaicRaster mosaicRaster = new MosaicRasterClass(); mosaicRaster.RasterCatalog = rasterCatalog;

//设置镶嵌选项

mosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH;

27