From fc7aae282af8b5ca9544fe3579e7b09aa0295f62 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期二, 16 七月 2024 15:02:01 +0800
Subject: [PATCH] 添加GDAL初始化

---
 src/main/java/com/se/simu/helper/GdalHelper.java |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/main/java/com/se/simu/config/InitConfig.java |    8 +++++---
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/se/simu/config/InitConfig.java b/src/main/java/com/se/simu/config/InitConfig.java
index 9b9ed0b..491bb3e 100644
--- a/src/main/java/com/se/simu/config/InitConfig.java
+++ b/src/main/java/com/se/simu/config/InitConfig.java
@@ -1,5 +1,6 @@
 package com.se.simu.config;
 
+import com.se.simu.helper.GdalHelper;
 import com.se.simu.helper.WebHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -32,13 +33,14 @@
     public void run(ApplicationArguments args) {
         // noinspection AlibabaRemoveCommentedCode
         try {
-            //GdalHelper.init(env.getProperty("sys.gdal_path"));
-
-            log.info("***************** 绯荤粺鍚姩瀹屾瘯 *****************" + "\n");
+            log.info("***************** 鍒濆鍖� GDAL *****************" + "\n");
+            GdalHelper.init(env.getProperty("sys.path.gdal"));
 
             String path = null != contextPath && contextPath.length() > 1 ? contextPath : "";
             log.info("API鏂囨。:http://localhost:" + serverPort + path + "/doc.html");
             log.info("API鏂囨。:http://{}:{}{}/doc.html", WebHelper.getHostIp(), serverPort, path);
+
+            log.info("***************** 绯荤粺鍚姩瀹屾瘯 *****************" + "\n");
         } catch (Exception ex) {
             log.error(ex.getMessage(), ex);
         }
diff --git a/src/main/java/com/se/simu/helper/GdalHelper.java b/src/main/java/com/se/simu/helper/GdalHelper.java
new file mode 100644
index 0000000..5de0452
--- /dev/null
+++ b/src/main/java/com/se/simu/helper/GdalHelper.java
@@ -0,0 +1,43 @@
+package com.se.simu.helper;
+
+import lombok.extern.slf4j.Slf4j;
+import org.gdal.gdal.gdal;
+import org.gdal.ogr.ogr;
+
+import java.io.File;
+
+/**
+ * GDAL甯姪绫�
+ *
+ * @author WWW
+ * @date 2024-07-16
+ */
+@Slf4j
+@SuppressWarnings("ALL")
+public class GdalHelper {
+    public static void init(String gdalPath) {
+        // 鏀寔涓枃璺緞
+        gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
+        // 灞炴�ц〃鏀寔涓枃锛欳P936
+        gdal.SetConfigOption("SHAPE_ENCODING", "");
+        gdal.SetConfigOption("PGEO_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s");
+        gdal.SetConfigOption("MDB_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s");
+
+        // 閰嶇疆鐜鍙橀噺
+        if (!StringHelper.isEmpty(gdalPath)) {
+            gdal.SetConfigOption("GDAL_DATA", gdalPath + File.separator + "gdal-data");
+            gdal.SetConfigOption("PROJ_LIB", gdalPath + File.separator + "proj7" + File.separator + "share");
+            //System.setProperty("PROJ_LIB", gdalPath + File.separator + "proj7" + File.separator + "share")
+            gdal.SetConfigOption("GDAL_DRIVER_PATH", gdalPath + File.separator + "gdalplugins");
+
+            String path = System.getenv("PATH");
+            if (!path.contains(gdalPath)) {
+                System.setProperty("PATH", path + ";" + gdalPath);
+            }
+        }
+
+        // 娉ㄥ唽鎵�鏈夌殑椹卞姩
+        gdal.AllRegister();
+        ogr.RegisterAll();
+    }
+}

--
Gitblit v1.9.3