许可优化
许可优化
产品
产品
解决方案
解决方案
服务支持
服务支持
关于
关于
软件库
当前位置:服务支持 >  软件文章 >  [AE] ArcGIS Engine与栅格Raster开发合集

[AE] ArcGIS Engine与栅格Raster开发合集

阅读数 15
点赞 0
article_banner

栅格数据

类  型】

  • ESRI GRID:一系列的文件组成
  • TIFF:TIF文件+AUX文件
  • ERDAS IMAGE:

【栅格数据集】由一个或多个波段组成,一个波段就是数据矩阵

  • 格网数据(如DEM数据)、单波段的影像数据:只含有一个波段
  • 多光谱影像数据:多波段的栅格数据集

【接口介绍】

  • IRasterWorkspaceEx:主要用来读取GeoDatabase中的栅格数据
  • IRasterWorkspace、IRasterWorpsace2:读取文件格式的栅格数据

遍历栅格

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文件:打开、保存栅格,获取栅格数据的二维矩阵,由二维矩阵生成栅格

【Tools文件】 AE 栅格文件的操作

  • 删除栅格文件
  • 打开栅格文件
  • 保存栅格文件
  • 栅格计算器
  • 获取栅格数据中的二维矩阵,得到System.Array类型(二维数组)
  • 根据System.Array二维矩阵(二维数组)修改栅格文件
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
    }
}

例子:获取栅格数据的二维矩阵,并修改,修改完之后应用到IGeoDataset中

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

IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromFilePath(fileName); // fileName指存本地的栅格文件路径
axMapControl1.AddLayer(rasterLayer, 0);   // 添加到MapControl中

IRasterDataset

【举例】获取指定波段

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");

单个栅格文件中多个波段参与计算

  1. 打开栅格
  2. 获得该栅格的波段集
  3. 从波段集中获取两个矩阵
  4. 用两个矩阵进行计算
// 打开栅格
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");

案例

ArcGIS的Nodata转成 ERDAS

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;
}

提取 指定范围的栅格数据

【两种方法】

  • IRasterLayerExport(esriCarto):提供的栅格数据提取功能有限,只能以矩形范围作为提取范围
  • IExtractionOp, IExtractionOp2 :提供了多边形,圆,属性,矩形等几种形式作为提取栅格数据
// 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);

TIN转Raster

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;

}



免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删


相关文章
技术文档
QR Code
微信扫一扫,欢迎咨询~
customer

online

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 board-phone 155-2731-8020
close1
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

姓名不为空

姓名不为空
手机不正确

手机不正确

手机不正确
公司不为空

公司不为空

公司不为空