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

该博客围绕栅格数据展开,介绍了相关接口与方法,如IrasterLayer接口、axMapControl1_OnMouseDown事件、IRaster2接口。还阐述了栅格属性的获取,以及像素值获取与显示的具体步骤,包括定义行列号全局变量、添加点击事件和读像素按钮,最后展示了效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

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接口

成员

Read/write propertyAttributeTableThe raster value attribute table.
Read/write propertyColormapThe colormap.
MethodCreateCursorExCreates a cursor with a given pixel block size or native block size.
Read/write propertyGeodataXformThe geodata transform.
Read/write propertyGeoTransformationsThe set of geographic transformations to be applied.
MethodGetPixelValueGets the pixel value for a given band at a given column and row.
MethodMapToPixelConverts a location (x, y) in map space into pixel space.
MethodPixelToMapConverts a location (column, row) in pixel space into map space.
Read-only propertyRasterDatasetThe parent raster dataset.
Read-only propertyRasterXformerThe raster transformer.
MethodToMapXMaps a pixel column to the x coordinate in map space.
MethodToMapYMaps a pixel row to the y coordinate in map space.
MethodToPixelColumnMaps a x coordinate in map space to the pixel column.
MethodToPixelRowMaps a y coordinate in map space to the pixel row.

Classes that implement IRaster2

ClassesDescription
RasterAn 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, "栅格信息");            
        }

 

多波段影像示意图

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 效果显示

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

薛桂琴

喜欢的读者,可以打赏鼓励一下

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值