【 类 型】
【栅格数据集】由一个或多个波段组成,一个波段就是数据矩阵
【接口介绍】
IRasterLayer pDEMRLayer = axMapControl1.get_Layer(1) as IRasterLayer;
IRaster pDEMR = pDEMRLayer.Raster;
IRasterProps pRasterProps = (IRasterProps)(pDEMRLayer.Raster);
//存储每个栅格的X坐标和Y坐标
double blockX = pRasterProps.MeanCellSize().X;
double blockY = pRasterProps.MeanCellSize().Y;
//栅格数据左上角栅格的空间坐标
double Xm = pRasterProps.Extent.XMin + blockX / 2;
double Ym = pRasterProps.Extent.YMin + blockX / 2;
int dHeight = pRasterProps.Height;//当前栅格数据集的行数
int dWidth = pRasterProps.Width; //当前栅格数据集的列数
IPnt pnt = new PntClass();
//读取栅格信息
pnt.SetCoords(0, 0);//0,0取值窗口的起始位置在原栅格数据上的位置
IPnt pntSize = new PntClass();
pntSize.SetCoords(dWidth, dHeight);//设置取值窗口的行列,注意这里是先列后行
IPixelBlock pixelBlock = pDEMR.CreatePixelBlock(pntSize);//生成像素块
pDEMR.Read(pnt, pixelBlock);
List<IPoint> depthList = new List<IPoint>();
for (int i = 0; i < dHeight; i++)
for (int j = 0; j < dWidth; j++)
{
object obj = Convert.ToDouble(pixelBlock.GetVal(0, i, j));
}
【位置】MainForm的静态方法
public static AxMapControl globalMapControl = null; //存放axMapControl,作为全局变量
// 在MainForm加载函数中添加最后一句
private void MainForm_Load(object sender, EventArgs e)
{
//get the MapControl
m_mapControl = (IMapControl3)axMapControl1.Object;
//disable the Save menu (since there is no document yet)
menuSaveDoc.Enabled = false;
// 【添加此句】
MainForm.globalMapControl = this.axMapControl1;
}
// 显示IGeoDataset至窗口中
public static void ShowRaster(IGeoDataset pGeo, string name)
{
IRasterBandCollection irbc = (IRasterBandCollection)pGeo;
IRasterDataset pRD = irbc.Item(0).RasterDataset;
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromDataset(pRD);
rasterLayer.Name = name;
MainForm.globalMapControl.AddLayer(rasterLayer);
MainForm.globalMapControl.ActiveView.Refresh();
}
public static void ShowRasterByUniqueValueRender(IGeoDataset pGeo, string name, string renderfiled = "Value")
{
try
{
IRasterBandCollection irbc = (IRasterBandCollection)pGeo;
IRasterDataset pRD = irbc.Item(0).RasterDataset;
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromDataset(pRD);
rasterLayer.Name = name;
IRasterUniqueValueRenderer uniqueValueRenderer = new RasterUniqueValueRendererClass();
IRasterRenderer pRasterRenderer = uniqueValueRenderer as IRasterRenderer;
pRasterRenderer.Raster = rasterLayer.Raster;
pRasterRenderer.Update();
IUniqueValues uniqueValues = new UniqueValuesClass();
IRasterCalcUniqueValues calcUniqueValues = new RasterCalcUniqueValuesClass();
calcUniqueValues.AddFromRaster(rasterLayer.Raster, 0, uniqueValues);//iBand=0
IRasterRendererUniqueValues renderUniqueValues = uniqueValueRenderer as IRasterRendererUniqueValues;
renderUniqueValues.UniqueValues = uniqueValues;
uniqueValueRenderer.Field = renderfiled;
// 色带
IAlgorithmicColorRamp colorRamp = new AlgorithmicColorRampClass();
// 头
IRgbColor pFromColor = new RgbColorClass();
pFromColor.Red = 255; //红色
pFromColor.Green = 0;
pFromColor.Blue = 0;
// 尾
IRgbColor pToColor = new RgbColorClass();
pToColor.Red = 0; // 绿色
pToColor.Green = 255;
pToColor.Blue = 0;
// 设置属性
colorRamp.FromColor = pFromColor;
colorRamp.ToColor = pToColor;
colorRamp.Size = uniqueValues.Count;
uniqueValueRenderer.HeadingCount = 1;
uniqueValueRenderer.set_Heading(0, "All Data Value");
uniqueValueRenderer.set_ClassCount(0, uniqueValues.Count);
bool pOk;
colorRamp.CreateRamp(out pOk);
IRasterRendererColorRamp pRasterRendererColorRamp = uniqueValueRenderer as IRasterRendererColorRamp;
pRasterRendererColorRamp.ColorRamp = colorRamp;
for (int i = 0; i < uniqueValues.Count; i++)
{
uniqueValueRenderer.AddValue(0, i, uniqueValues.get_UniqueValue(i));
uniqueValueRenderer.set_Label(0, i, uniqueValues.get_UniqueValue(i).ToString());
IFillSymbol fs = new SimpleFillSymbol();
fs.Color = colorRamp.get_Color(i);
uniqueValueRenderer.set_Symbol(0, i, fs as ISymbol);
}
pRasterRenderer.Update();
rasterLayer.Renderer = pRasterRenderer;
MainForm.globalMapControl.AddLayer(rasterLayer);
MainForm.globalMapControl.ActiveView.Refresh();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
【Tools文件】 AE 栅格文件的操作
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.SpatialAnalyst;
namespace PM25Application
{
class Tools
{
#region 栅格文件基本操作
/// <summary>
/// 删除栅格数据fp
/// </summary>
/// <param name="fp">路径</param>
public static bool DeleteRasterFile(string fp)
{
try
{
string fn = Path.GetFileNameWithoutExtension(fp);
var files = Directory.GetFiles(Path.GetDirectoryName(fp), fn + ".*");
if (files.Length < 0)
return true;
for (int i = 0; i < files.Length; i++)
{
File.Delete(files[i]); //删除文件
}
}
catch (Exception e) {
return false; //异常
}
return true;
}
/// <summary>
/// 打开栅格_tif格式
/// </summary>
/// <param name="fp">栅格路径</param>
/// <returns>IGeoDataset</returns>
public static IGeoDataset OpenRaster(string fp)
{
IWorkspaceFactory wf = new RasterWorkspaceFactoryClass();
IWorkspace ws = wf.OpenFromFile(Path.GetDirectoryName(fp), 0);
IRasterWorkspace2 rw = ws as IRasterWorkspace2;
IRasterDataset rd = rw.OpenRasterDataset(Path.GetFileName(fp));
IGeoDataset pGeo = rd as IGeoDataset;
MainForm.ShowRaster(pGeo, Path.GetFileName(fp));
return pGeo;
}
/// <summary>
/// 保存栅格_tif格式
/// </summary>
/// <param name="pGeo"></param>
/// <param name="out_fp"></param>
/// <returns></returns>
public static bool SaveRaster(IGeoDataset pGeo, string out_fp)
{
// out_fp是否存在,存在的话删除其文件
if (File.Exists(out_fp) == true)
{
bool ok = DeleteRasterFile(out_fp);
if (ok == false) { //删除文件失败
return false;
}
}
// 将矩阵GeoDataset转成栅格集
IRasterBandCollection irbc = (IRasterBandCollection)pGeo;
IRasterDataset pRD = irbc.Item(0).RasterDataset;
// 保存
IWorkspaceFactory workspaceFactoryOut = new RasterWorkspaceFactoryClass();
IWorkspace workspace1 = workspaceFactoryOut.OpenFromFile(Path.GetDirectoryName(out_fp), 0);
irbc.SaveAs(Path.GetFileName(out_fp), workspace1, "TIFF");
MainForm.ShowRaster(pGeo, Path.GetFileName(out_fp));
return true;
}
public static bool SaveRaster(IRasterBandCollection pRBC, string out_fp)
{
// 保存
IWorkspaceFactory workspaceFactoryOut = new RasterWorkspaceFactoryClass();
IWorkspace workspace1 = workspaceFactoryOut.OpenFromFile(Path.GetDirectoryName(out_fp), 0);
pRBC.SaveAs(Path.GetFileName(out_fp), workspace1, "TIFF");
return true;
}
/// <summary>
/// 两个IGeoDataset相减,并取绝对值
/// </summary>
/// <param name="pGeo1"></param>
/// <param name="pGeo2"></param>
/// <returns></returns>
public static IGeoDataset SubAndAbs(IGeoDataset pGeo1, IGeoDataset pGeo2)
{
IMapAlgebraOp pMapAlgebraOp = new RasterMapAlgebraOpClass();
pMapAlgebraOp.BindRaster(pGeo1, "pGeo1");
pMapAlgebraOp.BindRaster(pGeo2, "pGeo2");
string formula = string.Concat("Abs( [pGeo1] - [pGeo2] )");
formula = string.Concat("Con( [pGeo1] == 0 | [pGeo2] == 0, 0, ", formula, " )");
IGeoDataset result = pMapAlgebraOp.Execute(formula);
return result;
}
/// <summary>
/// 栅格文件转数组
/// </summary>
/// <param name="raster"></param>
/// <param name="novalue"></param>
/// <returns></returns>
public static System.Array RasterToArray(IGeoDataset pGD, ref object novalue)
{
IRaster raster = pGD as IRaster;
IRasterProps props = (IRasterProps)raster;
novalue = props.NoDataValue;
IPnt pBlockSize = new PntClass();
pBlockSize.SetCoords((double)props.Width, (double)props.Height);
IRaster2 raster2 = (IRaster2)raster;
IPixelBlock pixelBlock = raster2.CreateCursorEx(pBlockSize).PixelBlock;
pBlockSize.SetCoords(0.0, 0.0);
raster.Read(pBlockSize, pixelBlock);
IPixelBlock3 block3 = (IPixelBlock3)pixelBlock;
return (System.Array)block3.get_PixelData(0);
}
public static IGeoDataset AlterRasterArray(IGeoDataset pGeo, Array arr)
{
IRaster raster = pGeo as IRaster;
IRasterProps props = (IRasterProps)raster;
IPnt pBlockSize = new PntClass();
pBlockSize.SetCoords((double)props.Width, (double)props.Height);
IRaster2 raster2 = (IRaster2)raster;
IPixelBlock pixelBlock = raster2.CreateCursorEx(pBlockSize).PixelBlock;
pBlockSize.SetCoords(0.0, 0.0);
raster.Read(pBlockSize, pixelBlock);
pixelBlock.set_SafeArray(0, arr);
//编辑raster,将更新的值写入raster中
IRasterEdit rasterEdit = raster as IRasterEdit;
//左上点坐标
IPnt tlp = new Pnt();
tlp.SetCoords(0, 0);
rasterEdit.Write(tlp, pixelBlock);
rasterEdit.Refresh();
return pGeo;
}
#endregion
}
}
object novalues = 0; //Nodata的值,返回的是float[]类型
arr = Tools.RasterToArray(value_blue, ref novalues);
// 获得novalue值:novalues为<float[]>类型
float[] tmp = (float[])novalues;
float novalue = tmp[0];
// 遍历arr
for (int i = 0; i < arr.GetLength(0); i++) //arr.GetLength(i):得到第i维的长度
{
for (int j = 0; j < arr.GetLength(1); j++)
{
// 这一点的像素值
float pixelvalue = (float)arr.GetValue(i, j);
// 设置新的值
flaot aod_value = 1;
arr.SetValue(aod_value, i, j);
}
}
// 让二维数组arr生成栅格数据(使用传入的IGeoDataset作为模板)
IGeoDataset pGeo = Tools.OpenRaster(fp); //打开一个栅格文件,作为模板
aod = Tools.AlterRasterArray(pGeo , arr); //修改pGeo中的矩阵数组
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromFilePath(fileName); // fileName指存本地的栅格文件路径
axMapControl1.AddLayer(rasterLayer, 0); // 添加到MapControl中
【举例】获取指定波段
raster_dir = "F:\PM2.5\data\LC08_L1TP_119043_20161218_20170315_01_T1"
raster_name = "LC08_L1TP_119043_20161218_20170315_01_T1_B1.TIF"
//创建一个【栅格工作空间的工厂】IWorkspaceFactory
IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
//打开栅格的工作空间IRasterWorkspace(即栅格数据所在的文件夹)
IWorkspace workspace = workspaceFactory.OpenFromFile(raster_dir, 0);
IRasterWorkspace2 rasterWordspace = workspace as IRasterWorkspace2; // 获得IRasterWorkspace2接口
//打开栅格工作空间中的指定栅格数据集IRasterDataset(即指定栅格的文件名)
IRasterDataset rastDataset = rasterWordspace.OpenRasterDataset(raster_name);
IRasterDataset2 rd2 = rastDataset as IRasterDataset2; // 获得IRasterDataset2接口
//创建IRaster
IRaster raster = rd2.CreateFullRaster();
IRasterBandCollection rbc = (IRasterBandCollection)raster; //获得该栅格的所有波段
// 获得指定波段
IGeoDataset pGoe1 = rbc.Item(0) as IGeoDataset;
// 假设当前加载的栅格文件栅格值存储方式为:UShort类型
IRasterProps rasterProps = (IRasterProps)clipRaster;
int dHeight = rasterProps.Height;//当前栅格数据集的行数
int dWidth = rasterProps.Width; //当前栅格数据集的列数
double dX = rasterProps.MeanCellSize().X; //栅格的宽度
double dY = rasterProps.MeanCellSize().Y; //栅格的高度
IEnvelope extent=rasterProps.Extent; //当前栅格数据集的范围
rstPixelType pixelType=rasterProps.PixelType; //当前栅格像素类型
// 遍历
IPnt pntSize = new PntClass();
pntSize.SetCoords(dX, dY);
IPixelBlock pixelBlock = clipRaster.CreatePixelBlock(pntSize);
IPnt pnt = new PntClass();
for (int i = 0; i < dHeight; i++)
for (int j = 0; j < dWidth; j++)
{
pnt.SetCoords(i, j);
clipRaster.Read(pnt, pixelBlock);
if (pixelBlock != null)
{
object obj = pixelBlock.GetVal(0, 0, 0);
MessageBox.Show( Convert.ToUInt32(obj).ToString());
}
}
IGeoDataset outGeoDataset; //处理所得的最终结果
// 保存
IWorkspaceFactory workspaceFactoryOut = new RasterWorkspaceFactory();
IWorkspace workspace1 = workspaceFactoryOut.OpenFromFile(System.IO.Path.GetDirectoryName(out_fp), 0);
IRasterBandCollection irbc = outGeoDataset as IRasterBandCollection;
irbc.SaveAs("out.tif", workspace1, "TIFF");
IRasterDataset pRD = irbc.Item(0).RasterDataset;
// 显示到MapControl
IRasterLayer pOutRL = new RasterLayerClass();
pOutRL.CreateFromDataset(pRD);
pOutRL.Name = System.IO.Path.GetFileName(out_fp);
axMapControl1.AddLayer(pOutRL);
public static IRasterLayer rasterCalculate(IRasterLayer pRL1, IRasterLayer pRL2)
{
IRaster pR1 = pRL1.Raster;
IRaster pR2 = pRL2.Raster;
IGeoDataset pGeoDT1 = pR1 as IGeoDataset;
IGeoDataset pGeoDT2 = pR2 as IGeoDataset;
IMapAlgebraOp pRSalgebra = new RasterMapAlgebraOpClass();
pRSalgebra.BindRaster(pGeoDT1, "raster1");
pRSalgebra.BindRaster(pGeoDT2, "raster2");
IGeoDataset pOutGeoDT = pRSalgebra.Execute("[raster1] - [raster2]");
IRasterLayer pOutRL = new RasterLayerClass();
pOutRL.CreateFromRaster(pOutGeoDT, as IRaster);
return pOutRL;
}
string name1 = "band1";
string fp1 = @"\\vmware-host\Shared Folders\PM2.5\data\LC08_L1TP_119043_20161218_20170315_01_T1\LC08_L1TP_119043_20161218_20170315_01_T1_B1.TIF";
string name2 = "band2";
string fp2 = @"\\vmware-host\Shared Folders\PM2.5\data\LC08_L1TP_119043_20161218_20170315_01_T1\LC08_L1TP_119043_20161218_20170315_01_T1_B2.TIF";
string formula = "[band1] - [band2]";
string out_fp = @"\\vmware-host\Shared Folders\PM2.5\data\sum.tif";
// open1
IWorkspaceFactory wF1 = new RasterWorkspaceFactory();
IWorkspace ws1 = wF1.OpenFromFile(Path.GetDirectoryName(fp1), 0);
IRasterWorkspace2 rw1 = ws1 as IRasterWorkspace2;
IRasterDataset rD1 = rw1.OpenRasterDataset(Path.GetFileName(fp1));
IGeoDataset pGeo1 = rD1 as IGeoDataset;
// open2
IWorkspaceFactory wF2 = new RasterWorkspaceFactory();
IWorkspace ws2 = wF2.OpenFromFile(Path.GetDirectoryName(fp2), 0);
IRasterWorkspace2 rw2 = ws2 as IRasterWorkspace2;
IRasterDataset rD2 = rw2.OpenRasterDataset(Path.GetFileName(fp2));
IGeoDataset pGeo2 = rD2 as IGeoDataset;
// 栅格计算器
IMapAlgebraOp pRSalgebra = new RasterMapAlgebraOpClass();
// 设置变量
pRSalgebra.BindRaster(pGeo1, name1);
pRSalgebra.BindRaster(pGeo2, name2);
// 执行
IGeoDataset pOutGeo = pRSalgebra.Execute(formula);
// 将矩阵GeoDataset转成栅格集
IRasterBandCollection irbc = (IRasterBandCollection)pOutGeo;
IRasterDataset pRD = irbc.Item(0).RasterDataset;
// 保存
IWorkspaceFactory workspaceFactoryOut = new RasterWorkspaceFactory();
IWorkspace workspace1 = workspaceFactoryOut.OpenFromFile(Path.GetDirectoryName(out_fp), 0);
irbc.SaveAs(Path.GetFileName(out_fp), workspace1, "TIFF");
// 打开栅格
IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
IWorkspace workspace = workspaceFactory.OpenFromFile(pathFile, 0);
IRasterWorkspace2 rasterWordspace = workspace as IRasterWorkspace2;
IRasterDataset rastDataset = rasterWordspace.OpenRasterDataset(inName);
IRasterDataset2 rd2 = rastDataset as IRasterDataset2;
IRaster raster = rd2.CreateFullRaster();
IRasterBandCollection rbc = (IRasterBandCollection)raster; //获取矩阵集
// 栅格计算器
IMapAlgebraOp pRSalgebra = new RasterMapAlgebraOpClass();
// 从波段集中获取单个波段,即该波段的矩阵GeoDataSet(Item的下标从0开始)
IGeoDataset pGoe1 = rbc.Item(index1) as IGeoDataset;
IGeoDataset pGoe2 = rbc.Item(index2) as IGeoDataset;
// 设置变量
pRSalgebra.BindRaster(pGoe1, "raster1");
pRSalgebra.BindRaster(pGoe2, "raster2");
// 计算公式,其中变量用[]来引用
L = numericUpDown_L.Value;
String strOut = "([raster2] - [raster1])" + " * " + "(1 + " + L + ")" + " / " + "(([raster1] + [raster2]" + " + " + L + ")" + " * " + "1.00)";
// 执行
IGeoDataset pOutGeo = pRSalgebra.Execute(strOut);
IGeoDataset pGeo1 = ProNoDataRaster(pOutGeo);
// 将矩阵GeoDataset转成栅格集
IRasterBandCollection irbc = (IRasterBandCollection)pGeo1;
IRasterDataset pRD = irbc.Item(0).RasterDataset;
rastDataset_savi = pRD;
//保存文件前检查是否有文件占用
string savi = "savi.tif";
IWorkspaceFactory workspaceFactoryOut = new RasterWorkspaceFactory();
IWorkspace workspace1 = workspaceFactoryOut.OpenFromFile(out_dir, 0);
irbc.SaveAs(savi, workspace1, "TIFF");
private IGeoDataset ProNoDataRaster(IGeoDataset pGeoDataset)
{
IGeoDataset my_GeoDataset = pGeoDataset;
IRasterBandCollection pRBandCollection = my_GeoDataset as IRasterBandCollection;
IRasterBand pRBand = pRBandCollection.Item(0);
IRasterProps pRasterprops = pRBand as IRasterProps;
pRasterprops.NoDataValue = 0;
pRBand = pRasterprops as IRasterBand;
pRBand.ComputeStatsAndHist();
pRBandCollection = pRBand.RasterDataset as IRasterBandCollection;
return pRBandCollection as IGeoDataset;
}
【两种方法】
// IRasterLayerEport
IRasterLayerExport rLayerExport = new RasterLayerExportClass();
rLayerExport.RasterLayer = rasterLayer;// rasterLayer指当前加载的栅格图层
rLayerExport.Extent = clipExtent;//clipExtent指提取栅格数据的范围
if (proSpatialRef != null)
rLayerExport.SpatialReference = proSpatialRef;// proSpatialRef当前栅格数据的投影信息
IWorkspaceFactory pWF = new RasterWorkspaceFactoryClass();
try
{
IWorkspace pRasterWorkspace = pWF.OpenFromFile(_folder, 0);// _folder指栅格文件保存路径
IRasterDataset outGeoDataset = rLayerExport.Export(pRasterWorkspace, code, strRasterType);
// 调用ISaveAs接口将导出的数据集保存
// ...(省略)
}
Catch(Exception ex)
{
Throw new Argumention(ex.Message);
}
// IExtractionOp
IExtractionOp extraction = new RasterExtractionOpClass();
try
{
IGeoDataset geoDataset = extraction.Rectangle((IGeoDataset)clipRaster, clipExtent, true);
IRaster raster = geoDataset as IRaster;
if (raster != null)
{
IWorkspaceFactory WF = new RasterWorkspaceFactoryClass();
IWorkspace rasterWorkspace = WF.OpenFromFile(_folder, 0);
ISaveAs saveAs = (ISaveAs)raster;
saveAs.SaveAs(“Result.tif”, rasterWorkspace, 'TIFF');
}
}
catch (Exception ex)
{
MessageBox..Show(Ex.message);
}
// 双线性采样
IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass();
rasterGeometryProc.Resample(rstResamplingTypes.RSP_CubicConvolution, newCellSize, clipRaster);
public IRasterDataset tin2raster(string tempBathyTIN,string geoPath, string gridName)
{
string tinFolder = System.IO.Path.GetDirectoryName(tempBathyTIN);
string tinName = System.IO.Path.GetFileName(tempBathyTIN);
IRasterDataset rasterDataset = new RasterDatasetClass();
try
{
string rasterPath = System.IO.Path.GetDirectoryName(geoPath);
IWorkspaceFactory TinWF = new TinWorkspaceFactory();
ITinWorkspace TinWK = TinWF.OpenFromFile(tinFolder,0)as ITinWorkspace;
ITinAdvanced2 tinAd = TinWK.OpenTin(tinName) as ITinAdvanced2;
IEnvelope extent = tinAd.Extent;
IPoint origin = extent.LowerLeft;
origin.X = origin.X - (5 * 0.5);
origin.Y = origin.Y - (5 * 0.5);
int nCol = (int)Math.Round(extent.Width / 5) + 1;
int nRow = (int)Math.Round(extent.Height / 5) +1;
ISpatialReference2 spatialRef = (ISpatialReference2)extent.SpatialReference;
IWorkspaceFactory rasterWF = new RasterWorkspaceFactoryClass();
IRasterWorkspace2 workSpace = (IRasterWorkspace2)rasterWF.OpenFromFile(rasterPath,0);
rasterDataset = workSpace.CreateRasterDataset(gridName, 'GRID', origin,nCol,nRow,5,5,1,ESRI.ArcGIS.Geodatabase.rstPixelType.PT_FLOAT, spatialRef,true);
IRasterBandCollection bandColl = (IRasterBandCollection) rasterDataset;
IRasterBand rasterBand = bandColl.Item(0);
IRawPixels rawPixels = (IRawPixels)rasterBand;
IPnt blockSize = new DblPntClass();
blockSize.X = nCol;
blockSize.Y = nRow;
IPixelBlock3 pixelBlock = (IPixelBlock3)rawPixels.CreatePixelBlock(blockSize);
ITinSurface tinSurface = (ITinSurface)tinAd;
IRasterProps rasterProps = (IRasterProps)rawPixels;
object nodataFloat;
//long nodataInt;
object val = pixelBlock.get_PixelDataByRef(0);
MessageBox.Show(val.ToString());
double cellsize = 5;
origin.X = origin.X + (5 * 0.5);
origin.Y = origin.Y + (5 * nRow) - (5 * 0.5);
nodataFloat = Convert.ToDouble(rasterProps.NoDataValue.ToString());
tinSurface.QueryPixelBlock(origin.X,origin.Y,cellsize,cellsize,esriRasterizationType.esriElevationAsRaster,nodataFloat,val);
IPnt offset = new DblPntClass();
offset.X = 0;
offset.Y = 0;
rawPixels.Write(offset,pixelBlock as IPixelBlock);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return rasterDataset;
}
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删