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

创建个人地理数据库创建栅格目录引入两幅被镶嵌影像添加控件和类库运行,加载镶嵌好的影像添加事件响应函数添加类成员函数

关键代码: 1.添加类成员函数

publicvoid Mosaic(stringGDBName, stringcatalogName, stringoutputFolder, stringoutputName) {

//打开个人数据库

IWorkspaceFactoryworkspaceGDBFactory = newAccessWorkspaceFactoryClass(); IWorkspaceGDBworkspace = workspaceGDBFactory.OpenFromFile(GDBName, 0); //打开要被镶嵌的影像所在的栅格目录

IRasterWorkspaceExrasterWorkspaceEx = (IRasterWorkspaceEx)GDBworkspace; IRasterCatalograsterCatalog;

rasterCatalog = rasterWorkspaceEx.OpenRasterCatalog(catalogName); //定义一个影像镶嵌对象

IMosaicRastermosaicRaster = newMosaicRasterClass(); //镶嵌栅格目录中的所有影像到一个输出栅格数据集 mosaicRaster.RasterCatalog = rasterCatalog;

//设置镶嵌选项

mosaicRaster.MosaicColormapMode = rstMosaicColormapMode.MM_MATCH; mosaicRaster.MosaicOperatorType = rstMosaicOperatorType.MT_LAST; //打开输出栅格数据集所在的工作空间

IWorkspaceFactoryworkspaceFactory = newRasterWorkspaceFactoryClass(); IWorkspace workspace = workspaceFactory.OpenFromFile(outputFolder, 0); //保存到目标栅格数据集,数据格式可以是tiff,img,gid... ISaveAssaveas = (ISaveAs)mosaicRaster;

saveas.SaveAs(outputName, workspace, \); }

2.添加事件响应函数

privatevoidmiRasterMosaic_Click(object sender, EventArgs e) {

RasterUtilrastUtil = newRasterUtil();

rastUtil.Mosaic(\, \, \, \); }

3.运行结果

实现栅格统计程序 实验思路:

本实验是要实现统计融合后的MosaicRaster.tif影像的均值和标准差。ArcGIS Engine为栅格统计提供了相关组件,RasterStatistics组件实现了IRasterStatistics接口。实现实验包括以下几个部分:

1.添加控件:在程序主菜单项“栅格管理”的下拉菜单中新增菜单项“栅格统计”

2.添加类成员函数:向栅格工具类添加“栅格统计”函数,统计栅格影像的均值和标准差。

3.添加事件响应函数:为菜单项“栅格统计”菜单项添加点击事件响应函数,完成栅格统计,并将结果以对话框形式展示出来。

关键代码:

1.添加栅格统计函数

publicstringRasterStistics(stringfilePath, stringrasterName) {

IWorkspace workspace;

IRasterWorkspacerasterWorksapce; //打开工作空间

rasterWorksapce = OpenRasterWorkspaceFromFile(filePath); workspace = (IWorkspace)rasterWorksapce; //打开栅格数据集

IRasterDatasetrasterDataset = rasterWorksapce.OpenRasterDataset(rasterName); //得到栅格波段

IRasterBandCollectionrasterBands = (IRasterBandCollection)rasterDataset; IEnumRasterBandenumRasterBand = rasterBands.Bands; //定义一个字符串统计结果

stringsRasterStisticsResult = \栅格统计结果:\\n\; //逐个波段统计,每个波段的均值和标准差

IRasterBandrasterBand = enumRasterBand.Next(); while (rasterBand != null) {

//调用获取栅格统计信息函数 boolbRes = false;

rasterBand.HasStatistics(outbRes); if (!bRes)

{

rasterBand.ComputeStatsAndHist(); }

sRasterStisticsResult += GetRasterStistics(rasterBand); rasterBand = enumRasterBand.Next(); }

returnsRasterStisticsResult; }

//功能:根据给定栅格波段,统计其均值和均方差,并以字符串形式返回 privatestringGetRasterStistics(IRasterBandrasterBand) {

IRasterStatisticsrasterStatistics = rasterBand.Statistics; stringstatisticsResult;

statisticsResult = \均值为:\ + rasterStatistics.Mean.ToString() + \标准差为:\ +rasterStatistics.StandardDeviation.ToString();

returnstatisticsResult; }

2.添加事件响应函数

privatevoidmiRasterstatistic_Click(object sender, EventArgs e) {

stringrasterStatistics;

RasterUtilrastUtil = newRasterUtil(); rasterStatistics =rastUtil.RasterStistics(\, \); MessageBox.Show(rasterStatistics); }

3.运行成果