From e5d40172f9bd9b0b967cb0e74b551f1a135dae6f Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期日, 22 九月 2024 16:06:53 +0800
Subject: [PATCH] 1

---
 src/main/java/com/se/simu/service/GedbService.java |   35 +++++++++++++++++++++++++++++++----
 1 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/main/java/com/se/simu/service/GedbService.java b/src/main/java/com/se/simu/service/GedbService.java
index ca95b92..29e086e 100644
--- a/src/main/java/com/se/simu/service/GedbService.java
+++ b/src/main/java/com/se/simu/service/GedbService.java
@@ -13,6 +13,7 @@
 import com.se.simu.helper.StringHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.gdal.gdal.Dataset;
+import org.gdal.gdal.WarpOptions;
 import org.gdal.gdal.gdal;
 import org.gdal.gdalconst.gdalconst;
 import org.springframework.beans.factory.annotation.Value;
@@ -99,7 +100,7 @@
 
         String filePath = inPath + File.separator + fileDb.getDbid();
         downloadFiles(token, filePath, files, fileDb.getDbid(), fileId);
-        clipDemFile(filePath, files, basePath, bbox);
+        clipDemFile(filePath, files, basePath, bbox, 4528);
 
         return true;
     }
@@ -332,24 +333,50 @@
         is.close();
     }
 
-    private void clipDemFile(String filePath, List<GeFile> files, String basePath, String bbox) throws Exception {
+    private void clipDemFile(String filePath, List<GeFile> files, String basePath, String bbox, int epsg) throws Exception {
         String target = basePath + File.separator + demName;
         for (GeFile file : files) {
             if (file.getName().toLowerCase().endsWith(demType)) {
                 String source = filePath + File.separator + file.getName();
-                clipDem(source, target, bbox);
+                clipDem(source, target, bbox, epsg);
                 break;
             }
         }
     }
 
-    private void clipDem(String source, String target, String bbox) throws Exception {
+    private void clipDem(String source, String target, String bbox, int epsg) throws Exception {
         Dataset ds = null;
         try {
             ds = gdal.Open(source, gdalconst.GA_ReadOnly);
             if (null == ds || ds.getRasterCount() < 1 || null == ds.GetSpatialRef()) throw new Exception("DEM鏁版嵁鏃犳晥");
 
+            // String bbox = "116.64388473935195,39.884315914604464,116.64754729082588,39.887069143903496";
+            String[] bb = bbox.split(",");
 
+            // gdalwarp -ot UInt16 -s_srs EPSG:4326 -t_srs EPSG:2382 -r bilinear -of GTiff -te 116.526854182 40.0481829856 116.532848182 40.0541769856
+            // -te_srs EPSG:4326 -co COMPRESS=DEFLATE -co PREDICTOR=1 -co ZLEVEL=6 -co TILED=YES -wo OPTIMIZE_SIZE=TRUE E:\GDALhomework\000002.tif E:/CSDN/warped1.tif
+
+            Vector<String> vector = new Vector<>();
+            //vector.add("-s_srs");
+            //vector.add("EPSG:" + 4326);
+            vector.add("-t_srs");
+            vector.add("EPSG:" + epsg);
+            vector.add("-r");
+            vector.add("bilinear");
+            vector.add("-of");
+            vector.add("GTiff");
+            vector.add("-te");
+            vector.add(bb[0]);
+            vector.add(bb[1]);
+            vector.add(bb[2]);
+            vector.add(bb[3]);
+            vector.add("-te_srs");
+            vector.add("EPSG:" + 4326);
+
+            WarpOptions warpOptions = new WarpOptions(vector);
+
+            Dataset destDs = gdal.Warp(target, new Dataset[]{ds}, warpOptions);
+            destDs.delete();
         } finally {
             if (null != ds) ds.delete();
         }

--
Gitblit v1.9.3