ArcGIS Engine 10 开发手册(8-8)示例:改变栅格数据像素的值
发布时间: 2018-01-16
所属分类: ArcGIS Engine 10 开发手册
本文通过代码演示如何改变栅格数据像素的值。
示例代码
public void ChangeRasterValue (IRasterDataset2 pRasterDatset)
{
IRaster2 pRaster2 = pRasterDatset.CreateFullRaster () as IRaster2;
IPnt pPntBlock = new PntClass ();
pPntBlock.X = 128;
pPntBlock.Y = 128;
IRasterCursor pRasterCursor = pRaster2.CreateCursorEx (pPntBlock);
IRasterEdit pRasterEdit = pRaster2 as IRasterEdit;
if (pRasterEdit.CanEdit ())
{
IRasterBandCollection pBands = pRasterDatset as IRasterBandCollection;
IPixelBlock3 pPixelblock3 = null;
int pBlockwidth = 0;
int pBlockheight = 0;
System.Array pixels;
IPnt pPnt = null;
object pValue;
long pBandCount = pBands.Count;
//获取Nodata
//IRasterProps pRasterPro = pRaster2 as IRasterProps;
//object pNodata = pRasterPro.NoDataValue;
do
{
pPixelblock3 = pRasterCursor.PixelBlock as IPixelBlock3;
pBlockwidth = pPixelblock3.Width;
pBlockheight = pPixelblock3.Height;
for (int k = 0; k < pBandCount; k++)
{
pixels = (System.Array) pPixelblock3.get_PixelData (k);
for (int i = 0; i < pBlockwidth; i++)
{
for (int j = 0; j < pBlockheight; j++)
{
pValue = pixels.GetValue (i, j);
if (Convert.ToInt32 (pValue) == 0)
{
pixels.SetValue (Convert.ToByte (50), i, j);
}
}
}
pPixelblock3.set_PixelData (k, pixels);
}
pPnt = pRasterCursor.TopLeft;
pRasterEdit.Write (pPnt,(IPixelBlock) pPixelblock3);
}
while (pRasterCursor.Next ());
System.Runtime.InteropServices.Marshal.ReleaseComObject (pRasterEdit);
}
}
处理结果
原始影像图:
处理后的影像图:
ArcGIS Engine 10 开发手册全集
ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子