Przeglądaj źródła

vector 添加坐标中心

wuweihao 5 lat temu
rodzic
commit
afeef67d21

Plik diff jest za duży
+ 3 - 1
src/main/java/com/fd/constant/Command.java


+ 18 - 3
src/main/java/com/fd/controller/RasterController.java

@@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.PostConstruct;
 import java.io.File;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.BlockingQueue;
@@ -97,8 +98,10 @@ public class RasterController {
 
     @ApiOperation("上传栅格数据,只能上传tif文件")
     @PostMapping(value = "upload", consumes = { "multipart/form-data" })
-    private R upload(@RequestParam("file") MultipartFile file){
+    private R upload(@RequestParam("file") MultipartFile file, @RequestParam(value = "coord",required = false) String[] coord){
         log.info("run upload");
+        log.info("coord: {}", Arrays.toString(coord));
+        String strCoord = Arrays.toString(coord);
 
         // 文件名全名
         String fileName = file.getOriginalFilename();
@@ -119,7 +122,7 @@ public class RasterController {
         }
 
 
-        R r = rasterServer.uploadBigFile(file);
+        R r = rasterServer.uploadBigFile(file, strCoord);
 
         OutputFileEntity entity = (OutputFileEntity) r.getData();
 
@@ -213,7 +216,7 @@ public class RasterController {
 
 
     /**
-     * 坐标判断消费队列
+     * 坐标转换消费队列
      */
     public class JudgeCoordConsumerThread implements Runnable{
 
@@ -402,6 +405,9 @@ public class RasterController {
         FileUtils.createDir(outFileStep1);
         outFileStep1 = outFileStep1 + File.separator + entity.getFileName();
 
+        // 坐标处理
+        String coord = entity.getCoord();
+
         String step_1 = Command.RASTER_TRANSFORM_GDALWARP_STRICT_1;
         String step_2 = Command.RASTER_TRANSFORM_GDALWARP_STRICT_2;
         step_1 = step_1.replace("@inputFile", entity.getUploadPath());
@@ -433,4 +439,13 @@ public class RasterController {
         return entity;
     }
 
+
+
+
+    public static void main(String[] args) {
+        String [] a = {"1.1","1.2","1.3"};
+        List<String> list = Arrays.asList(a);
+        System.out.println(list.get(1));
+    }
+
 }

+ 47 - 9
src/main/java/com/fd/controller/VectorController.java

@@ -25,7 +25,9 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.PostConstruct;
 import java.io.File;
+import java.util.Arrays;
 import java.util.Date;
+import java.util.Map;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
@@ -97,15 +99,37 @@ public class VectorController {
      * 因为他是要目录上传,所以一目录名为唯一标识符。
      * 这个模块的所有生成的文件都需要加个目录,以防重名覆盖
      */
+//    @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
+//    @PostMapping(value = "uploadMult/{directoryName}", consumes = { "multipart/form-data" })
+//    private R uploadMult(@RequestParam("file") MultipartFile[] file,
+//                     @PathVariable("directoryName") String directoryName,
+//                     @RequestParam(value = "coord",required = false) String coord){
+//        log.info("run uploadMult");
+//        log.info("coord: {}", coord);
+//
+//        R r = vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
+//
+//        OutputFileEntity entity = (OutputFileEntity) r.getData();
+//
+//        // 判断坐标
+//        entity = JudgeCoord(entity);
+//
+//        return new R(200, entity);
+//
+////        return vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
+//    }
+
+
     @ApiOperation("上传矢量数据, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
     @PostMapping(value = "uploadMult/{directoryName}", consumes = { "multipart/form-data" })
     private R uploadMult(@RequestParam("file") MultipartFile[] file,
-                     @PathVariable("directoryName") String directoryName,
-                     @RequestParam(value = "coord",required = false) String coord){
+                         @PathVariable("directoryName") String directoryName,
+                         @RequestParam("coord") String[] coord){
         log.info("run uploadMult");
-        log.info("coord: {}", coord);
+        log.info("coord: {}", Arrays.toString(coord));
+        String strCoord = Arrays.toString(coord);
 
-        R r = vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
+        R r = vectorServer.uploadDirectoryFileMul(file, directoryName, strCoord);
 
         OutputFileEntity entity = (OutputFileEntity) r.getData();
 
@@ -129,21 +153,24 @@ public class VectorController {
         cmd = cmd.replace("@inputFile", entity.getUploadPath());
         log.info("cmd: {}", cmd);
 
-        Integer isJudge = cmdServer.exeCmdJudgeCoord(cmd);
+//        Integer isJudge = cmdServer.exeCmdJudgeCoord(cmd);
+
+        Map map = vectorServer.cmdJudgeCoord(cmd);
+        Integer code = (int)map.get("code");
 
 
         // 转换坐标 普通坐标转换
-        if (isJudge == 1000){
+        if (code == 1000){
             // 普通坐标转换
             log.info("need to general transform");
             entity.setCoordType(TypeCode.COORD_SYSTEM_2000);
-        } else if (isJudge == 1001) {
+        } else if (code == 1001) {
 
             // 严格坐标转换 (西安80转wgs84),需要参数
-            log.info("need to strict transform, code: {}", isJudge);
+            log.info("need to strict transform, code: {}", code);
             entity.setCoordType(TypeCode.COORD_XIAN_1980);
 
-        } else if (0 == isJudge){
+        } else if (0 == code){
             // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
             log.info("not to transform");
             entity.setCoordType(TypeCode.COORD_WGS84);
@@ -155,6 +182,17 @@ public class VectorController {
 
         entity.setUpdateTime(new Date());
         vectorServer.save(entity);
+
+        // 保存经纬度
+        StyleEntity styleEntity = new StyleEntity();
+        styleEntity.setOutputFileId(entity.getId());
+        styleEntity.setCreateTime(new Date());
+        styleEntity.setUpdateTime(new Date());
+        styleEntity.setLongitude(map.get("longitude")+"");
+        styleEntity.setLatitude(map.get("latitude")+"");
+
+        vectorServer.saveStyle(styleEntity);
+
         return entity;
     }
 

+ 20 - 0
src/main/java/com/fd/entity/StyleEntity.java

@@ -40,5 +40,25 @@ public class StyleEntity extends BaseEntity implements Serializable {
     @Column
     private String name;
 
+    /**
+     * 图层
+     */
+    @Column
+    private String layer;
+
+
+    /**
+     * 经度
+     */
+    @Column
+    private String longitude;
+
+
+    /**
+     * 纬度
+     */
+    @Column
+    private String latitude;
+
 
 }

+ 1 - 1
src/main/java/com/fd/server/RasterServer.java

@@ -18,7 +18,7 @@ public interface RasterServer {
 
     R moveFileToServer(Long fileId, ConfigJsonDto param);
 
-    R uploadBigFile(MultipartFile file);
+    R uploadBigFile(MultipartFile file, String strCoord);
 
     R findByType(String fileTypeRaster, PageDto param);
 

+ 13 - 0
src/main/java/com/fd/server/VectorServer.java

@@ -5,10 +5,12 @@ import com.fd.dto.PageDto;
 import com.fd.dto.StyleDto;
 import com.fd.entity.FileEntity;
 import com.fd.entity.OutputFileEntity;
+import com.fd.entity.StyleEntity;
 import com.fd.util.R;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * Created by Owen on 2019/11/21 0021 15:29
@@ -42,10 +44,21 @@ public interface VectorServer {
     R saveStyle(StyleDto entity);
 
 
+    StyleEntity saveStyle(StyleEntity entity);
+
+
     /**
      * 获取样式
      * @param id outputFileId
      * @return R
      */
     R getStyle(Long id);
+
+
+    /**
+     * 判断坐标
+     * @param cmd 命令
+     * @return Map
+     */
+    Map cmdJudgeCoord(String cmd);
 }

+ 120 - 4
src/main/java/com/fd/server/impl/CmdServerImpl.java

@@ -15,7 +15,10 @@ import org.springframework.stereotype.Service;
 
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
-import java.util.Date;
+import java.math.BigDecimal;
+import java.util.*;
+
+import static java.math.BigDecimal.ROUND_HALF_UP;
 
 /**
  * Created by Owen on 2019/11/14 0014 15:33
@@ -138,10 +141,13 @@ public class CmdServerImpl implements CmdServer {
      */
     @Override
     public Integer exeCmdJudgeCoord(String commandStr) {
-        Integer isCmd = null; // 命令运行结果 1:失败, 0:成功
+        // 命令运行结果 1:失败, 0:成功
+        Integer isCmd = null;
 
         StringBuffer sb = new StringBuffer();
         StringBuffer errorStr = new StringBuffer();
+
+        Map map = null;
         try {
             String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
             Process ps = Runtime.getRuntime().exec(cmd);
@@ -164,6 +170,10 @@ public class CmdServerImpl implements CmdServer {
             while ((line = br.readLine()) != null) {
                 //执行结果加上回车
                 sb.append(line).append("\n");
+                // 获取经纬度
+//                if (line.contains("Extent: (")){
+//                    map = getExtent(line);
+//                }
             }
             log.info("result: {}", sb.toString());
 
@@ -190,7 +200,7 @@ public class CmdServerImpl implements CmdServer {
 
             if (sb.toString().contains("GEOGCS[\"Xian 1980\"")) {
                 // 需要严格坐标转换
-                isCmd = 1001;  // 2:
+                isCmd = 1001;
                 log.info("需要严格坐标转换code:{}, GEOGCS[\"Xian 1980\"", isCmd);
             }
 
@@ -199,6 +209,13 @@ public class CmdServerImpl implements CmdServer {
                 isCmd = 0;
                 log.info("不需要坐标转换code:{}, GEOGCS[\"WGS 84\"", isCmd);
             }
+
+
+            // 获取经纬度
+            if (sb.toString().contains("Extent: (")) {
+
+            }
+
         } else {
             log.info("error exeCmd wsitFore: {}", isCmd);
         }
@@ -215,7 +232,8 @@ public class CmdServerImpl implements CmdServer {
      */
     @Override
     public Integer exeCmdRasterJudgeCoord(String commandStr) {
-        Integer isCmd = null; // 命令运行结果 1:失败, 0:成功
+        // 命令运行结果 1:失败, 0:成功
+        Integer isCmd = null;
 
         StringBuffer sb = new StringBuffer();
         StringBuffer errorStr = new StringBuffer();
@@ -371,4 +389,102 @@ public class CmdServerImpl implements CmdServer {
     }
 
 
+
+    /**
+     * 获取经纬度平均值
+     * @param str 传入参数
+     * @return map
+     */
+    private Map getExtent(String str){
+        str = str.replace("Extent: (", "");
+        str = str.replaceAll("\\(", "");
+        str = str.replaceAll("\\)", "");
+        str = str.replaceAll(" -", ",");
+
+        String[] strArray = str.split(",");
+        List<String> list = Arrays.asList(strArray);
+
+        BigDecimal b0 = new BigDecimal(list.get(0));
+        BigDecimal b1 = new BigDecimal(list.get(1));
+        BigDecimal b2 = new BigDecimal(list.get(2));
+        BigDecimal b3 = new BigDecimal(list.get(3));
+
+        // 经度
+        BigDecimal longitude = b0.add(b2);
+        longitude = longitude.divide(new BigDecimal(2), 6, BigDecimal.ROUND_HALF_UP);
+        // 纬度
+        BigDecimal latitude = b1.add(b3);
+        latitude = latitude.divide(new BigDecimal(2), 6, BigDecimal.ROUND_HALF_UP);
+
+        HashMap<Object, Object> map = new HashMap<>();
+        map.put("longitude", longitude);
+        map.put("latitude", latitude);
+        return map;
+    }
+
+    public static void main(String[] args) {
+        String a= "Geometry: Polygon\n" +
+                "Feature Count: 1\n" +
+                "Extent: (38406065.048401, 2492544.702881) - (38406742.383118, 2493085.698914)\n" +
+                "Layer SRS WKT:\n" +
+                "PROJCS[\"Xian_1980_3_degree_Gauss_Kruger_zone_38\",\n" +
+                "    GEOGCS[\"Xian 1980\",\n" +
+                "        DATUM[\"Xian_1980\",\n" +
+                "            SPHEROID[\"IAG 1975\",6378140,298.257,\n" +
+                "                AUTHORITY[\"EPSG\",\"7049\"]],\n" +
+                "            AUTHORITY[\"EPSG\",\"6610\"]],\n" +
+                "        PRIMEM[\"Greenwich\",0],\n" +
+                "        UNIT[\"Degree\",0.0174532925199433]],\n" +
+                "    PROJECTION[\"Transverse_Mercator\"],\n" +
+                "    PARAMETER[\"latitude_of_origin\",0],\n" +
+                "    PARAMETER[\"central_meridian\",114],\n" +
+                "    PARAMETER[\"scale_factor\",1],\n" +
+                "    PARAMETER[\"false_easting\",38500000],\n" +
+                "    PARAMETER[\"false_northing\",0],\n" +
+                "    UNIT[\"metre\",1,\n" +
+                "        AUTHORITY[\"EPSG\",\"9001\"]],\n" +
+                "    AXIS[\"Easting\",EAST],\n" +
+                "    AXIS[\"Northing\",NORTH]]\n" +
+                "Data axis to CRS axis mapping: 1,2";
+
+        String b = "Extent: (38406065.048401, 2492544.702881) - (38406742.383118, 2493085.698914)\n";
+
+        if (b.contains("Extent: (")){
+            String s = b.substring(b.lastIndexOf("Extent: (") + 8, b.lastIndexOf("\n"));
+            System.out.println(s);
+            s = s.replaceAll("\\(", "");
+            s = s.replaceAll("\\)", "");
+            s = s.replaceAll(" -", ",");
+            s = s.replaceAll("-", ",");
+//            s = s.replaceAll("\\t", "");
+            s = StringUtils.deleteWhitespace(s);
+
+            String[] bb = s.split(",");
+            List<String> asList = Arrays.asList(bb);
+            System.out.println(Arrays.asList(bb));
+            System.out.println("0: " + asList.get(0));
+            System.out.println("1: " + asList.get(1));
+            System.out.println("2: " + asList.get(2));
+            System.out.println("3: " + asList.get(3));
+
+
+            String s1 = asList.get(0);
+            String s2 = asList.get(1);
+            String s3 = asList.get(2);
+            String s4 = asList.get(3);
+            BigDecimal b01 = new BigDecimal(s1);
+            BigDecimal b02 = new BigDecimal(s2);
+            BigDecimal b03 = new BigDecimal(s3);
+            BigDecimal b04 = new BigDecimal(s4);
+
+
+
+
+
+
+
+        }
+    }
+
+
 }

+ 18 - 5
src/main/java/com/fd/server/impl/RasterServerImpl.java

@@ -9,8 +9,11 @@ import com.fd.constant.TypeCode;
 import com.fd.dto.ConfigJsonDto;
 import com.fd.dto.PageDto;
 import com.fd.entity.FileEntity;
+//import com.fd.entity.LayerEntity;
 import com.fd.entity.OutputFileEntity;
+import com.fd.entity.StyleEntity;
 import com.fd.repository.FileRepository;
+//import com.fd.repository.LayerRepository;
 import com.fd.repository.OutputFileRepository;
 import com.fd.server.CmdServer;
 import com.fd.server.RasterServer;
@@ -67,6 +70,10 @@ public class RasterServerImpl implements RasterServer {
     private CmdServer cmdServer;
 
 
+//    @Autowired
+//    private LayerRepository layerRepository;
+
+
     @Override
     public R deleteById(Long fileId) {
         // 删除服务器文件
@@ -128,7 +135,7 @@ public class RasterServerImpl implements RasterServer {
             // 修改前端的config.json 文件
             String lastName = StringUtils.substringAfterLast(entity.getSlicePath(), "/");
             log.info("lastName: {}", lastName);
-            writeJsonFile(param, lastName);
+            writeJsonFile(param, lastName, entity);
 
             //修改linux 文件权限
             String cmd = Command.CMD_CHOMD_755;
@@ -153,7 +160,7 @@ public class RasterServerImpl implements RasterServer {
     }
 
     @Override
-    public R uploadBigFile(MultipartFile file) {
+    public R uploadBigFile(MultipartFile file, String strCoord) {
         long start = System.currentTimeMillis();
         if (file.isEmpty() || file.getSize() <= 0) {
             log.info("文件为空");
@@ -190,6 +197,7 @@ public class RasterServerImpl implements RasterServer {
         entity.setCreateTime(new Date());
         entity.setUpdateTime(new Date());
         entity.setType(TypeCode.FILE_TYPE_RASTER);
+        entity.setCoord(strCoord);
         entity.setStatus(2);
         fileRepository.save(entity);
 
@@ -198,6 +206,7 @@ public class RasterServerImpl implements RasterServer {
         outputFile.setUploadPath(entity.getFileUrl());
         outputFile.setFileName(entity.getFileName());
         outputFile.setStatus(2);
+        outputFile.setCoord(strCoord);
         outputFile.setType(TypeCode.FILE_TYPE_RASTER);
         outputFile.setCreateTime(new Date());
         outputFile.setUpdateTime(new Date());
@@ -235,7 +244,7 @@ public class RasterServerImpl implements RasterServer {
         return outputFileRepository.save(fileSchedule);
     }
 
-    private void writeJsonFile(ConfigJsonDto param, String lastName) {
+    private void writeJsonFile(ConfigJsonDto param, String lastName, OutputFileEntity entity) {
         String s = FileUtils.readFile(CONFIG_JSON_PATH);
 
         JSONObject original = JSON.parseObject(s);
@@ -246,9 +255,11 @@ public class RasterServerImpl implements RasterServer {
 
         JSONObject subJson = new JSONObject();
         long cu = System.currentTimeMillis();
-        subJson.put("name", "raster_" + cu); // 需要唯一
+        // 需要唯一
+        subJson.put("name", "raster_" + cu);
         subJson.put("text", param.getText());
-        subJson.put("type", "imagery"); // raster 就用这个类型
+        // raster 就用这个类型
+        subJson.put("type", "imagery");
         subJson.put("checked", false);
         subJson.put("show", true);
         subJson.put("url", "../data/" + lastName);
@@ -260,6 +271,8 @@ public class RasterServerImpl implements RasterServer {
         log.info("original update: {}", original.toJSONString());
         try {
             FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
+
+
         } catch (IOException e) {
             e.printStackTrace();
         }

+ 161 - 8
src/main/java/com/fd/server/impl/VectorServerImpl.java

@@ -10,9 +10,11 @@ import com.fd.dto.ConfigJsonDto;
 import com.fd.dto.PageDto;
 import com.fd.dto.StyleDto;
 import com.fd.entity.FileEntity;
+//import com.fd.entity.LayerEntity;
 import com.fd.entity.OutputFileEntity;
 import com.fd.entity.StyleEntity;
 import com.fd.repository.FileRepository;
+//import com.fd.repository.LayerRepository;
 import com.fd.repository.OutputFileRepository;
 import com.fd.repository.StyleRepository;
 import com.fd.server.CmdServer;
@@ -31,8 +33,11 @@ import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStreamReader;
+import java.math.BigDecimal;
 import java.util.*;
 
 
@@ -72,6 +77,9 @@ public class VectorServerImpl implements VectorServer {
     @Autowired
     private StyleRepository styleRepository;
 
+//    @Autowired
+//    private LayerRepository layerRepository;
+
     @Override
     public R moveFileToServer(Long fileId, ConfigJsonDto param) {
         Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
@@ -85,7 +93,7 @@ public class VectorServerImpl implements VectorServer {
         try {
             org.apache.commons.io.FileUtils.copyDirectoryToDirectory(new File(entity.getSlicePath()), new File(MOVE_FILE_TO_SERVER));
             // 修改前端的config.json 文件
-            writeJsonFile(param, entity.getDirectory());
+            writeJsonFile(param, entity.getDirectory(), entity);
 
             //修改linux 文件权限
             String cmd = Command.CMD_CHOMD_755;
@@ -330,20 +338,153 @@ public class VectorServerImpl implements VectorServer {
 
     @Override
     public R saveStyle(StyleDto entity) {
-        StyleEntity styleEntity = new StyleEntity();
-        BeanUtils.copyProperties(entity, styleEntity);
-        styleEntity.setCreateTime(new Date());
+//        StyleEntity styleEntity = new StyleEntity();
+        StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(entity.getOutputFileId());
+
+
+//        BeanUtils.copyProperties(entity, styleEntity);
         styleEntity.setUpdateTime(new Date());
+        styleEntity.setContent(entity.getContent());
         StyleEntity save = styleRepository.save(styleEntity);
         return new R(200, save.getOutputFileId());
     }
 
     @Override
+    public StyleEntity saveStyle(StyleEntity entity) {
+        return styleRepository.save(entity);
+    }
+
+    @Override
     public R getStyle(Long id) {
         return new R(200, styleRepository.findByOutputFileIdTop(id));
     }
 
     @Override
+    public Map cmdJudgeCoord(String commandStr) {
+            // 命令运行结果 1:失败, 0:成功
+            Integer isCmd = null;
+
+            StringBuffer sb = new StringBuffer();
+            StringBuffer errorStr = new StringBuffer();
+
+            Map map = null;
+            try {
+                String[] cmd = new String[]{"/bin/sh", "-c", commandStr};
+                Process ps = Runtime.getRuntime().exec(cmd);
+
+                BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
+                BufferedReader errorBuf = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
+
+                // error : 坑, 控制台信息是从errorBuf这里出来的
+                String errorLine;
+                while ((errorLine = errorBuf.readLine()) != null) {
+                    errorStr.append(errorLine).append("\n");
+                }
+                if (StringUtils.isNotEmpty(errorStr)){
+                    log.info("error result: {}", errorStr.toString());
+                }
+
+
+                // success ,没有获取到信息
+                String line;
+                while ((line = br.readLine()) != null) {
+                    //执行结果加上回车
+                    sb.append(line).append("\n");
+                    // 获取经纬度
+
+                    if (line.contains("Extent: (")){
+                        log.info("extent: {}", line);
+                        map = getExtent(line);
+                    }
+                }
+                log.info("result: {}", sb.toString());
+
+                // 结束命令行
+                isCmd = ps.waitFor();
+                map.put("code", isCmd);
+
+                // 关闭流
+                br.close();
+                errorBuf.close();
+
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+
+
+            if (isCmd == 0) {
+                log.info("end exeCmd : {}", isCmd);
+                // 判断坐标
+                if (sb.toString().contains("GEOGCS[\"China Geodetic Coordinate System 2000\"")) {
+                    // 需要普通坐标转换
+                    isCmd = 1000;
+                    log.info("需要坐标转换code:{}, GEOGCS[\"China Geodetic Coordinate System 2000\"", isCmd);
+                }
+
+                if (sb.toString().contains("GEOGCS[\"Xian 1980\"")) {
+                    // 需要严格坐标转换
+                    isCmd = 1001;
+                    log.info("需要严格坐标转换code:{}, GEOGCS[\"Xian 1980\"", isCmd);
+                }
+
+                if (sb.toString().contains("GEOGCS[\"WGS 84\"")) {
+                    // 不需要坐标转换
+                    isCmd = 0;
+                    log.info("不需要坐标转换code:{}, GEOGCS[\"WGS 84\"", isCmd);
+                }
+
+
+                // 获取经纬度
+                if (sb.toString().contains("Extent: (")) {
+
+                }
+
+            } else {
+                log.info("error exeCmd wsitFore: {}", isCmd);
+            }
+
+            return map;
+
+    }
+
+
+    /**
+     * 获取经纬度平均值
+     * @param str 传入参数
+     * @return map
+     */
+    private Map getExtent(String str){
+
+        str = str.replace("Extent: (", "");
+        str = str.replaceAll("\\(", "");
+        str = str.replaceAll("\\)", "");
+        str = str.replaceAll(" -", ",");
+
+        // 去除所有空白字符
+        str = StringUtils.deleteWhitespace(str);
+        String[] strArray = str.split(",");
+        List<String> list = Arrays.asList(strArray);
+        log.info("extent list: {}", Arrays.asList(strArray));
+
+        BigDecimal b0 = new BigDecimal(list.get(0));
+        BigDecimal b1 = new BigDecimal(list.get(1));
+        BigDecimal b2 = new BigDecimal(list.get(2));
+        BigDecimal b3 = new BigDecimal(list.get(3));
+
+        // 经度
+        BigDecimal longitude = b0.add(b2);
+        longitude = longitude.divide(new BigDecimal(2), 6, BigDecimal.ROUND_HALF_UP);
+        // 纬度
+        BigDecimal latitude = b1.add(b3);
+        latitude = latitude.divide(new BigDecimal(2), 6, BigDecimal.ROUND_HALF_UP);
+
+        HashMap<Object, Object> map = new HashMap<>();
+        map.put("longitude", longitude);
+        map.put("latitude", latitude);
+        return map;
+    }
+
+    @Override
     public OutputFileEntity findById(Long fileId) {
         Optional<OutputFileEntity> o = outputFileRepository.findById(fileId);
         if (o.isPresent()) {
@@ -361,7 +502,7 @@ public class VectorServerImpl implements VectorServer {
     /**
      * 修改config.json
      */
-    private void writeJsonFile(ConfigJsonDto param, String lastName) {
+    private void writeJsonFile(ConfigJsonDto param, String lastName, OutputFileEntity entity) {
         String s = FileUtils.readFile(CONFIG_JSON_PATH);
 
         JSONObject original = JSON.parseObject(s);
@@ -372,20 +513,32 @@ public class VectorServerImpl implements VectorServer {
 
         JSONObject subJson = new JSONObject();
         long cu = System.currentTimeMillis();
-        subJson.put("name", "vector_" + cu); // 需要唯一
+        // 需要唯一
+        subJson.put("name", "vector_" + cu);
+
         subJson.put("text", param.getText());
-        subJson.put("type", "geodata"); // vector 就用这个类型geodata
+        // vector 就用这个类型geodata
+        subJson.put("type", "geodata");
         subJson.put("checked", false);
         subJson.put("show", true);
         subJson.put("url", "../data/" + lastName);
-
         layers.add(subJson);
 
+
+
         original.put("layers", layers);
 
         log.info("original update: {}", original.toJSONString());
         try {
             FileUtils.fileWriter(JSON.toJSONString(original), CONFIG_JSON_PATH);
+
+            // 将图层信息保存到db
+
+            StyleEntity styleEntity = styleRepository.findByOutputFileIdTop(entity.getId());
+            styleEntity.setLayer(subJson.toJSONString());
+            styleEntity.setUpdateTime(new Date());
+            styleRepository.save(styleEntity);
+
         } catch (IOException e) {
             e.printStackTrace();
         }

+ 12 - 3
src/main/java/com/fd/util/RegexUtils.java

@@ -15,6 +15,8 @@ public class RegexUtils {
     /** No. */
     public static final String INTEGER_PATTERN = "^([+-]?)\\d*\\.?\\d+$" ;
 
+    public static final String INT_DECIMAL = "\\d*\\.?\\d+$" ;
+
 
     /**  匹配中文 */
     public static boolean regexChinese(String param){
@@ -32,6 +34,14 @@ public class RegexUtils {
         return param.matches(INTEGER_PATTERN) ;
     }
 
+    /**  匹配数字 */
+    public static boolean regexIntOrDecimal(String param){
+        if(StringUtils.isEmpty(param)){
+            return Boolean.FALSE ;
+        }
+        return param.matches(INTEGER_PATTERN) ;
+    }
+
 
 
     public static void main(String[] args) {
@@ -39,11 +49,10 @@ public class RegexUtils {
         String a1 = "i m aaa";
         String a2 = "1245454--";
         String a3 = "1245454--中国人";
-        String a4 = "123..";
+        String a4 = "123";
 
 
-        System.out.println(regexInt(a));
-        System.out.println(regexInt(a4));
+        System.out.println(regexIntOrDecimal(a4));
 
     }
 }