客户要求从TIFF图像中提取光谱波段值,画光谱曲线。自己也是刚学AE,搞了半天才提取到光谱波段值。添加注释分享一下。
private void axMapControl_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
{
if (e.button == 2)
{
//栅格图层
var rasterLayer = this.axMapControl.get_Layer(0) as IRasterLayer;
//栅格图层光谱波段集合
var rasterBandCollection = rasterLayer.Raster as IRasterBandCollection;
//读取栅格图层的属性
var rasterProps = rasterLayer.Raster as IRasterProps;
//像素点X方向的大小(图层含有地理坐标)
double pixelXsize = (rasterProps.Extent.XMax - rasterProps.Extent.XMin) / rasterProps.Width;
//像素点Y方向的大小(图层含有地理坐标)
double pixelYsize = (rasterProps.Extent.YMax - rasterProps.Extent.YMin) / rasterProps.Height;
//栅格图层的位置(以像素为单位)
var pnt = new PntClass() { X = (e.mapX - rasterProps.Extent.XMin) / pixelXsize, Y = (rasterProps.Extent.YMax - e.mapY) / pixelYsize };
//定义像素块大小
IPixelBlock pixelBlock = rasterLayer.Raster.CreatePixelBlock(new PntClass() { X = 1, Y = 1 });
//将栅格图层中指定位置的像素信息读入像素块中
rasterLayer.Raster.Read(pnt,pixelBlock);
StringBuilder sb = new StringBuilder();
//遍历所有波段
for (int i = 0; i < rasterBandCollection.Count; i++)
{
//获取像素块中的值
sb.AppendFormat("{0}:{1};", rasterBandCollection.Item(i).Bandname, pixelBlock.GetVal(i, 0, 0));
}
this.Text = sb.ToString();
}
}
https://www.cnblogs.com/sunqin/archive/2012/12/11/2813378.html