/// <summary>
/// 解决字段中文名称乱码
/// </summary>
/// <param name="fe"></param>
/// <param name="index"></param>
/// <returns></returns>
public static string getNameStr(Feature fe, int index)
{
string str = string.Empty;
OSGeo.OGR.FieldDefn pFieldDefn = fe.GetFieldDefnRef(index);
// 解决中文字段乱码,用OGR_Fld函数读取字段名
IntPtr pcharFld = OGR_Fld_GetNameRef(OSGeo.OGR.FieldDefn.getCPtr(pFieldDefn));
// 转为unicode二进制
byte[] unibytes = System.Text.Encoding.Unicode.GetBytes(Marshal.PtrToStringUni(pcharFld));
int length = 0;
for (int i = 0; i < unibytes.Length; i++)
{
if (unibytes[i] == 0)
{
break;
}
length++;
}
byte[] bytes = new byte[length];
Array.Copy(unibytes, bytes, length);
str = System.Text.Encoding.UTF8.GetString(bytes);//再转成UTF8
return str;
}
c# GDAL字段中文名称乱码
最新推荐文章于 2023-11-10 17:55:22 发布