From a3d8b2a5a449f2f633973786573b5306f29a517e Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期三, 29 十一月 2023 16:33:45 +0800
Subject: [PATCH] 添加“使用GDAL获取EPSG编码”

---
 src/main/java/com/lf/server/service/data/RasterService.java |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/lf/server/service/data/RasterService.java b/src/main/java/com/lf/server/service/data/RasterService.java
index 625b0c4..1870908 100644
--- a/src/main/java/com/lf/server/service/data/RasterService.java
+++ b/src/main/java/com/lf/server/service/data/RasterService.java
@@ -2,6 +2,7 @@
 
 import com.lf.server.entity.all.StaticData;
 import com.lf.server.helper.StringHelper;
+import com.lf.server.helper.WebHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.gdal.gdal.Dataset;
@@ -11,6 +12,7 @@
 import org.gdal.ogr.ogr;
 import org.gdal.osr.SpatialReference;
 import org.osgeo.proj4j.*;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
@@ -25,6 +27,9 @@
     private SpatialReference sr4326;
 
     private SpatialReference sr4490;
+
+    @Value("${sys.gdal_path}")
+    private String gdalPath;
 
     private final static Log log = LogFactory.getLog(RasterService.class);
 
@@ -80,6 +85,38 @@
     }
 
     /**
+     * 浣跨敤GDAL鑾峰彇EPSG缂栫爜
+     */
+    public Integer getEpsgByGdal(String file) {
+        try {
+            File f = new File(file);
+            if (!f.exists() || f.isDirectory()) {
+                return null;
+            }
+
+            String cmd = String.format("%s\\gdalsrsinfo.exe \"%s\" -o epsg", gdalPath, file);
+            String rs = WebHelper.exec2(cmd);
+            if (StringHelper.isEmpty(rs)) {
+                return null;
+            }
+
+            String[] strs = rs.split("\n");
+            for (String str : strs) {
+                if (str.contains("EPSG:")) {
+                    String epsg = str.replace("EPSG:", "");
+
+                    return Integer.parseInt(epsg);
+                }
+            }
+
+            return 0;
+        } catch (Exception ex) {
+            log.error(ex.getMessage(), ex);
+            return null;
+        }
+    }
+
+    /**
      * 鍧愭爣杞崲
      */
     public Object csTransform(double x, double y, int epsg) {

--
Gitblit v1.9.3