GDAL - CSharp环境配置
更新时间:2023-12-16 15:34:01 阅读量: 教育文库 文档下载
- 瓜迪奥拉推荐度:
- 相关推荐
一、GDAL C# DLL下载
http://www.gisinternals.com/sdk/
http://www.gisinternals.com/sdk/PackageList.aspx?file=release-1400-gdal-1-10-1-mapserver-6-4-1.zip
位于压缩包中的位置:bin\\gdal\\csharp\\...目录下:
开发时把以_csharp.dll结尾的添加到项目引用,其余的拷贝到bebug目录下。
二、在调用Gdal.AllRegister() 方法时报异常:“OSGeo.GDAL.GdalPINVOKE”的类型初始值设定项引发
异常。
原因分析:gdal初始化时,其依赖dll项不全导致异常,可采用Dependency Walker工具查看相关依赖项。把九个DLL拷贝到debug是不能解决问题的。
解决方法:
采用SharpMap的GDAL初始化方法,需要两个数据: 1. GdalConfiguration.cs 2. gdal_data_config.rar
第一步:将GdalConfiguration.cs添加到项目中,然后解压gdal_data_config.rar到debug目录下,文件夹名称为gdal。
第二步:在使用Gdal.AllRegister()初始化前,调用以下两句代码进行相关初始化数据的配置即可。
SharpMap.GdalConfiguration.ConfigureGdal(); SharpMap.GdalConfiguration.ConfigureOgr();
附件1:GdalConfiguration.cs
/****************************************************************************** *
* Name: GdalConfiguration.cs.pp * Project: GDAL CSharp Interface
* Purpose: A static configuration utility class to enable GDAL/OGR. * Author: Felix Obermaier *
*****************************************************************************/
using System; using System.IO;
using System.Reflection;
using Gdal = OSGeo.GDAL.Gdal; using Ogr = OSGeo.OGR.Ogr;
namespace SharpMap {
public static partial class GdalConfiguration {
private static bool _configuredOgr; private static bool _configuredGdal;
///
/// Function to determine which platform we're on ///
private static string GetPlatform() {
return IntPtr.Size == 4 ? \ : \; }
///
/// Construction of Gdal/Ogr ///
static GdalConfiguration() {
var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; var executingDirectory = Path.GetDirectoryName(executingAssemblyFile);
if (string.IsNullOrEmpty(executingDirectory))
throw new InvalidOperationException(\);
var gdalPath = Path.Combine(executingDirectory, \); var nativePath = Path.Combine(gdalPath, GetPlatform());
// Prepend native path to environment path, to ensure the // right libs are being used.
var path = Environment.GetEnvironmentVariable(\);
path = nativePath + \ + Path.Combine(nativePath, \) + \ + path; Environment.SetEnvironmentVariable(\, path);
// Set the additional GDAL environment variables. var gdalData = Path.Combine(gdalPath, \);
Environment.SetEnvironmentVariable(\, gdalData); Gdal.SetConfigOption(\, gdalData);
var driverPath = Path.Combine(nativePath, \);
Environment.SetEnvironmentVariable(\, driverPath); Gdal.SetConfigOption(\, driverPath);
Environment.SetEnvironmentVariable(\, gdalData); Gdal.SetConfigOption(\, gdalData);
var projSharePath = Path.Combine(gdalPath, \);
Environment.SetEnvironmentVariable(\, projSharePath); Gdal.SetConfigOption(\, projSharePath); }
///
/// Method to ensure the static constructor is being called. ///
///
if (_configuredOgr) return;
// Register drivers Ogr.RegisterAll(); _configuredOgr = true;
PrintDriversOgr(); }
///
/// Method to ensure the static constructor is being called. ///
///
if (_configuredGdal) return;
// Register drivers Gdal.AllRegister(); _configuredGdal = true;
PrintDriversGdal(); }
private static void PrintDriversOgr() { #if DEBUG
var num = Ogr.GetDriverCount(); for (var i = 0; i < num; i++) {
var driver = Ogr.GetDriver(i);
Console.WriteLine(string.Format(\, i, driver.name)); } #endif }
private static void PrintDriversGdal() { #if DEBUG
var num = Gdal.GetDriverCount(); for (var i = 0; i < num; i++) {
var driver = Gdal.GetDriver(i);
Console.WriteLine(string.Format(\, i, driver.ShortName, driver.LongName)); } #endif } } }
正在阅读:
GDAL - CSharp环境配置12-16
GPS监控系统在企业交通安全管理中的作用03-12
中专较量争论机次要学什么内容03-30
中专春季班与春季班差别是什么03-30
《穆斯林的葬礼》与伊斯兰丧葬文化05-06
五年级上册数学第三单元导学案分饼06-21
含数据库10-18
7.15 第6次课 摩尔质量07-03
威海客运段班组建设管理办法01-25
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 配置
- 环境
- CSharp
- GDAL
- 2019年人教版小学一年级数学上册单元试卷 全册 doc
- 2017高考政治(人教版)大一轮复习讲义文档第一单元生活与消费第一课Word版含答案
- 某项目多媒体系统施工组织设计方案 - 图文
- WORD文档怎么自动生成目录?
- 曲线连续梁计算书
- 丰台区2012―2013学年度第一学期期末练习(高一政治)
- 团体心理辅导活动课教案
- 全国中学生英语能力电视大赛试卷(初二年级)
- 人事部年终总结 - 图文
- 新编大学英语综合教程3(第三版)课后翻译答案
- 非诚勿扰之西游篇
- 公路工程检查细则
- matlab实用教程100例
- 2019年整理--小学第一学期开学典礼讲话稿
- 挡土墙及边坡防护施工方案
- 我为教育建言献策
- 四轮定位系统外文文献翻译、中英文翻译、外文翻译 - 图文
- 《鸿门宴》人物比较
- 小学语文课外阅读推荐课走进《昆虫记》教学实录
- 国际贸易答案