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

推荐订阅源

博客园_首页
Security Archives - TechRepublic
Security Archives - TechRepublic
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
S
Security @ Cisco Blogs
S
Security Affairs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
Lohrmann on Cybersecurity
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
Forbes - Security
Forbes - Security
H
Heimdal Security Blog
A
Arctic Wolf
NISL@THU
NISL@THU
P
Proofpoint News Feed
W
WeLiveSecurity
S
Schneier on Security
AI
AI
Schneier on Security
Schneier on Security
N
News and Events Feed by Topic
L
LINUX DO - 最新话题
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Know Your Adversary
Know Your Adversary
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
Cyberwarzone
Cyberwarzone
I
Intezer
S
Securelist
Help Net Security
Help Net Security
Microsoft Security Blog
Microsoft Security Blog
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
Last Week in AI
Last Week in AI
Jina AI
Jina AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
WordPress大学
WordPress大学
罗磊的独立博客
月光博客
月光博客
雷峰网
雷峰网
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
MongoDB | Blog
MongoDB | Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 司徒正美
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events

博客园 - 神游虚空

学习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);
    }
}