C# GDAL 开发准备

                  目录

GDAL C# DLL 下载

 准备dll

开发环境配置

代码测试


GDAL C# DLL 下载

编译后的DLL下载地址:http://www.gisinternals.com/release.php

 准备dll

1、bin/gdal/csharp文件夹中的dll

2、bin/  的dll

以及gdal-data文件夹

开发环境配置

新建解决方案和项目,根据下载gdal的位数配置管理器的位数

把准好的dll复制到\bin\x64\Debug文件夹下

添加以“_csharp.dll”结尾的dll库添加到项目引用中

代码测试

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OSGeo.OGR;
using OSGeo.OSR;
using System.IO;
using System.Runtime.InteropServices;

namespace TestGdal32
{
    class Program
    {
        static void Main(string[] args)
        {
            string shpPathD = @"F:\11TestData\ogr测试shp\Original.shp";
            Ogr.RegisterAll();
            OSGeo.GDAL.Gdal.SetConfigOption("SHAPE_ENCODING", "");
            OSGeo.GDAL.Gdal.SetConfigOption("GDAL_DATA", "gdal-data");
            OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");// 解决Shp文件路径中文路径乱码,无法读取的问题
            DataSource dsD = Ogr.Open(shpPathD, 1);
            Layer layer = dsD.GetLayerByIndex(0);
            string named = layer.GetName();
            Console.WriteLine(named);
           
        }
    }
}

猜你喜欢

转载自blog.csdn.net/fangyu723/article/details/107941184