ArcEngine 栅格数据 总结

  • 商务合作
  • 								
    		
    	
    	
    	
    	

    GIS开发者

    gis,openlayers,leaflet,gis应用,geoai,geoserver,cesium,python,arcpy,arcmap,webgis

  • GIS论坛
  • 	


				

ArcEngine 栅格数据 总结

				

				
				

目录


本文大部分内容参考AO帮助文档和ArcMap帮助文档,大家实际使用中遇到的问题也可以在本帖下方留言交流,谢谢!
欢迎浏览,拒绝转载!

基础知识

栅格数据基础知识:传送门

栅格数据是由一系列等间距的格网矩阵组成,用来表达完整的主题、光谱、图像信息。
栅格数据模型分为栅格数据集(Raster dataset)、栅格目录(Raster catalog)、镶嵌数据集(Mosaic dataset)。他们以文件系统、个人地理数据库、文件地理数据库、企业地理数据库为数据源进行存储。

栅格数据集也就是我们经常所得的jpg、tif文件等, ArcGIS 将这些栅格数据抽象为 RasterDataset,栅格数据集就代表了磁盘中的一个文件,它由一个或多个波段组成。在使用栅格数据集的时候,栅格数据会被转换成 IMG 文件存储在数据库中。我们可以对栅格数据集进行一些操作,如改变空间参考,建立影像金字塔等。

栅格目录,正如其名字一样是一个目录,跟书的目录相似,它记录了一个或者多个栅格数据集,每一个栅格数据集都作为一条记录存储在栅格目录中。栅格目录对栅格数据集的管理有两种方式,托管和非托管。托管方式的时候,栅格数据是存储在数据库中, 非托管的时候,栅格目录记录了栅格数据集的路径,也就是栅格数据并没有存储在数据库中。当我们删除一条记录的时候,对我们的栅格数据没有任何影响。

镶嵌数据集可以说是栅格数据集和栅格目录的混合技术,它的存储方式和栅格目录类似,但是在使用的时候和普通的栅格数据集是一样的,镶嵌数据集用于管理和发布海量多分辨率,多传感器影像,对栅格数据提供了动态镶嵌和实时处理的功能。
对文件地理数据库、个人地理数据库和 ArcSDE 地理数据库中的栅格存储加以比较:

类图

在线地址:传送门
本地路径:本地路径:如 C:\Program Files (x86)\ArcGIS\DeveloperKit10.2\Diagrams\DataSourcesRasterObjectModel.pdf
##和栅格数据集有关的GP工具

栅格数据接口使用示例

打开栅格数据工作空间

 
     
     
     
     
  1. //Open a file geodatabase workspace as RasterWorkspace.
  2. static IRasterWorkspaceEx OpenFGDB(string FGDBPath)
  3. {
  4. //FGDBPath string example: c:\data\raster.gdb.
  5. IWorkspaceFactory2 workspaceFactory = new FileGDBWorkspaceFactoryClass();
  6. return (IRasterWorkspaceEx)workspaceFactory.OpenFromFile(FGDBPath, 0);
  7. }
  8. //Open an ArcSDE workspace as RasterWorkspace.
  9. static IRasterWorkspaceEx OpenSDE(string conString)
  10. {
  11. //conString example: SERVER=ais;INSTANCE=9200;VERSION=sde.DEFAULT;USER=raster;PASSWORD=raster.
  12. IWorkspaceFactory2 workspaceFactory = new SdeWorkspaceFactoryClass();
  13. return (IRasterWorkspaceEx)workspaceFactory.OpenFromString(conString, 0);
  14. }
  15. //Open an accessed workspace as RasterWorkspace.
  16. static IRasterWorkspaceEx OpenAccess(string PGDBPath)
  17. {
  18. //FGDBPath string example: c:\data\rasters.mdb.
  19. IWorkspaceFactory2 workspaceFactory = new AccessWorkspaceFactoryClass();
  20. return (IRasterWorkspaceEx)workspaceFactory.OpenFromFile(PGDBPath, 0);
  21. }
  22. //Open a file workspace as RasterWorkspace.
  23. static IRasterWorkspace OpenFileWorkspace(string wsPath)
  24. {
  25. //wsPath example: c:\data\rasters.
  26. IWorkspaceFactory workspaceFact = new RasterWorkspaceFactoryClass();
  27. return (IRasterWorkspace)workspaceFact.OpenFromFile(wsPath, 0);
  28. }

打开栅格数据集

 
     
     
     
     
  1. IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(datasetName);
 
     
     
     
     
  1. IRasterDataset rasterDataset = rasterWorkspaceEx.OpenRasterDataset(datasetName);

创建栅格数据集

  1. Creating a raster dataset(创建以文件存储的栅格数据集,如TIFF)
    1)Create a workspace.创建工作空间
    2)Create a TIFF file with specified width, height, pixel type, cell size, and other necessary dimensions.创建一个TIFF文件,并指定它的宽度,高度,像素类型、像元大小和其他必要的维度。
    3)Use the IPixelBlock and IRasterEdit interfaces to edit the pixel values.使用IPixelBlock 和 IRasterEdit 接口来编辑像元的值。
 
     
     
     
     
  1. public static IRasterDataset CreateRasterDataset(string Path, string FileName)
  2. {
  3. try
  4. {
  5. IRasterWorkspace2 rasterWs = OpenRasterWorkspace(Path);
  6. //Define the spatial reference of the raster dataset.
  7. ISpatialReference sr = new UnknownCoordinateSystemClass();
  8. //Define the origin for the raster dataset, which is the lower left corner of the raster.
  9. IPoint origin = new PointClass();
  10. origin.PutCoords(15.0, 15.0);
  11. //Define the dimensions of the raster dataset.
  12. int width = 100; //This is the width of the raster dataset.
  13. int height = 100; //This is the height of the raster dataset.
  14. double xCell = 30; //This is the cell size in x direction.
  15. double yCell = 30; //This is the cell size in y direction.
  16. int NumBand = 1; // This is the number of bands the raster dataset contains.
  17. //Create a raster dataset in TIFF format.
  18. IRasterDataset rasterDataset = rasterWs.CreateRasterDataset(FileName, "TIFF",
  19. origin, width, height, xCell, yCell, NumBand, rstPixelType.PT_UCHAR, sr,
  20. true);
  21. //If you need to set NoData for some of the pixels, you need to set it on band
  22. //to get the raster band.
  23. IRasterBandCollection rasterBands = (IRasterBandCollection)rasterDataset;
  24. IRasterBand rasterBand;
  25. IRasterProps rasterProps;
  26. rasterBand = rasterBands.Item(0);
  27. rasterProps = (IRasterProps)rasterBand;
  28. //Set NoData if necessary. For a multiband image, a NoData value needs to be set for each band.
  29. rasterProps.NoDataValue = 255;
  30. //Create a raster from the dataset.
  31. IRaster raster = rasterDataset.CreateFullRaster();
  32. //Create a pixel block using the weight and height of the raster dataset.
  33. //If the raster dataset is large, a smaller pixel block should be used.
  34. //Refer to the topic "How to access pixel data using a raster cursor".
  35. IPnt blocksize = new PntClass();
  36. blocksize.SetCoords(width, height);
  37. IPixelBlock3 pixelblock = raster.CreatePixelBlock(blocksize)as IPixelBlock3;
  38. //Populate some pixel values to the pixel block.
  39. System.Array pixels;
  40. pixels = (System.Array)pixelblock.get_PixelData(0);
  41. for (int i = 0; i < width; i++)
  42. for (int j = 0; j < height; j++)
  43. if (i == j)
  44. pixels.SetValue(Convert.ToByte(255), i, j);
  45. else
  46. pixels.SetValue(Convert.ToByte((i * j) / 255), i, j);
  47. pixelblock.set_PixelData(0, (System.Array)pixels);
  48. //Define the location that the upper left corner of the pixel block is to write.
  49. IPnt upperLeft = new PntClass();
  50. upperLeft.SetCoords(0, 0);
  51. //Write the pixel block.
  52. IRasterEdit rasterEdit = (IRasterEdit)raster;
  53. rasterEdit.Write(upperLeft, (IPixelBlock)pixelblock);
  54. //Release rasterEdit explicitly.
  55. System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);
  56. return rasterDataset;
  57. }
  58. catch (Exception ex)
  59. {
  60. System.Diagnostics.Debug.WriteLine(ex.Message);
  61. return null;
  62. }
  63. }
  64. public static IRasterWorkspace2 OpenRasterWorkspace(string PathName)
  65. {
  66. //This function opens a raster workspace.
  67. try
  68. {
  69. IWorkspaceFactory workspaceFact = new RasterWorkspaceFactoryClass();
  70. return workspaceFact.OpenFromFile(PathName, 0)as IRasterWorkspace2;
  71. }
  72. catch (Exception ex)
  73. {
  74. System.Diagnostics.Debug.WriteLine(ex.Message);
  75. return null;
  76. }
  77. }
  1. Creating a raster dataset in a geodatabase(创建以GDB存储的栅格数据集,如GRID)
    1)Create a file geodatabase workspace factory.创建哥FGDB的工作工厂对象。
    2)Create a raster workspace and query IRasterWorkspaceEx.创建一个栅格工作空间对象并且转换到IRasterWorkspaceEx对象上
    3)Define the storage and raster properties using the RasterStorageDef and RasterDef classes. 利用RasterStorageDef 和RasterDef 类定义栅格数据集的存储和栅格属性。
    4)Create the dataset using the CreateRasterDataset method.利用CreateRasterDataset方法创建栅格数据集。
 
     
     
     
     
  1. IWorkspaceFactory wsf = new FileGDBWorkspaceFactoryClass();
  2. IRasterWorkspaceEx ws = (IRasterWorkspaceEx)wsf.OpenFromFile(@"c:\temp\fgdb.gdb", 0);
  3. //Define the raster storage.
  4. IRasterStorageDef storage = new RasterStorageDefClass();
  5. storage.Tiled = true;
  6. storage.TileHeight = 128;
  7. storage.TileWidth = 128;
  8. //Define the spatial reference.
  9. IRasterDef rasterDef = new RasterDefClass();
  10. rasterDef.SpatialReference = new UnknownCoordinateSystemClass();
  11. //Create data.
  12. IRasterDataset rasterDs = ws.CreateRasterDataset("newraster", 3,
  13. rstPixelType.PT_SHORT, storage, "sde.DEFAULT", rasterDef, null);

访问HDF和NIFF数据的子集

一些栅格格式,如分层数据格式(HDF),可以在单个文件中包含多个subdatasets。访问HDF subdatasets使用IRasterDatasetJukebox接口,请参见下面的代码示例:

 
     
     
     
     
  1. IWorkspaceFactory wsf = new FileGDBWorkspaceFactoryClass();
  2. IRasterWorkspaceEx ws = (IRasterWorkspaceEx)wsf.OpenFromFile(@"c:\temp\fgdb.gdb", 0);
  3. //Define the raster storage.
  4. IRasterStorageDef storage = new RasterStorageDefClass();
  5. storage.Tiled = true;
  6. storage.TileHeight = 128;
  7. storage.TileWidth = 128;
  8. //Define the spatial reference.
  9. IRasterDef rasterDef = new RasterDefClass();
  10. rasterDef.SpatialReference = new UnknownCoordinateSystemClass();
  11. //Create data.
  12. IRasterDataset rasterDs = ws.CreateRasterDataset("newraster", 3,
  13. rstPixelType.PT_SHORT, storage, "sde.DEFAULT", rasterDef, null);

读取JPEG EXIF扩展标记信息

 
     
     
     
     
  1. public static void JPEG_EXIFtag(IRasterDataset exifDataset)
  2. {
  3. //exifDataset represents a raster dataset opened from a JPEG file that has EXIF tags.
  4. IDataset dataset = (IDataset)exifDataset;
  5. //Get the EXIF tags and the associated values.
  6. IPropertySet propertySet = dataset.PropertySet;
  7. System.Object tag_names;
  8. System.Object tag_values;
  9. propertySet.GetAllProperties(out tag_names, out tag_values);
  10. string[] stringNames = (string[])tag_names;
  11. object[] stringValues = (object[])tag_values;
  12. for (int i = 0; i < stringNames.Length - 1; i++)
  13. {
  14. System.Console.WriteLine(stringNames[i]);
  15. System.Console.WriteLine(stringValues[i]);
  16. }
  17. }

读取像素数据

  • 使用光栅游标访问像素数据
 
     
     
     
     
  1. public static void UsingRasterCursorWithPixelBlock(IRasterDataset2 rasterDs)
  2. {
  3. try
  4. {
  5. //Create a raster.
  6. IRaster2 raster2 = rasterDs.CreateFullRaster()as IRaster2;
  7. //Create a raster cursor with a system-optimized pixel block size by passing a null.
  8. IRasterCursor rasterCursor = raster2.CreateCursorEx(null);
  9. //Use the IRasterEdit interface.
  10. IRasterEdit rasterEdit = raster2 as IRasterEdit;
  11. //Loop through each band and pixel block.
  12. IRasterBandCollection bands = rasterDs as IRasterBandCollection;
  13. IPixelBlock3 pixelblock3 = null;
  14. long blockwidth = 0;
  15. long blockheight = 0;
  16. System.Array pixels;
  17. IPnt tlc = null;
  18. object v;
  19. long bandCount = bands.Count;
  20. do
  21. {
  22. pixelblock3 = rasterCursor.PixelBlock as IPixelBlock3;
  23. blockwidth = pixelblock3.Width;
  24. blockheight = pixelblock3.Height;
  25. pixelblock3.Mask(255);
  26. for (int k = 0; k < bandCount; k++)
  27. {
  28. //Get the pixel array.
  29. pixels = (System.Array)pixelblock3.get_PixelData(k);
  30. for (long i = 0; i < blockwidth; i++)
  31. {
  32. for (long j = 0; j < blockheight; j++)
  33. {
  34. //Get the pixel value.
  35. v = pixels.GetValue(i, j);
  36. //Do something with the value.
  37. }
  38. }
  39. //Set the pixel array to the pixel block.
  40. pixelblock3.set_PixelData(k, pixels);
  41. }
  42. //Write back to the raster.
  43. tlc = rasterCursor.TopLeft;
  44. rasterEdit.Write(tlc, (IPixelBlock)pixelblock3);
  45. }
  46. while (rasterCursor.Next() == true);
  47. System.Runtime.InteropServices.Marshal.ReleaseComObject(rasterEdit);
  48. }
  49. catch (Exception ex)
  50. {
  51. System.Diagnostics.Debug.WriteLine(ex.Message);
  52. }
  53. }
  • 使用RawBlocks 对象访问像素数据
    Raster pixels can be accessed through the IRasterEdit and IPixelBlock3 interfaces. These interfaces read and edit pixels on raster objects. The RawBlocks object, new at ArcGIS 10, works with pixels on a raster band. It reads pixels using an internal tiling structure and loops through the pixel blocks without resampling.
    This topic shows how to use the RawBlocks object to manipulate raster data at a pixel level.
    概要翻译:可以通过IRasterEdit 和 IPixelBlock3 接口访问栅格像素,这两个接口会在栅格对象本身读去和编辑栅格像素。在ArcGIS10版本以后,提供了使用RawBlocks 对象,它在栅格波段上操作像素,它使用一个内部瓦片结构和循环遍历像素块(没有重采样)读取像素。这一主题展示了如何使用RawBlocks对象在一个像素水平操纵栅格数据。
 
     
     
     
     
  1. public static void ReadWriteRawBlocks(IRasterDataset rasDs)
  2. {
  3. IRasterBandCollection rasBandCol = (IRasterBandCollection)rasDs;
  4. IRawBlocks rawBlocks;
  5. IRasterInfo rasInfo;
  6. IPixelBlock pb;
  7. // Iterate through each band of the dataset.
  8. for (int m = 0; m <= rasBandCol.Count - 1; m++)
  9. {
  10. // QI to IRawBlocks from IRasterBandCollection.
  11. rawBlocks = (IRawBlocks)rasBandCol.Item(m);
  12. rasInfo = rawBlocks.RasterInfo;
  13. // Create the pixel block.
  14. pb = rawBlocks.CreatePixelBlock();
  15. // Determine the tiling scheme for the raster dataset.
  16. int bStartX = (int)Math.Floor((rasInfo.Extent.Envelope.XMin -
  17. rasInfo.Origin.X) / (rasInfo.BlockWidth * rasInfo.CellSize.X));
  18. int bEndX = (int)Math.Ceiling((rasInfo.Extent.Envelope.XMax -
  19. rasInfo.Origin.X) / (rasInfo.BlockWidth * rasInfo.CellSize.X));
  20. int bStartY = (int)Math.Floor((rasInfo.Origin.Y -
  21. rasInfo.Extent.Envelope.YMax) / (rasInfo.BlockHeight *
  22. rasInfo.CellSize.Y));
  23. int bEndY = (int)Math.Ceiling((rasInfo.Origin.Y -
  24. rasInfo.Extent.Envelope.YMin) / (rasInfo.BlockHeight *
  25. rasInfo.CellSize.Y));
  26. // Iterate through the pixel blocks.
  27. for (int pbYcursor = startY; pbYcursor < endY; pbYcursor++)
  28. {
  29. for (int pbXcursor = startX; pbXcursor < endX; pbXcursor++)
  30. {
  31. // Get the pixel block.
  32. rawBlocks.ReadBlock(pbXcursor, pbYcursor, 0, pb);
  33. System.Array safeArray;
  34. // Put the pixel block into a SafeArray for manipulation.
  35. safeArray = (System.Array)pb.get_SafeArray(0);
  36. // Iterate through the pixels in the pixel block.
  37. for (int safeArrayHeight = 0; safeArrayHeight < pb.Height;
  38. safeArrayHeight++)
  39. {
  40. for (int safeArrayWidth = 0; safeArrayWidth < pb.Width;
  41. safeArrayWidth++)
  42. {
  43. // Use System.Array.SetValue to write the new pixel value back into the SafeArray.
  44. safeArray.SetValue(Convert.ToByte(128), safeArrayWidth,
  45. safeArrayHeight);
  46. }
  47. }
  48. // Set the SafeArray back to the pixel block.
  49. pb.set_SafeArray(0, safeArray);
  50. // Write the pixel block back to the dataset.
  51. rawBlocks.WriteBlock(pbXcursor, pbYcursor, 0, pb);
  52. }
  53. }
  54. }
  55. }

创建栅格属性表

 
     
     
     
     
  1. static void BuildRasterAttributeTable(IRasterDataset rasterDataset, ITable table)
  2. {
  3. //Cast to IRasterDatasetEdit2 to build a raster attribute table.
  4. IRasterDatasetEdit2 rasterDatasetEdit = (IRasterDatasetEdit2)rasterDataset;
  5. //Build a default raster attribute table with VALUE and COUNT fields.
  6. if (table == null)
  7. {
  8. rasterDatasetEdit.BuildAttributeTable();
  9. }
  10. else
  11. {
  12. //Assign the given table as the raster attribute table.
  13. rasterDatasetEdit.AlterAttributeTable(table);
  14. }
  15. }

读取栅格数据属性(官方文档)

主要用到的接口:

  1. IRasterProps
  2. IRasterBandCollection
  3. IRasterDataset
  4. IRasterPyramid3
  5. IRasterBand
    栅格属性列表:
    列数和行数(Columns and Rows):通过IRasterProps的Width和Height属性获取
    波段数量(Number of Bands):通过IRasterBandCollection接口获取(可以由IRaster对象跳转接口到此接口)
    像元大小(CellSize(X,Y)):通过IRasterProps的MeanCellSize
    格式(Format):通过IRasterDataset的Format属性获取
    源类型(Source Type):可以通过GP工具SetRasterProperties来设置。
    像素类型(Pixel Type):通过IRasterProps接口的PixelType 属性获取
    像素位深(Pixel Depth):根据像素类型来判断像素位深
    无数据值(NoData Value):通过IRasterProps 的NoDataValue属性获取
    颜色表/色带(Colormap):通过IRaster2接口的Colormap属性获取色带
    金字塔(Pyramids):通过IRasterPyramid3接口来创建、获取、删除金字塔(PS:用IRasterDataset接口跳转到IRasterPyramid3接口)
    压缩(Compression):通过IRasterDataset的CompressionType属性获取压缩类型
    范围(Extent):将IRasterDataset接口对象转换成IGeoDataset对象来范围信息
    空间参考(Spatial Reference):1)将IRasterDataset接口对象转换成IGeoDataset对象来获取空间参考信息 2)通过IRasterProps 的属性SpatialReference获取 3)其它方法
    统计(Statistics):通过IRasterBand接口的Statistics属性获取波段的统计信息
    波段集合:通过IRasterBandCollection 接口来添加、删除、获取波段。

构建金字塔

构建金字塔有两种方式:1)利用IRasterPyramid3接口来创建金字塔 2)利用GP工具创建金字塔
示例代码:
1)

 
     
     
     
     
  1. IRasterPyramid3 pRasterPyramid = rasterDataset as IRasterPyramid3;
  2. if (pRasterPyramid != null && !pRasterPyramid.Present)
  3. {
  4. //-1代表创建全部级别的金字塔,0代表删除金字塔,其它代表创建对应级别的金字塔
  5. pRasterPyramid.BuildPyramid(-1, rstResamplingTypes.RSP_NearestNeighbor);
  6. }

2)

 
     
     
     
     
  1. //如何监听GP消息请参考文章《ArcEngine GP笔记(持续补充中......)》
  2. ESRI.ArcGIS.DataManagementTools.BuildPyramids buildPyramids = new ESRI.ArcGIS.DataManagementTools.BuildPyramids();
  3. buildPyramids.in_raster_dataset = sRasterFile; //栅格数据源
  4. buildPyramids.resample_technique = cmbEditResample.Text; //重分类方法
  5. buildPyramids.compression_type = cmbEditCompressType.Text; //压缩类型
  6. buildPyramids.compression_quality = Convert.ToInt32(txtCompressQuality.Text); //压缩质量
  7. IGeoProcessorResult gpResult = m_geoProcesser.Execute(buildPyramids, null);
  8. if (gpResult.Status == ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
  9. {
  10. //do something
  11. }

个人经验:遇到数据量大的数据创建金字塔比较耗时,建议使用第二种方式GP工具创建金字塔,可以对GP工具进行监听,实时输出动态消息;数据量小的时候可以使用接口,简单快捷。个人经验仅供参考,如有意见,请留言!

栅格数据另存

栅格数据另存有两种方式:①利用ISaveAs和ISaveAs2接口 ②利用GP工具另存
示例代码:
1)ISaveAs2接口另存图片

 
     
     
     
     
  1. //去黑边
  2. IRasterProps pRasterProps=pRaster as IRasterProps;
  3. pRasterProps.NoDataValue=255;
  4. //另存输出
  5. ISaveAs2 pSaveAs = pRaster as ISaveAs2;
  6. if (!pSaveAs.CanSaveAs(sFormat))
  7. {
  8. XtraMessageBox.Show("不支持指定像素类型或文件格式的输出", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  9. return ;
  10. }
  11. IWorkspaceFactory worksapceFactory = new RasterWorkspaceFactoryClass();
  12. workspace = worksapceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(m_sOutputPath), 0);
  13. IDataset dataset = pSaveAs.SaveAs(System.IO.Path.GetFileName(m_sOutputPath), workspace, sFormat);

个人经验: ISaveAs 保存Grid格式数据技巧
2)可以利用CopyRaster工具拷贝一份栅格数据实现栅格数据的另存。

栅格数据裁切

栅格数据裁切有两种方式:①利用接口进行裁切 ②利用GP工具进行裁切
1)利用接口进行裁切
①基于IEnvelope对象裁切,主要用到的接口:IRasterGeometryProc

 
     
     
     
     
  1. IRasterGeometryProc pRasterGeometryProc = new RasterGeometryProcClass();
  2. pRasterGeometryProc.Clip(pClipEnvelope,pInputRaster)

②利用 IExtractionOp2接口进行裁切,然后用ISaveAs2接口保存裁切后的结果。代码链接:传送门(这种方法不支持含孔洞的面作为裁切范围)
③调用IClipFilter裁切,参考链接
④调用IRasterFunction裁切,参考链接

 
     
     
     
     
  1. // Create the Function Arguments object.
  2. IClipFunctionArguments rasterFunctionArguments = (IClipFunctionArguments)new
  3. ClipFunctionArguments();
  4. // The input data can be of type IRasterDataset, IRasterBand, or IRaster.
  5. rasterFunctionArguments.Raster = inputData;
  6. // Set the parameters for the function:
  7. // Set the clipping type (clip outside leaves the area inside the envelope untouched)
  8. rasterFunctionArguments.ClippingType =
  9. esriRasterClippingType.esriRasterClippingOutside;
  10. // Set the extents to clip to by providing a raster envelope object.
  11. rasterFunctionArguments.ClippingGeometry = rasterEnvelope;
  12. // Create the Raster Function object.
  13. IRasterFunction rasterFunction = new ClipFunction();
  14. // Create the Function Raster Dataset object.
  15. IFunctionRasterDataset functionRasterDataset = new FunctionRasterDataset();
  16. // Create a name object for the Function Raster Dataset.
  17. IFunctionRasterDatasetName functionRasterDatasetName = (IFunctionRasterDatasetName)
  18. new FunctionRasterDatasetName();
  19. // Specify the output file name for the new dataset (including the .afr extension at the end).
  20. functionRasterDatasetName.FullName = @"c:\temp\Clip.afr";
  21. functionRasterDataset.FullName = (IName)functionRasterDatasetName;
  22. // Initialize the new Function Raster Dataset with the Raster Function and its arguments.
  23. functionRasterDataset.Init(rasterFunction, rasterFunctionArguments);

2)调用Clip工具进行裁切,代码略(这块我做过基于范围、文件、ROI绘制图形的裁切,不会的可以留言,我可以把示例代码发过去)。
这块有几个注意事项:
① 注意输入数据和裁切范围要有坐标系
② 注意被裁切的数据和裁切范围是否可以叠加上
③ 注意将裁切范围转换到输入数据的坐标系上去
④ 如果基于栅格文件裁切,clipping_geometry设置为 “NONE”;如果基于矢量文件裁切,clipping_geometry设置为 “ClippingGeometry”;
⑤ 如果基于四角坐标裁切,注意rectangle参数格式;如果in_template_dataset不为空字符串或空对象,设置rectangle参数为“#”即可。

 
     
     
     
     
  1. in_rectangle = string.Format("{0} {1} {2} {3}", pEnvelope.XMin, pEnvelope.YMin, pEnvelope.XMax, pEnvelope.YMax);

栅格数据可视化

1.栅格数据渲染包括一下几种:

  • Raster Unique value Renderer 唯一值渲染
  • Raster Classify Renderer 分类渲染
  • Raster Stretch Renderer 色带拉伸渲染
  • RGB渲染,必须为多波段影像
    主要用到的接口:
  1. IRasterLayer
  2. IRasterRenderer


示例代码暂时略,有问题的同学可以留言。这块想着以后有时间的话以新帖子总结,顺便将色带总结了。

2.栅格图层的显示效果
栅格图层的显示效果受亮度、对比度、透明度等因素的影响。
用到的接口:
1)ILayerEffects
2)IRasterDisplayProps

栅格数据分析

分享几个我项目中用到的栅格分析功能的例子:
1)坡度分析

 
     
     
     
     
  1. private IRaster ProduceSlopeData(DirectoryInfo demFile, string outputFolder,
  2. string strOutputMeasurement, double zFactor, IGeoDataset inputGeoDataset, IWorkspace pWorkspace)
  3. {
  4. IRaster solpeRaster = null;
  5. ISurfaceOp pSurface = new RasterSurfaceOpClass();
  6. esriGeoAnalysisSlopeEnum enumSlope = (strOutputMeasurement == "DEGREE") ? esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopeDegrees :
  7. esriGeoAnalysisSlopeEnum.esriGeoAnalysisSlopePercentrise;
  8. IGeoDataset outSlopeDataset = pSurface.Slope(inputGeoDataset, enumSlope, zFactor);
  9. //输出坡度数据
  10. ISaveAs pSlopeSaveAs = outSlopeDataset as ISaveAs;
  11. string outputSlopeName = demFile.Parent.Name.ToUpper() +"SLP";
  12. //string outputSlopeName = demFile.Parent.Name + "SLP.tif";
  13. if (System.IO.File.Exists(System.IO.Path.Combine(outputFolder, outputSlopeName)))
  14. {
  15. IRasterDataset oldRasterDataset = (pWorkspace as IRasterWorkspace).OpenRasterDataset(outputSlopeName);
  16. (oldRasterDataset as IDataset).Delete();
  17. }
  18. IDataset solpeDataset = pSlopeSaveAs.SaveAs(outputSlopeName, pWorkspace, "GRID");
  19. //IDataset solpeDataset = pSlopeSaveAs.SaveAs(outputSlopeName, pWorkspace, "TIFF");
  20. IRasterDataset solpeRasterDataset = solpeDataset as IRasterDataset;
  21. if (solpeRasterDataset != null)
  22. {
  23. solpeRaster = solpeRasterDataset.CreateDefaultRaster();
  24. }
  25. System.Runtime.InteropServices.Marshal.ReleaseComObject(outSlopeDataset);
  26. System.Runtime.InteropServices.Marshal.ReleaseComObject(solpeRasterDataset);
  27. return solpeRaster;
  28. }

2)坡向分析

 
     
     
     
     
  1. private void ProduceAspectData(DirectoryInfo demFile, string outputFolder, IGeoDataset inputGeoDataset, IWorkspace pWorkspace)
  2. {
  3. ISurfaceOp pSurface = new RasterSurfaceOpClass();
  4. IGeoDataset outAspectDataset = pSurface.Aspect(inputGeoDataset);
  5. ISaveAs pAspectSaveAs = outAspectDataset as ISaveAs;
  6. string outputAspectName = demFile.Parent.Name.ToUpper() + "SPD";
  7. //string outputAspectName = demFile.Parent.Name + "SPD.tif";
  8. string outputAspectFilePath = System.IO.Path.Combine(outputFolder, outputAspectName);
  9. if (System.IO.File.Exists(outputAspectFilePath))
  10. {
  11. IRasterDataset oldRasterDataset = (pWorkspace as IRasterWorkspace).OpenRasterDataset(outputAspectName);
  12. (oldRasterDataset as IDataset).Delete();
  13. }
  14. IDataset aspectDataset = pAspectSaveAs.SaveAs(outputAspectName, pWorkspace, "GRID");
  15. //IDataset aspectDataset = pAspectSaveAs.SaveAs(outputAspectName, pWorkspace, "TIFF");
  16. System.Runtime.InteropServices.Marshal.ReleaseComObject(outAspectDataset);
  17. System.Runtime.InteropServices.Marshal.ReleaseComObject(aspectDataset);
  18. }

3)重分类

 
     
     
     
     
  1. private IRasterDataset ProduceSlopeZone(DirectoryInfo demFile, string outputFolder,
  2. IWorkspace pWorkspace, IRaster pInRaster)
  3. {
  4. if (pInRaster == null)
  5. {
  6. m_richTxtBoxLog.SelectionColor = System.Drawing.Color.Red;
  7. m_richTxtBoxLog.AppendText("生成高程带数据失败!\r\n");
  8. return null;
  9. }
  10. IReclassOp pReclassOp = new RasterReclassOpClass();
  11. IGeoDataset pGeodataset = pInRaster as IGeoDataset;
  12. INumberRemap pNumRemap = new NumberRemapClass();
  13. IRasterStatistics pRasterStatistic = GetRasterStatistics(pInRaster);
  14. pNumRemap.MapRange(0, 2, 0);
  15. pNumRemap.MapRange(2, 3, 2);
  16. pNumRemap.MapRange(3, 5, 3);
  17. pNumRemap.MapRange(5, 6, 5);
  18. pNumRemap.MapRange(6, 8, 6);
  19. pNumRemap.MapRange(8, 10, 8);
  20. pNumRemap.MapRange(10, 15, 10);
  21. pNumRemap.MapRange(15, 25, 15);
  22. pNumRemap.MapRange(25, 35, 25);
  23. pNumRemap.MapRange(35, 45, 35);
  24. if (pRasterStatistic.Maximum > 45)
  25. {
  26. pNumRemap.MapRange(45, 90, 45);
  27. }
  28. IRemap pRemap = pNumRemap as IRemap;
  29. IRaster2 pOutRaster = pReclassOp.ReclassByRemap(pGeodataset, pRemap, false) as IRaster2;
  30. //保存
  31. ISaveAs pAspectSaveAs = pOutRaster as ISaveAs;
  32. string outputAspectName = demFile.Parent.Name.ToUpper() + "SPZA.tif";
  33. if (System.IO.File.Exists(System.IO.Path.Combine(outputFolder, outputAspectName)))
  34. {
  35. IRasterDataset oldRasterDataset = (pWorkspace as IRasterWorkspace).OpenRasterDataset(outputAspectName);
  36. (oldRasterDataset as IDataset).Delete();
  37. }
  38. IDataset aspectDataset = pAspectSaveAs.SaveAs(outputAspectName, pWorkspace, "TIFF");
  39. System.Runtime.InteropServices.Marshal.ReleaseComObject(pInRaster);
  40. return (aspectDataset as IRasterDataset);
  41. }
  42. ///
  43. /// 获取栅格统计
  44. ///
  45. ///
  46. ///
  47. private IRasterStatistics GetRasterStatistics(IRaster pRaster)
  48. {
  49. if (null == pRaster)
  50. return null;
  51. IRasterBandCollection pRBandCol = pRaster as IRasterBandCollection;
  52. IRasterBand pRBand = pRBandCol.Item(0);
  53. if (pRBand.Statistics == null)
  54. {
  55. pRBand.ComputeStatsAndHist();
  56. }
  57. return pRBand.Statistics;
  58. }

和栅格数据相关的GP工具箱

和栅格数据有关的工具箱:3D Analyst Tools 、Data Management Tools、Spatial Analyst Tools 等工具箱。

具体内容不在此赘述,有问题的可以留言。


本文书写参考内容:
1)官方帮助文档
2)个人项目经验
3)参考博客:arcengine栅格数据使用总结
4)相关文档资料:CSDN下载-》ArcEngine 栅格数据总结.ppt

转载自:https://blog.csdn.net/yh0503/article/details/52644017

相关推荐

  • ArcEngine 图层标注 (根据字段、角度)
  • ArcEngine 图层标注 (根据字段、角度)
  • arcengine 数据转换和迁移函数说明
  • ArcEngine 拓扑检查 总结
  • 【转载】ArcEngine ITable 与System.DataTable相互转换
  • ArcEngine 数据查询、数据操作总结
			

You may also like...

分类

分类 选择分类目录 ArcEngine ArcGIS    ArcGISServer    ArcMap       水文分析    ArcPy database GDAL geospatial Geotrellis GIS    CAD    GIS理论    开源GIS       GeoServer          入门          安装          数据管理             数据设置             栅格数据             矢量数据       geotools       ogc       三维开发          cesium             cesium中级教程1             cesium初级入门1          threejs             threejs初级       开源GIS新闻 GIS+BIM GIS人工智能 GIS前沿 GIS大数据 GIS应用 GIS项目 OGR oraclespatial PostGreSQL PROJ webgis    arcgis api for javascript       3.x       4.x    ArcGIS API For JavaScript官方文档    leaflet    openlayers WebGIS 原理、设计、实现 开发工具    git 开发语言    C#    CSS    html5       bootstrap       echarts       ztree    Java    JavaScript       es6    Python       pyspider       Python教程       Python数据分析       Scrapy教程    vue 技术积累 操作系统    centos    ubuntu    windows 数据库    MongoDB    MySQL       nodejs    Oracle 空间分析 空间统计 算法 精选文章 网站建设 资源下载
		

标签

ArcGIS
arcgis api for javascript
arcgis api for javascript专栏
arcgis api for js
arcmap
ArcPy
cesium官方教程
es6
esri-leaflet入门教程(4)-加载各类图层
GDAL
geosanalysis
geoserver
GeoServer地图开发解决方案(一):环境搭建篇
GeoServer地图开发解决方案(二):地图数据处理篇
geostatistic
Geotools
geotrellis
GIS
git
leaflet
mongodb
ogr
openayers系列教程
openlayers
openlayers4
oracle spatial
PostGIS
postgresql
proj4
python教程
Python数据分析
scrapy
vue
webgis
人工智能
地图
地理信息
大数据
开源
智慧城市
空间分析
空间大数据
空间统计
自动驾驶

近期文章

  • windows远程桌面传送文件
  • ArcEngine获取mdb下要素类FeatureClass,独立要素类,没有dataset获取要素类
  • ArcEngine中调用字段计算器的实现Calculate Field工具
  • js获取地址栏参数
  • IDEA 每次启动springboot 报端口被占

版权说明

部分文章来自于网络,如有侵权,请联系我删除。

支付宝
微信支付
请使用 支付宝 或 微信 扫码支付
            
跳至工具栏
分享到:

你可能感兴趣的:(AE)