C#数据类型与对应ArcObject栅格数据类型

  数据类型匹配是写通用ArcObject程序必须考虑的事情。为了以后方便,整理了一下C#数据类型和与之对应的ArcObject栅格数据类型。ArcObject栅格数据机类型可参照ESRI.ArcGIS.Geodatabase.rstPixelType.

C#数据类型与对应ArcObject栅格数据类型

  顺便给出一个转换函数

C#数据类型与对应ArcObject栅格数据类型
/// <summary>
/// Convert the csharp value to the ArcObject pixel value.
/// </summary>
/// <param name="csharpValue">Cshapr value</param>
/// <param name="pixelValueType">The pixel type of ouput value</param>
/// <param name="pixelValue">Output pixel value</param>
/// <returns>A value indicating whether the convention is successful</returns>
public static bool CSharpValue2PixelValue(object csharpValue, rstPixelType pixelValueType, out object pixelValue)
{
    try
    {
        switch (pixelValueType)
        {
            case rstPixelType.PT_UCHAR:
                pixelValue = (object)Convert.ToByte(csharpValue);
                return true;
            case rstPixelType.PT_CHAR:
                pixelValue = (object)Convert.ToSByte(csharpValue);
                return true;
            case rstPixelType.PT_SHORT:
                pixelValue = (object)Convert.ToInt16(csharpValue);
                return true;
            case rstPixelType.PT_USHORT:
                pixelValue = (object)Convert.ToUInt16(csharpValue);
                return true;
            case rstPixelType.PT_CLONG:
                pixelValue = (object)Convert.ToInt32(csharpValue);
                return true;
            case rstPixelType.PT_ULONG:
                pixelValue = (object)Convert.ToUInt32(csharpValue);
                return true;
            case rstPixelType.PT_FLOAT:
                pixelValue = (object)Convert.ToSingle(csharpValue);
                return true;
            case rstPixelType.PT_DOUBLE:
                pixelValue = (object)Convert.ToDouble(csharpValue);
                return true;
            default:
                pixelValue = null;
                return false;
        }
    }
    catch (Exception)
    {
        pixelValue = null;
        return false;
    }
}
C#数据类型与对应ArcObject栅格数据类型

C#数据类型与对应ArcObject栅格数据类型

上一篇:秒懂算法1——冒泡排序,及一种小改进(C#实现)


下一篇:eclipse