From ed8c7a5effd0d423ce1118b680ecdca6fe732609 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 02 七月 2025 16:43:13 +0800
Subject: [PATCH] Merge branch 'master' of http://192.168.11.205:9000/r/P2022036_Service

---
 src/main/java/com/lf/server/helper/GdalHelper.java |   44 ++++++++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/lf/server/helper/GdalHelper.java b/src/main/java/com/lf/server/helper/GdalHelper.java
index 5cc3c44..c03235f 100644
--- a/src/main/java/com/lf/server/helper/GdalHelper.java
+++ b/src/main/java/com/lf/server/helper/GdalHelper.java
@@ -10,6 +10,7 @@
 import org.gdal.ogr.*;
 import org.gdal.osr.SpatialReference;
 
+import java.io.File;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.time.LocalDate;
@@ -28,20 +29,31 @@
 public class GdalHelper {
     private final static Log log = LogFactory.getLog(GdalHelper.class);
 
-   public static void init() {
-       // 娉ㄥ唽鎵�鏈夌殑椹卞姩
-       gdal.AllRegister();
+    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");
 
-       // 涓轰簡鏀寔涓枃璺緞锛岃娣诲姞涓嬮潰杩欏彞浠g爜
-       gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
+        // 閰嶇疆鐜鍙橀噺
+        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");
 
-       // 閰嶇疆GDAL_DATA璺緞锛坓dal鏍圭洰褰曚笅鐨刡in\gdal-data锛�
-       // gdal.SetConfigOption("GDAL_DATA", "E:\\terrait\\TianJin\\Zip\\release-1928-x64-dev\\release-1928-x64\\bin\\gdal-data");
-       // gdal.SetConfigOption("PROJ_LIB", "E:\\terrait\\TianJin\\Zip\\release-1928-x64-dev\\release-1928-x64\\bin\\proj7\\share");
+            String path = System.getenv("PATH");
+            if (!path.contains(gdalPath)) {
+                System.setProperty("PATH", path + ";" + gdalPath);
+            }
+        }
 
-       // 涓轰簡浣垮睘鎬ц〃瀛楁鏀寔涓枃锛岃娣诲姞涓嬮潰杩欏彞锛欳P936
-       gdal.SetConfigOption("SHAPE_ENCODING", "");
-   }
+        // 娉ㄥ唽鎵�鏈夌殑椹卞姩
+        gdal.AllRegister();
+        ogr.RegisterAll();
+    }
 
     /**
      * 璇诲彇tif鏂囦欢
@@ -129,7 +141,7 @@
                 break;
             }
         } catch (Exception ex) {
-            ex.printStackTrace();
+            log.error(ex.getMessage(), ex);
         }
     }
 
@@ -192,8 +204,8 @@
                 //layerDto.setCount(count);
                 //layerDto.setMap(mapList);
             }
-        } catch (Exception e) {
-            e.printStackTrace();
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
         } finally {
             if (dataSource != null) {
                 dataSource.delete();
@@ -238,11 +250,11 @@
                 } while (true);
             }
         } catch (Exception ex) {
-            ex.printStackTrace();
+            log.error(ex.getMessage(), ex);
         }
     }
 
-    private static Object getProperty(Feature feature, int index) {
+    public static Object getProperty(Feature feature, int index) {
         int type = feature.GetFieldType(index);
 
         PropertyGetter propertyGetter;

--
Gitblit v1.9.3