基于C#的ArcEngine二次开发教程(15):栅格像素值的定位与读取

目录

1 接口与方法

1.1 IrasterLayer接口

1.2 axMapControl1_OnMouseDown事件

1.3 IRaster2接口

2 栅格属性的获取

3 像素值获取与显示

3.1 定义行列号全局变量

3.2 添加axMapControl1_OnMouseDown点击事件

3.3 添加【读像素】按钮

4 效果显示


1 接口与方法

1.1 IrasterLayer接口

1.2 axMapControl1_OnMouseDown事件

获取点击位置的像素坐标

1.3 IRaster2接口

成员

AttributeTable The raster value attribute table.
Colormap The colormap.
CreateCursorEx Creates a cursor with a given pixel block size or native block size.
GeodataXform The geodata transform.
GeoTransformations The set of geographic transformations to be applied.
GetPixelValue Gets the pixel value for a given band at a given column and row.
MapToPixel Converts a location (x, y) in map space into pixel space.
PixelToMap Converts a location (column, row) in pixel space into map space.
RasterDataset The parent raster dataset.
RasterXformer The raster transformer.
ToMapX Maps a pixel column to the x coordinate in map space.
ToMapY Maps a pixel row to the y coordinate in map space.
ToPixelColumn Maps a x coordinate in map space to the pixel column.
ToPixelRow Maps a y coordinate in map space to the pixel row.

Classes that implement IRaster2

Classes Description
Raster An in-memory representation of a dynamic raster that can perform resampling and reprojection.
其中IRaster2.MapToPixel可将地图坐标转化为行列号
[C#]public void MapToPixel (
    doublex,
    doubley,
    ref intpColumn,
    ref intpRow);
IRaster2.GetPixelValue获取对应波段和位置的像素值
[C#]public object GetPixelValue (
    intiBand,
    intiColumn,
    intiRow);

2 栅格属性的获取

private void 波段数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IRasterLayer myRasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;
            MessageBox.Show("查询到的影像波段数为" + myRasterLayer.BandCount.ToString(), "栅格信息");
        }

        private void 行列数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IRasterLayer myRasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;            
            MessageBox.Show("行数:" + myRasterLayer.RowCount.ToString() + "\r\n列数:"  + myRasterLayer.ColumnCount.ToString(), "栅格信息");
        }

        private void 图层名ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IRasterLayer myRasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;
            MessageBox.Show("图层名:" + myRasterLayer.Name, "栅格信息");            
        }

 

基于C#的ArcEngine二次开发教程(15):栅格像素值的定位与读取_第1张图片 多波段影像示意图

3 像素值获取与显示

3.1 定义行列号全局变量

        int col;
        int row;

3.2 添加axMapControl1_OnMouseDown点击事件

 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            IRasterLayer rstlyer = axMapControl1.get_Layer(0) as IRasterLayer;
            IRaster rst = rstlyer.Raster;
            IRaster2 rst2 = rst as IRaster2;
            rst2.MapToPixel(e.mapX, e.mapY, out col, out row);
        }

3.3 添加【读像素】按钮

        private void 读像素ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IRasterLayer myRasterLayer = axMapControl1.get_Layer(0) as IRasterLayer;
            IRaster myRaster = myRasterLayer.Raster;
            IRaster2 myRaster2 = myRaster as IRaster2;//ESRI.ArcGIS.DataSourcesRaster
            object ret = myRaster2.GetPixelValue(0, col, row);
            string rs = Convert.ToString(ret);
            MessageBox.Show("行数:" + row.ToString() + "列数:" + col.ToString() + "当前像元值为:"+rs);
            
        }

4 效果显示

 

你可能感兴趣的:(栅格数据)