




已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、栅格数据的存储类型栅格数据一般可以存储为ESRI GRID(由一系列文件组成),TIFF格式(包括一个TIF文件和一个AUX文件),IMAGINE Image格式 在AE中一般调用ISaveAs接口来保存栅格数据2、栅格数据集和栅格编目的区别一个栅格数据集由一个或者多个波段(RasterBand)的数据组成,一个波段就是一个数据矩阵。对于格网数据(DEM数据)和单波段的影像数据,表现为仅仅只有一个波段数据的栅格数据集,而对于多光谱影像数据则表现为具有多个波段的栅格数据集栅格编目(RasterCatalog)用于显示某个研究区域内各种相邻的栅格数据,这些相邻的栅格数据没有经过拼接处理合成一副大的影像图3、IRasterWorkspaceEx与IRasterWorkspace ,IRsterWorkspace2的区别1).IRasteWorkspaceEx接口主要是用来读取GeoDatabase中的栅格数据集和栅格编目2) . IRasterWorkspace ,IRsterWorkspace2主要是用来读取以文件格式存储在本地的栅格数据4、加载栅格数据(以存储在本地的栅格数据文件为例)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栅格文件名if (rastDataset = null)Console.WriteLine(Could not open the raster dataset.);return;5、如何读取栅格数据的属性和遍历栅格数据栅格数据的属性包括栅格大小,行数,列数,投影信息,栅格范围等等,见下面代码(假设当前加载的栅格文件栅格值存储方式为:UShort类型)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();6、如何提取指定的范围的栅格数据提取指定范围内的栅格数据通常用两种方法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();tryIWorkspace pRasterWorkspace = pWF.OpenFromFile(_folder, 0);/ _folder指栅格文件保存路径IRasterDataset outGeoDataset = rLayerExport.Export(pRasterWorkspace, code, strRasterType);/调用ISaveAs接口将导出的数据集保存.Catch(Exception ex)Throw new Argumention(ex.Message);2IExtractionOp接口(调用此接口前,应该先检查空间许可)IExtractionOp extraction = new RasterExtractionOpClass();tryIGeoDataset 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);catch (Exception ex)MessageBox.Show(Ex.message);62如何创建一个栅格数据public IRasterDataset CreateFileRasterDataset(string directoryName, string fileName)/ This function creates a new img file in the given workspace/ and then assigns pixel valuestryIRasterDataset rasterDataset = null;IPoint originPoint = new PointClass();originPoint.PutCoords(0, 0);/ Create the datasetIRasterWorkspace2 rasterWorkspace2 = null;rasterWorkspace2 = CreateRasterWorkspace(directoryName);rasterDataset = rasterWorkspace2.CreateRasterDataset(fileName, IMAGINE Image, originPoint, 200, 100, 1, 1, 1, rstPixelType.PT_UCHAR, new UnknownCoordinateSystemClass(), true);IRawPixelsrawPixels = null; /之后他代表第一波段(实际只有一个波段)纵横代码IPixelBlock3 pixelBlock3 = null; /承载栅格影像数据的块(内存块吗。)IPnt pixelBlockOrigin = null;IPnt pixelBlockSize = null;IRasterBandCollection rasterBandCollection;IRasterProps rasterProps;/ QI for IRawPixels and IRasterPropsrasterBandCollection = (IRasterBandCollection)rasterDataset;rawPixels =(IRawPixels)rasterBandCollection.Item(0);rasterProps =(IRasterProps)rawPixels;/Create pixelblock 创建像素块pixelBlockOrigin = new DblPntClass();pixelBlockOrigin.SetCoords(0, 0);pixelBlockSize =new DblPntClass();pixelBlockSize.SetCoords(rasterProps.Width, rasterProps.Height);pixelBlock3= (IPixelBlock3)rawPixels.CreatePixelBlock(pixelBlockSize); / 上述函数为参数为IPnt Size,返回值为IPixelBlock/ Read pixelblock 读取像素块,虽然它是由rawPixels创造的rawPixels.Read(pixelBlockOrigin, (IPixelBlock)pixelBlock3);/ Get pixeldata arraySystem.Object, pixelData;pixelData = (System.Object,)pixelBlock3.get_PixelDataByRef(0); /参数int plane/ Loop through all the pixels and assign valuefor (int i = 0; i rasterProps.Width; i+)for (int j = 0; j rasterProps.Height; j+)pixelDatai, j = (i * j) % 255;/ Write the pixeldata backSystem.Object cachePointer;cachePointer = rawPixels.AcquireCache();rawPixels.Write(pixelBlockOrigin, (IPixelBlock)pixelBlock3);rawPixels.ReturnCache(cachePointer);/ Return raster datasetreturn rasterDataset;catch (Exception ex)System.Diagnostics.Debug.WriteLine(ex.Message);return null;public IRasterWorkspace2 CreateRasterWorkspace(string pathName)/ Create RasterWorkspaceIWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass();return workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspace2;63依旧是生成栅格文件 public IRasterDataset CreateRasterDataset(string Path, string FileName) try /Create raster workspace. This example also works with any other workspaces that support raster data such as a file geodatabase (FGDB) workspace. /Access the workspace and the SDE workspace. IRasterWorkspace2 rasterWs = OpenRasterWorkspace(Path); /Define the spatial reference of the raster dataset. ISpatialReference sr = new UnknownCoordinateSystemClass(); /Define the origin for the raster dataset, which is the lower left corner of the raster. IPoint origin = new PointClass(); origin.PutCoords(15.0, 15.0); /Define the dimension of the raster dataset. int width = 100; /This is the width of the raster dataset. int height = 100; /This is the height of the raster dataset. double xCell = 30; /This is the cell size in x direction. double yCell = 30; /This is the cell size in y direction. int NumBand = 1; / This is the number of bands the raster dataset contains. /Create a raster dataset in grid format. IRasterDataset rasterDataset = rasterWs.CreateRasterDataset(FileName, GRID, origin, width, height, xCell, yCell, NumBand, rstPixelType.PT_UCHAR, sr, true); /Get the raster band. IRasterBandCollection rasterBands = (IRasterBandCollection)rasterDataset; IRasterBand rasterBand; IRasterProps rasterProps; rasterBand = rasterBands.Item(0); rasterProps = (IRasterProps)rasterBand; /Set NoData if necessary. For a multiband image, NoData value needs to be set for each band. rasterProps.NoDataValue = 255; /Create a raster from the dataset. IRaster raster = rasterDataset.CreateDefaultRaster(); /Create a pixel block. IPnt blocksize = new PntClass(); blocksize.SetCoords(width, height); IPixelBlock3 pixelblock = raster.CreatePixelBlock(blocksize) as IPixelBlock3; /Populate some pixel values to the pixel block. System.Array pixels; pixels = (System.Array)pixelblock.get_PixelData(0); for (int i = 0; i width; i+) for (int j = 0; j height; j+) if (i = j) pixels.SetValue(Convert.ToByte(255), i, j); else pixels.SetValue(Convert.ToByte(i * j) / 255), i, j); pixelblock.set_PixelData(0, (System.Array)pixels); /Define the location that the upper left corner of the pixel block is to write. IPnt upperLeft = new PntClass(); upperLeft.SetCoords(0, 0); /Write the pixel block. IRasterEdit rasterEdit = (IRasterEdit)raster; rasterEdit.Write(upperLeft, (IPixelBlock)pixelblock); /Release rasterEdit explicitly. System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit); return rasterDataset; catch (Exception ex) System.Diagnostics.Debug.WriteLine(ex.Message); return null; public IRasterWorkspace2 OpenRasterWorkspace(string PathName) /This function opens a raster workspace. try IWorkspaceFactory workspaceFact = new RasterWorkspaceFactoryClass(); return workspaceFact.OpenFromFile(PathName, 0) as IRasterWorkspace2; catch (Exception ex) System.Diagnostics.Debug.WriteLine(ex.Message); return null; 来自/ESRI/thread-50215-1-1.html7栅格数据重采样栅格数据的重采样主要基于三种方法:最邻近采样(NEAREST),双线性ILINEAR)和三次卷积采样(CUBIC)。(1).最邻近采样:它用输入栅格数据中最临近栅格值作为输出值。因此,在重采样后的输出栅格中的每个栅格值, 都是输入栅格数据中真实存在而未加任何改变的值。这种方法简单易用,计算量小,重采样的速度最快。(2).双线性采样:此重采样法取待采样点(x,y)点周围四个邻点,在y方向(或X方向)内插两次,再在x方向(或y方向)内插一次,得到(x,y)点的栅格值。(3).三次卷积采样:这是进一步提高内插精度的一种方法。它的基本思想是增加邻点来获得最佳插值函数。取待计算点周围相邻的16个点,与双线性采样类似,可先在某一方向上内插,如先在x方向上,每四个值依次内插四次,再根据四次的计算结果在y方上内插,最终得到内插结果代码示例:采用双线性采样IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass();rasterGeometryProc.Resample(rstResamplingTypes.RSP_CubicConvolution, newCellSize, clipRaster); 栅格数据重分类 (2009-01-10 10:10:09) 标签:栅格 重分类 分类: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=pInRaster 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; IRasterLayer pRLayer = new RasterLayerClass(); IRasterBandCollection pRsBandCol = pGeodataset as IRasterBandCollection; IRasterBand pRasterBand = pRsBandCol.Item(0); pRasterBand.ComputeStatsAndHist(); IRasterStatistics pRasterStatistic = pRasterBand.Statistics; double dMaxValue = pRasterStatistic.Maximum ; double dMinValue = pRasterStatistic.Minimum ; INumberRemap pNumRemap = new NumberRemapClass(); pNumRemap.MapRange(dMinValue, 0, 0); pNumRemap.MapRange(0, dMaxValue, 1); IRemap pRemap = pNumRemap as IRemap; IRaster pOutRaster = pReclassOp.ReclassByRemap(pGeodataset, pRemap, false) as IRaster ; pRLayer.CreateFromRaster(pOutRaster); return pRLayer; 栅格图层和矢量图层的属性表浏览 if (pLyr is IFeatureLayer) DataTable pTable = new DataTable(); IFeatureLayer pFealyr = pLyr as IFeatureLayer; IFeatureClass pFCls = pFealyr.FeatureClass; string shape = ; if (pFCls.ShapeType = esriGeometryType.esriGeometryPoint) shape = Point; else if (pFCls.ShapeType = esriGeometryType.esriGeometryPolyline) shape = Polyline; else if (pFCls.ShapeType = esriGeometryType.esriGeometryPolygon) shape = Polygon; for (int i = 0; i pFCls.Fields.FieldCount; i+) pTable.Columns.Add(pFCls.Fields.get_Field(i).Name); IFeatureCursor pCursor = pFCls.Search(null, false); int ishape = pFCls.Fields.FindField(Shape); IFeature pFea = pCursor.NextFeature(); while (pFea != null) DataRow pRow = pTable.NewRow(); for (int i = 0; i pFCls.Fields.FieldCount; i+) if (i = ishape) pRowi = shape; continue; pRowi = pFea.get_Value(i).ToString(); pTable.Rows.Add(pRow); pFea = pCursor.NextFeature(); dataGridView1.DataSource = pTable; else if (pLyr is IRasterLayer) IRasterLayer pRlyr = pLyr as IRasterLayer; IRaster pRaster = pRlyr.Raster; IRasterProps pProp = pRaster as IRasterProps; pProp.PixelType = rstPixelType.PT_LONG; if (pProp.PixelType = rstPixelType.PT_LONG) IRasterBandCollection pBcol = pRaster as IRasterBandCollection; IRasterBand pBand = pBcol.Item(0); ITable pRTable = pBand.AttributeTable; DataTable pTable = new DataTable(); for (int i = 0; i pRTable.Fields.FieldCount; i+) pTable.Columns.Add(pRTable.Fields.get_Field(i).Name); ICursor pCursor= pRTable.Search(null, false); IRow pRrow= pCursor.NextRow(); while (pRrow != null) DataRow pRow = pTable.NewRow(); for (int i =0 ;ipRrow .Fields .FieldCount ;i+) pRowi = pRrow.get_Value(i).ToString () ; pTable.Rows.Add(pRow); pRrow = pCursor.NextRow(); dataGridView1.DataSource = pTable; 创建栅格数据集 (2008-04-20 14:14:05) 标签:arcgis engine c 代码 it 分类:三文鱼的GIS 关键词:创建栅格数据集 IRasterWorkspace2 IRasterDataset CreateRasterDataset C# public IRasterDataset CreateFileRasterDataset(string directoryName, string fileName) / This function creates a new img file in the given workspace / and then assigns pixel values try IRasterDataset rasterDataset = null; IPoint originPoint = new PointClass(); originPoint.PutCoords(0, 0); / Create the dataset IRasterWorkspace2 rasterWorkspace2 = null; rasterWorkspace2 = CreateRasterWorkspace(directoryName); rasterDataset = rasterWorkspace2.CreateRasterDataset(fileName, IMAGINE Image, originPoint, 200, 100, 1, 1, 1, rstPixelType.PT_UCHAR, new UnknownCoordinateSystemClass(), true); IRawPixels rawPixels = null; IPixelBlock3 pixelBlock3 = null; IPnt pixelBlockOrigin = null; IPnt pixelBlockSize = null; IRasterBandCollection rasterBandCollection; IRasterProps rasterProps; / QI for IRawPixels and IRasterProps rasterBandCollection = (IRasterBandCollection)rasterDataset; rawPixels = (IRawPixels)rasterBandCollection.Item(0); rasterProps = (IRasterProps)rawPixels; / Create pixelblock pixelBlockOrigin = new DblPntClass(); pixelBlockOrigin.SetCoords(0, 0); pixelBlockSize = new DblPntClass(); pixelBlockSize.SetCoords(rasterProps.Width, rasterProps.Height); pixelBlock3 = (IPixelBlock3)rawPixels.CreatePixelBlock(pixelBlockSize); / Read pixelblock rawPixels.Read(pixelBlockOrigin, (IPixelBlock)pixelBlock3); / Get pixeldata array System.Object, pixelData; pixelData = (System.Object,)pixelBlock3.get_PixelDataByRef(0); / Loop through all the pixels and assign value for (int i = 0; i rasterProps.Width; i+) for (int j = 0; j rasterProps.Height; j+) pixelDatai, j = (i * j) % 255; / Write the pixeldata back System.Object cachePointer; cachePointer = rawPixels.AcquireCache(); rawPixels.Write(pixelBlockOrigin, (IPixelBlock)pixelBlock3); rawPixels.ReturnCache(cachePointer); / Return raster dataset return rasterDataset; catch (Exception ex) System.Diagnostics.Debug.WriteLine(ex.Message); return null; public IRasterWorkspace2 CreateRasterWorkspace(string pathName) / Create RasterWorkspace IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactoryClass(); return workspaceFactory.OpenFromFile(pathName, 0) as IRasterWorkspace2; public IRasterDataset tin2raster(string tempBathyTIN,string geoPath, string gridName) string tinFolder = System.IO.Path.GetDirectoryName(tempBathyTIN); string tinName = System.IO.Path.GetFileName(tempBathyTIN); IRasterDataset rasterDataset = new RasterDatasetClass(); try string rasterPath = System.IO.Path.GetDirectoryName(geoPath); IWorkspaceFactory TinWF = new TinWorkspaceFactory(); ITinWorkspace TinWK = TinWF.OpenFromFile(tinFolder,0)as ITinWorkspace; ITinA
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 财务分析的意义和内容说课稿-2025-2026学年中职专业课-财务管理-财经类-财经商贸大类
- unit 7 Today is Monday教学设计-2025-2026学年小学英语四年级下册北师大版(一起)
- 第1课 寻根之旅教学设计-2025-2026学年初中艺术·美术人教版2024七年级下册-人教版2024
- 幼儿的社会行为与道德发展说课稿-2025-2026学年中职专业课-幼儿心理学-学前教育类-教育与体育大类
- 外研版八年级上册英语全册教学设计(配2025年秋改版教材)
- 跳动的琴弦(欣赏 阳光照耀着塔什库尔)教学设计-2025-2026学年小学音乐西师大版五年级上册-西师大版
- 蓄电池知识培训内容课件
- 2025年天津市红桥区中考三模物理试题(解析版)
- 2025年四川省资阳市中考英语试卷(含答案与解析)
- 第1章 生命的世界说课稿-2025-2026学年初中生物学北师大版七年级上册-北师大版
- 2025 护理法律风险防范课件
- 2024-2025学年北京市西城区高一(下)期末数学试卷(含解析)
- 2025年网格员招聘笔试题库含答案
- 造型基础教学课件
- 抗菌型PE(聚乙烯)保鲜膜行业深度调研及发展项目商业计划书
- 行政单位固定资产培训
- 中国先秦文学课件
- 园林绿化监理质量控制措施
- 2022年版新课程标准解析与教学指导
- 森林生态系统韧性-洞察及研究
- 2025年湖北省中考语文试卷真题(含标准答案)
评论
0/150
提交评论