C# arcgis engine 十六进制字符串转换成wkb

using ESRI.ArcGIS.Geometry;
using System;

public class WkbConverter
{
    public static IGeometry ConvertHexToGeometry(string hexString)
    {
        byte[] byteArray = StringToByteArray(hexString);

        IGeometryFactory3 geometryFactory = new GeometryEnvironment() as IGeometryFactory3;
        IGeometry geometry = geometryFactory.CreateGeometryFromWkbVariant(byteArray) as IGeometry;
        
        return geometry;
    }

    private static byte[] StringToByteArray(string hexString)
    {
        int length = hexString.Length / 2;
        byte[] byteArray = new byte[length];

        for (int i = 0; i < length; i++)
        {
            byteArray[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
        }

        return byteArray;
    }
}

调用

string hexString = "0101000000cdcccccccccc2c40cdcccccccccc4440";

IGeometry geometry = WkbConverter.ConvertHexToGeometry(hexString);

你可能感兴趣的:(c#,arcgis,java)