From 786e89f85c5e558900240b5c8ff6172b5f91134f Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 25 九月 2023 12:15:47 +0800 Subject: [PATCH] 添加获取文件路径方法 --- src/main/java/com/moon/server/service/data/RasterAnalysisService.java | 34 ++++++++++++++++++++++++++++++++-- 1 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/moon/server/service/data/RasterAnalysisService.java b/src/main/java/com/moon/server/service/data/RasterAnalysisService.java index 5d143a6..d881b33 100644 --- a/src/main/java/com/moon/server/service/data/RasterAnalysisService.java +++ b/src/main/java/com/moon/server/service/data/RasterAnalysisService.java @@ -7,6 +7,7 @@ import com.moon.server.entity.data.PublishEntity; import com.moon.server.helper.GeoHelper; import com.moon.server.helper.PathHelper; +import com.moon.server.helper.StringHelper; import com.moon.server.helper.WebHelper; import com.moon.server.service.all.WebSocketService; import org.apache.commons.logging.Log; @@ -17,11 +18,13 @@ import org.gdal.gdal.gdal; import org.gdal.ogr.Geometry; import org.gdal.ogr.ogr; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.awt.geom.Point2D; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.util.*; @@ -32,6 +35,9 @@ */ @Service public class RasterAnalysisService { + @Value("${sys.gdal_path}") + String gdalPath; + @Resource PathHelper pathHelper; @@ -42,7 +48,7 @@ /** * 娴嬭瘯 - * + * <p> * POINT (26.72 -48.58) * LINESTRING(18.44 -46.69,20.14 -45.93) * POLYGON ((5.11 -41.64,7.68 -43.59,4.73 -43.3,5.11 -41.64)) @@ -81,7 +87,7 @@ return; } - String filePath = pathHelper.getConfig().getUploadPath() + File.separator + metas.get(0).getPath(); + String filePath = getFilePath(metas); File file = new File(filePath); if (!file.exists() || file.isDirectory()) { setError(entity, "婧愭暟鎹笉瀛樺湪"); @@ -98,6 +104,30 @@ } /** + * 鑾峰彇鏂囦欢璺緞 + */ + private String getFilePath(List<MetaEntity> metas) throws IOException { + String basePath = pathHelper.getConfig().getUploadPath() + File.separator; + if (metas.size() == 1) { + return basePath + metas.get(0).getPath(); + } + + String tempPath = pathHelper.getTempPath() + File.separator, guid = StringHelper.getGuid(); + String fileList = tempPath + guid + ".txt"; + FileWriter fw = new FileWriter(fileList); + for (MetaEntity meta : metas) { + fw.write((basePath + meta.getPath()).toCharArray()); + } + fw.close(); + + String vrt = tempPath + guid + ".vrt"; + String cmd = String.format("\"%s\\gdalbuildvrt.exe\" -input_file_list \"%s\" \"%s\"", gdalPath, fileList, vrt); + WebHelper.exec(cmd); + + return vrt; + } + + /** * 鎺ㄩ�佹秷鎭� */ private void postInfo(AnalysisResultEntity entity) throws IOException { -- Gitblit v1.9.3