管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-07-18 d20fdf2fccbfdd4a5ac2e6e79523a9558b9a2b51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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();
        }
    }
}