惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
U
Unit 42
H
Hackread – Cybersecurity News, Data Breaches, AI and More
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
I
InfoQ
博客园 - 司徒正美

博客园 - 神游虚空

学习AI编程 安装 RAGFlow 安装 KTransformer 量化投资赚的哪方面的钱? python中调用 .net 的 dll 时,报错:Exception has occurred: TypeLoadException 使用 Open XML SDK 实现 html 富文本转换为 docx 格式示例 在python中 先调用C#的dll 返回了一个类的列表,如何把这个列表转换为 python 中的 DataFrame? vue项目服务器部属源码调试解决办法 vue3 + ts + element_plus 创建后台管理系统,学习记录 大A指数周内效应分析 两个通达信公式 如何在.netcore 上实现 Rbac 权限管理 修道是精神上的减熵过程 BPMN2.0 Specifaction 节选翻译,10.4.6 事件处理(handling Events,原文 275页) BPMN2.0 Specifaction 节选翻译,10.4 事件 Events (原文233页) 使用ef或dbcontext的时候主要注意三个问题 EFCore 中 group 分组后,只选出每组中含有最大值的数据行 BPMN2.0 Specifaction 节选翻译,10.2.8 循环特征 Loop Characteristics (原文 189页) BPMN2.0 Specifaction 节选翻译,10.2.5 子流程 Sub-Processes (原文173页) BPMN2.0 Specifaction 节选翻译,10 Process (原文145页)
解决 GDAL 用 C# 访问时,中文乱码问题。
神游虚空 · 2026-04-28 · via 博客园 - 神游虚空

下面代码用于获取中文图层名、字段名及字段值。

public class SafeOgr
{
    /// <summary>
    /// 获取图层名(自动处理 UTF-8 编码)
    /// </summary>
    [DllImport("gdal.dll", EntryPoint = "OGR_L_GetName", CallingConvention = CallingConvention.Cdecl)]
    static extern IntPtr OGR_L_GetName(HandleRef handle);
    public static string GetLayerName(Layer layer)
    {
        HandleRef handle = Layer.getCPtr(layer);
        IntPtr ptr = OGR_L_GetName(handle);
        return Utf8BytesToString(ptr);
    }

    /// <summary>
    /// 获取字段名(自动处理 UTF-8 编码)
    /// </summary>
    [DllImport("gdal.dll", EntryPoint = "OGR_Fld_GetNameRef", CallingConvention = CallingConvention.Cdecl)]
    static extern IntPtr OGR_Fld_GetNameRef(HandleRef handle);
    public static string GetFieldName(FieldDefn field)
    {
        HandleRef handle = FieldDefn.getCPtr(field);
        IntPtr ptr = OGR_Fld_GetNameRef(handle);
        return Utf8BytesToString(ptr);
    }

    /// <summary>
    /// 获取字段值字符串(自动处理 UTF-8 编码)
    /// </summary>
    [DllImport("gdal.dll", EntryPoint = "OGR_F_GetFieldAsString", CallingConvention = CallingConvention.Cdecl)]
    static extern IntPtr OGR_F_GetFieldAsString(HandleRef handle, int idx);
    public static string GetFieldAsString(Feature feat, int idx)
    {
        HandleRef handle = Feature.getCPtr(feat);
        IntPtr ptr = OGR_F_GetFieldAsString(handle, idx);
        return Utf8BytesToString(ptr);
    }

    private static string Utf8BytesToString(IntPtr ptr)
    {
        if (ptr == IntPtr.Zero)
            return null;

        int len = 0;
        while (Marshal.ReadByte(ptr, len) != 0) len++;

        byte[] bytes = new byte[len];
        Marshal.Copy(ptr, bytes, 0, len);

        return System.Text.Encoding.UTF8.GetString(bytes);
    }
}