1、1.直接用IRasterLayer接口打开一个栅格文件并加载到地图控件IRasterLayer rasterLayer = new RasterLayerClass();rasterLayer.CreateFromFilePath(fileName); / fileName指存本地的栅格文件路径axMapControl1.AddLayer(rasterLayer, 0);2. 用IRasterDataset接口打开一个栅格数据集IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();IWorkspace workspa
2、ce;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栅格文件名if (rast
3、Dataset = null)Could not open the raster dataset.5、如何读取栅格数据的属性和遍历栅格数据栅格数据的属性包括栅格大小,行数,列数,投影信息,栅格范围等等,见下面代码(假设当前加载的栅格文件栅格值存储方式为:UShort类型)IRasterProps rasterProps = (IRasterProps)clipRaster;int dHeight = rasterProps.Height;/当前栅格数据集的行数int dWidth = rasterProps.Width; /当前栅格数据集的列数double dX = rasterProps.M
4、eanCellSize().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
5、 = 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();6、如何提取指定的范围的栅格数据提取指定范围内的栅格数据通常用两种方法IRasterLayerExport(esr
6、iCarto), IExtractionOp, IExtractionOp2 (url=esriSpatialAnalyst/url),IRasterLayerExport接口提供的栅格数据提取功能有限,只能以矩形范围作为提取范围,而IExtractionOp接口提供了多边形,圆,属性,矩形等几种形式作为提取栅格数据.1).IRasterLayerExport接口IRasterLayerExport rLayerExport = new RasterLayerExportClass();rLayerExport.RasterLayer = rasterLayer;/ rasterLayer指当
7、前加载的栅格图层rLayerExport.Extent = clipExtent;/clipExtent指提取栅格数据的范围if (proSpatialRef !rLayerExport.SpatialReference = proSpatialRef;/ proSpatialRef当前栅格数据的投影信息IWorkspaceFactory pWF = new RasterWorkspaceFactoryClass();tryIWorkspace pRasterWorkspace = pWF.OpenFromFile(_folder, 0);/ _folder指栅格文件保存路径IRasterDa
8、taset outGeoDataset = rLayerExport.Export(pRasterWorkspace, code, strRasterType);/调用ISaveAs接口将导出的数据集保存.Catch(Exception ex)Throw new Argumention(ex.Message);2IExtractionOp接口(调用此接口前,应该先检查空间许可)IExtractionOp extraction = new RasterExtractionOpClass();IGeoDataset geoDataset = extraction.Rectangle(IGeoDat
9、aset)clipRaster, clipExtent, true);IRaster raster = geoDataset as IRaster;if (raster !IWorkspaceFactory WF = new RasterWorkspaceFactoryClass();IWorkspace rasterWorkspace = WF.OpenFromFile(_folder, 0);ISaveAs saveAs = (ISaveAs)raster;saveAs.SaveAs(“Result.tif”, rasterWorkspace, TIFFcatch (Exception e
10、x)MessageBox.Show(Ex.message);7栅格数据重采样栅格数据的重采样主要基于三种方法:最邻近采样(NEAREST),双线性ILINEAR)和三次卷积采样(CUBIC)。(1).最邻近采样:它用输入栅格数据中最临近栅格值作为输出值。因此,在重采样后的输出栅格中的每个栅格值, 都是输入栅格数据中真实存在而未加任何改变的值。这种方法简单易用,计算量小,重采样的速度最快。(2).双线性采样:此重采样法取待采样点(x,y)点周围四个邻点,在y方向(或X方向)内插两次,再在x方向(或y方向)内插一次,得到(x,y)点的栅格值。(3).三次卷积采样:这是进一步提高内插精度的一种方法。
11、它的基本思想是增加邻点来获得最佳插值函数。取待计算点周围相邻的16个点,与双线性采样类似,可先在某一方向上内插,如先在x方向上,每四个值依次内插四次,再根据四次的计算结果在y方上内插,最终得到内插结果代码示例:采用双线性采样IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass();rasterGeometryProc.Resample(rstResamplingTypes.RSP_CubicConvolution, newCellSize, clipRaster);Tag标签: 栅格数据 ArcEngine标签
12、:栅格 重分类 分类:AE二次开发 public static IRasterLayer SetViewShedRenderer(IRaster pInRaster,string sField,string sPath) IRasterDescriptor pRD = new RasterDescriptorClass(); pRD.Create(pInRaster, new QueryFilterClass(), sField);IReclassOp pReclassOp = new RasterReclassOpClass();IGeoDataset pGeodataset=pInRast
13、er as IGeoDataset;IRasterAnalysisEnvironment pEnv = pReclassOp as IRasterAnalysisEnvironment;IWorkspaceFactory pWSF=new RasterWorkspaceFactoryClass();IWorkspace pWS = pWSF.OpenFromFile(sPath, 0);pEnv.OutWorkspace = pWS;object objSnap = null;object objExtent = pGeodataset.Extent;pEnv.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ref objExtent, ref objSnap);pEnv.OutSpatialReference = pGeodataset.SpatialReference;IRaster
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1