using OSGeo.GDAL;
|
using OSGeo.OGR;
|
using OSGeo.OSR;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace SimuTools.Tools
|
{
|
public class GdalHelper
|
{
|
private static bool isInited;
|
|
private static GdalHelper instance;
|
|
private static readonly object obj = new object();
|
|
public static SpatialReference sr4326 { set; get; }
|
|
public static SpatialReference sr4490 { set; get; }
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
private GdalHelper()
|
{
|
lock (obj)
|
{
|
if (!isInited)
|
{
|
RegisterGDal();
|
|
sr4326 = new SpatialReference(null);
|
sr4326.ImportFromEPSG(4326);
|
|
sr4490 = new SpatialReference(null);
|
sr4490.ImportFromEPSG(4490);
|
|
isInited = true;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 实例
|
/// </summary>
|
public static GdalHelper Instance
|
{
|
get
|
{
|
lock (obj)
|
{
|
if (null == instance)
|
{
|
instance = new GdalHelper();
|
}
|
|
return instance;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 注册GDAL
|
/// </summary>
|
public void RegisterGDal()
|
{
|
string gdalData = Path.Combine(Handle.BaseDir, "gdal-data");
|
Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
|
|
string proj7 = Path.Combine(Handle.BaseDir, "proj7\\share");
|
Environment.SetEnvironmentVariable("PROJ_LIB", proj7);
|
|
Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // NO,YES
|
Gdal.SetConfigOption("SHAPE_ENCODING", ""); // 空,gb2312,CP936
|
|
Ogr.RegisterAll();
|
Gdal.AllRegister();
|
}
|
}
|
}
|