using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.DataSourcesRaster;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ESRI.ArcGIS.esriSystem.AoInitialize aoInit;
#region Initialize Licensing
try
{
Console.WriteLine("Obtaining License");
ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop);
aoInit = new AoInitializeClass();
esriLicenseStatus licStatus = aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
Console.WriteLine("Ready with license");
}
catch (Exception exc)
{
// If it fails at this point, shutdown the test and ignore any subsequent errors.
Console.WriteLine("Fails:" + exc.Message);
return;
}
#endregion
IWorkspaceFactory pWorkspaceFactory = new RasterWorkspaceFactoryClass();
string strPath = @"D:\数据";
IWorkspace pWS = pWorkspaceFactory.OpenFromFile(strPath, 0);
IRasterWorkspace pRWS = pWS as IRasterWorkspace;
IRaster pRaster = pRWS.OpenRasterDataset("chinaelev1.tif").CreateDefaultRaster();
IUniqueValues pUv = new UniqueValuesClass();
IRasterCalcUniqueValues pRcuv = new RasterCalcUniqueValuesClass();
pRcuv.AddFromRaster(pRaster, 0, pUv);
object pUniqueValues, pCounts;
pUv.GetHistogram(out pUniqueValues,out pCounts);
}
}
}
调试的时候到了pRWS.OpenRasterDataset("chinaelev1.tif")这一句,提示“打开栅格数据集失败”,我以为是license的原因,可是反复设置license文件,也不能解决问题,后来把@"D:\数据";的数据目录改为英文就能过去了,真是奇葩呀!!谁能知道是什么原因呢?各位亲