C#+arcengine获得栅格数据的像素值(高程)
2015-02-03 19:28
549 查看
此文问获得栅格数据的像元值(即高程),有可能部分见解不到位,望大神看到了不惜指教!
/// <summary>
/// 得到高程(通过像素值)
/// </summary>
/// <param name="maskTifPath">Raster路径</param>
private List<int> GetElevation(string maskTifPath, List<IPoint> pointColList)//pointcollist是点集合,可以参照博文获得点集合
{
IRaster raster = GetRaster(maskTifPath);//参见博文获得raster数据
//得到一段光栅带
IRasterBandCollection rasterBandCollection = (IRasterBandCollection)raster;
for (int icount = 0; icount < rasterBandCollection.Count; icount++)//测试数据count为1
{
IRasterBand rasterBand = rasterBandCollection.Item(icount);
//像素
IRawPixels rawPixels = (IRawPixels)rasterBand;
IRasterProps rasterProps = (IRasterProps)rawPixels;
//IGeoDataset geodataset = (IGeoDataset)raster;
//IEnvelope2 envelop = new EnvelopeClass();
//envelop = (IEnvelope2)geodataset.Extent;
//IPoint point = envelop.UpperLeft;
// 像元大致范围
//double blockX = (double)rasterProps.MeanCellSize().X;//网格X间距
//double blockY = (double)rasterProps.MeanCellSize().Y;//网格Y间距
//double blockArea = blockX * blockY;//网格面积
//int columns = rasterProps.Width;//dem列数
//int rows = rasterProps.Height;//dem行数
// 指定像素块大小
IPnt blockSize = new DblPnt();
//blockSize.X = columns;
//blockSize.Y = rows;
blockSize.X = 5;//赋值为多少比较合适?
blockSize.Y = 5;
//blockSize.X = blockX;
//blockSize.Y = blockY;
//指定像素块大小来创建像素快
IPixelBlock3 pixelBlock = (IPixelBlock3)rawPixels.CreatePixelBlock(blockSize);
IPnt blockOrigin = new DblPnt();
IPoint point = new PointClass();
List<int> pixels = new List<int>();
for (int j = 0; j < pointColList.Count; j++)
{
point = pointColList[j];
blockOrigin.X = point.X;
blockOrigin.Y = point.Y;
// 读取指定位置的像素块(blockOrigin为指定位置)
rawPixels.Read(blockOrigin, (IPixelBlock)pixelBlock);
//存储格网dem的二维数组
System.Array pixelData = (System.Array)pixelBlock.get_PixelDataByRef(icount);
// 获得每一个栅格的高程值
for (int col = 0; col < pixelData.GetLength(0); col++)
{
for (int row = 0; row < pixelData.GetLength(1); row++)
{
pixels.Add(Convert.ToInt32(pixelData.GetValue(col, row)));
}
}
return pixels;
}
}
}
本博文参照http://www.docin.com/p-607056135.html,感谢!
/// <summary>
/// 得到高程(通过像素值)
/// </summary>
/// <param name="maskTifPath">Raster路径</param>
private List<int> GetElevation(string maskTifPath, List<IPoint> pointColList)//pointcollist是点集合,可以参照博文获得点集合
{
IRaster raster = GetRaster(maskTifPath);//参见博文获得raster数据
//得到一段光栅带
IRasterBandCollection rasterBandCollection = (IRasterBandCollection)raster;
for (int icount = 0; icount < rasterBandCollection.Count; icount++)//测试数据count为1
{
IRasterBand rasterBand = rasterBandCollection.Item(icount);
//像素
IRawPixels rawPixels = (IRawPixels)rasterBand;
IRasterProps rasterProps = (IRasterProps)rawPixels;
//IGeoDataset geodataset = (IGeoDataset)raster;
//IEnvelope2 envelop = new EnvelopeClass();
//envelop = (IEnvelope2)geodataset.Extent;
//IPoint point = envelop.UpperLeft;
// 像元大致范围
//double blockX = (double)rasterProps.MeanCellSize().X;//网格X间距
//double blockY = (double)rasterProps.MeanCellSize().Y;//网格Y间距
//double blockArea = blockX * blockY;//网格面积
//int columns = rasterProps.Width;//dem列数
//int rows = rasterProps.Height;//dem行数
// 指定像素块大小
IPnt blockSize = new DblPnt();
//blockSize.X = columns;
//blockSize.Y = rows;
blockSize.X = 5;//赋值为多少比较合适?
blockSize.Y = 5;
//blockSize.X = blockX;
//blockSize.Y = blockY;
//指定像素块大小来创建像素快
IPixelBlock3 pixelBlock = (IPixelBlock3)rawPixels.CreatePixelBlock(blockSize);
IPnt blockOrigin = new DblPnt();
IPoint point = new PointClass();
List<int> pixels = new List<int>();
for (int j = 0; j < pointColList.Count; j++)
{
point = pointColList[j];
blockOrigin.X = point.X;
blockOrigin.Y = point.Y;
// 读取指定位置的像素块(blockOrigin为指定位置)
rawPixels.Read(blockOrigin, (IPixelBlock)pixelBlock);
//存储格网dem的二维数组
System.Array pixelData = (System.Array)pixelBlock.get_PixelDataByRef(icount);
// 获得每一个栅格的高程值
for (int col = 0; col < pixelData.GetLength(0); col++)
{
for (int row = 0; row < pixelData.GetLength(1); row++)
{
pixels.Add(Convert.ToInt32(pixelData.GetValue(col, row)));
}
}
return pixels;
}
}
}
本博文参照http://www.docin.com/p-607056135.html,感谢!
相关文章推荐
- C#+Arcengine实现GP工具中的extract by mask(提取掩膜),可以实现提取shp范围的栅格数据,可用来获得shp范围的高程
- C#+arcengine获得栅格数据
- C#+arcengine实现栅格计算器的减功能(可以用来修改栅格数据的高程)
- C#+arcengine获得栅格数据的属性表
- C#+arcengine实现输出水深图的功能(通过淹没区域和dem高程数据)(包含栅格计算器(减)、feature to line、产生随机点、获得高程、extract values to poin)
- C#+arcengine修改栅格数据的像元值
- C#+ArcEngine:加载打开Shp矢量数据和栅格数据(VS2010窗体+代码)
- C#+arcengine实现获得raster相应边界的Z值(高程)
- C#+ArcEngine加载影像Raster栅格数据,并与ArcGIS一样判断是否创建金字塔。
- C#+Arcengine实现GP工具中Data Management Tool》raster》raster processing中的clip功能(矢量数据对栅格数据的裁剪)
- ArcEngine,C#数据删除几种方法以及性能比较
- WinForm(C#)CheckedlistBox绑定数据,并获得选中的值(ValueMember)和显示文本(DisplayMember
- .net C# 获得数据集行和列
- ArcEngine和GDAL读写栅格数据机制对比(一)
- 基于ArcEngine+C#设计与开发国土资源一张图空间数据管理平台软件
- (转)arcengine栅格数据使用总结
- ArcEngine加载SDE中的栅格数据的问题
- C#获得SQLServer服务器名、数据库名、表名、以及字段名【转载】
- ArcEngine,C#删除数据几种方法和性能比较
- C#应用GDAL通过传入范围获取tif数据的最大高程值及其坐标