ArcEngine栅格影像开发.doc_第1页
ArcEngine栅格影像开发.doc_第2页
ArcEngine栅格影像开发.doc_第3页
ArcEngine栅格影像开发.doc_第4页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1栅格数据处理常用到的接口:IRasterIRatserLayerIRasterDatasetIInterpolationOp IGeoDatasetIPixelBlock2 IPnt IRawPixels(read)IRaster(read)2. 加载栅格数据(1) 直接用IRasterLayer接口打开一个栅格文件并加载到地图控件IRasterLayer rasterLayer = new RasterLayerClass();rasterLayer.CreateFromFilePath(fileName); / fileName指存本地的栅格文件路径axMapControl1.AddLayer(rasterLayer, 0);(2) 用IRasterDataset接口打开一个栅格数据集IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();IWorkspace workspace;workspace = workspaceFactory.OpenFromFile(inPath, 0); /inPath栅格数据存储路径if (workspace = null)Console.WriteLine(Could not open the workspace.);return;IRasterWorkspace rastWork = (IRasterWorkspace)workspace;IRasterDataset rastDataset;rastDataset= rastWork.OpenRasterDataset(inName);/inName栅格文件名3. 读取栅格数据的属性和遍历栅格数据IRasterProps rasterProps = (IRasterProps)clipRaster;int dHeight = rasterProps.Height;/当前栅格数据集的行数int dWidth = rasterProps.Width; /当前栅格数据集的列数double dX = rasterProps.MeanCellSize().X; /栅格的宽度double dY = rasterProps.MeanCellSize().Y; /栅格的高度IEnvelope extent=rasterProps.Extent; /当前栅格数据集的范围rstPixelType pixelType=rasterProps.PixelType; /当前栅格像素类型IPnt pntSize = new PntClass();pntSize.SetCoords(dX, dY);IPixelBlock pixelBlock = clipRaster.CreatePixelBlock(pntSize);IPnt pnt = new PntClass();for (int i = 0; i dHeight; i+)for (int j = 0; j dWidth; j+)pnt.SetCoords(i, j);clipRaster.Read(pnt, pixelBlock);if (pixelBlock != null)object obj = pixelBlock.GetVal(0, 0, 0);MessageBox.Show( Convert.ToUInt32(obj).ToString();4. 提取指定的范围的栅格数据提取指定范围内的栅格数据通常用两种方法IRasterLayerExport(esriCarto), IExtractionOp, IExtractionOp2 (esriSpatialAnalyst),IRasterLayerExport接口提供的栅格数据提取功能有限,只能以矩形范围作为提取范围,而IExtractionOp接口提供了多边形,圆,属性,矩形等几种形式作为提取栅格数据.(1).IRasterLayerExport接口IRasterLayerExport rLayerExport = new RasterLayerExportClass();rLayerExport.RasterLayer = rasterLayer;/ rasterLayer指当前加载的栅格图层rLayerExport.Extent = clipExtent;/clipExtent指提取栅格数据的范围if (proSpatialRef != null)rLayerExport.SpatialReference = proSpatialRef;/ proSpatialRef当前栅格数据的投影信息IWorkspaceFactory pWF = new RasterWorkspaceFactoryClass();IWorkspace pRasterWorkspace = pWF.OpenFromFile(_folder, 0);/ _folder指栅格文件保存路径IRasterDataset outGeoDataset = rLayerExport.Export(pRasterWorkspace, code, strRasterType);/调用ISaveAs接口将导出的数据集保存.(2) IExtractionOp接口(调用此接口前,应该先检查空间许可)IExtractionOp extraction = new RasterExtractionOpClass();IGeoDataset geoDataset = extraction.Rectangle(IGeoDataset)clipRaster, clipExtent, true);IRaster raster = geoDataset as IRaster;if (raster != null)IWorkspaceFactory WF = new RasterWorkspaceFactoryClass();IWorkspace rasterWorkspace = WF.OpenFromFile(_folder, 0);ISaveAs saveAs = (ISaveAs)raster;saveAs.SaveAs(“Result.tif”, rasterWorkspace, TIFF);5. 创建栅格数据需要用到的接口有:IWorkspaceFactory, IRasterWorkspace2, IPoint, IRasterDataset, 实例代码如下:IWorkspaceFactory pWSF=new RasterWorkspaceFactoryClass();IRasterWorkspace pRasWS=pWSF.OpenFromFile(pFileName,0);IRasterWorkspace2 pRasWS2=pRasWS as IRasterWorkspace2;IPoint pOrigin=new PointClass();pOrigin.PutCoords(0,0);IRasterDataset pOutDS=pRasWS2.CreateRasterDataset(“test.tif”,”TIFF”,pOrigin,512,512,2,2,3,PT_FLOAT,null,true);6. 创建并设置单元格的值public IRasterDataset CreateRasterDataset2(string pRasterFile)trystring pDir = System.IO.Path.GetDirectoryName(pRasterFile);string pFileName = System.IO.Path.GetFileNameWithoutExtension(pRasterFile);IWorkspaceFactory pWsF = new RasterWorkspaceFactoryClass();IRasterWorkspace2 pRWs = pWsF.OpenFromFile(pDir, 0) as IRasterWorkspace2;/定义数据集投影ISpatialReference pSpatialRef = GetSpatialRef();double XLeftCorner = GetMapLeftX();double YBottomCorner = GetMapBottomY();double YTopCorner = GetMapTopY();double XRightCorner = GetMapRightX();/定义数据集的行列数、像元大小、波段数int pRows = GetRows();int pCols = GetColumns();double xCell = GetCellXSize();double yCell = GetCellYSize();int NumBand = 1;/修正起始点坐标IPoint pOrignPt = new PointClass();double dX = XLeftCorner - xCell / 2;double dY = YBottomCorner + yCell / 2;pOrignPt.PutCoords(dX, dY);/定义栅格数据集为GRID格式IRasterDataset pRDs = pRWs.CreateRasterDataset(pFileName, GRID, pOrignPt, pCols, pRows, xCell, yCell, NumBand, rstPixelType.PT_FLOAT, pSpatialRef, true);IRasterBandCollection pRBandCollection = pRDs as IRasterBandCollection;IRasterBand pRBand = pRBandCollection.Item(0);IRasterProps pRProp = pRBand as IRasterProps;IPnt pBlockSize = new PntClass();IEnvelope pEnvelope = pRProp.Extent;pBlockSize.SetCoords(pEnvelope.Width, pEnvelope.Height);IRasterDataset2 pRDs2 = pRDs as IRasterDataset2;IRaster pRaster = pRDs2.CreateFullRaster();IRaster2 pRaster2 = pRaster as IRaster2;IPixelBlock pixelBlock = pRaster2.CreateCursorEx(pBlockSize).PixelBlock;int w = pixelBlock.Width;int h = pixelBlock.Height;/read the first pixel blockIPnt topleftCorner = new PntClass();topleftCorner.SetCoords(XLeftCorner, YTopCorner);pRaster.Read(topleftCorner, pixelBlock);IPixelBlock3 pixelBlock3 = pixelBlock as IPixelBlock3;System.Array pixels = (System.Array)pixelBlock3.get_PixelData(0);for (int i = 0; i w; i+)for (int j = 0; j h; j+)if(i = j)pixels.SetValue(i*j, i, j); pixelBlock3.set_PixelData(0, (System.Object)pixels);/write the modified pixel block to the raster datasetIRasterEdit rasterEdit = (IRasterEdit)pRaster;rasterEdit.Write(topleftCorner, pixelBlock);/Release rasterEdit explicitly.System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);return pRDs;catch (Exception ex)System.Diagnostics.Debug.WriteLine(ex.Message);return null;7. 使用多边形裁剪影像Public Function ClipRasterByPolgon(pInGeoDataset As IGeoDataset, pPolygon As IPolygon) As IRaster Dim pRaster As IRaster If TypeOf pInGeoDataset Is IRasterLayer Then Dim pRasterlayer As IRasterLayer Set pRasterlayer = pInGeoDataset Set pRaster = pRasterlayer.Raster ElseIf TypeOf pInGeoDataset Is IRasterDataset Then Dim pRasterDataset As IRasterDataset Set pRasterDataset = pInGeoDataset Set pRaster = pRasterDataset.CreateDefaultRaster ElseIf TypeOf pInGeoDataset Is IRaster Then Set pRaster = pInGeoDataset Else Exit Function End If Dim pInputDataset As IGeoDataset Set pInputDataset = pRaster Dim pExtractionOp As IExtractionOp Set pExtractionOp = New RasterExtractionOp Dim pRasterAnalys

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论