فهرست منبع

修改
切片接口
上传接口判断坐标

wuweihao 5 سال پیش
والد
کامیت
2dfdc963c7

+ 4 - 4
src/main/java/com/fd/config/MyInterceptor.java

@@ -24,12 +24,12 @@ public class MyInterceptor implements HandlerInterceptor {
      */
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
-        log.info("run preHandle");
+//        log.info("run preHandle");
+//
+//        log.info("request url: {}", request.getRequestURL());
+//        log.info("request tRemoteAddr: {}", request.getRemoteAddr());
 
-        log.info("request url: {}", request.getRequestURL());
 
-
-//        String originHeader = request.getHeader("origin");
         String requestHeaders = request.getHeader("Access-Control-Request-Headers");
         if (requestHeaders==null) {
             requestHeaders = "";

+ 4 - 1
src/main/java/com/fd/config/WebMvcConfg.java

@@ -85,7 +85,10 @@ public class WebMvcConfg implements WebMvcConfigurer {
         // 设置全程返回时间
         fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
         // 设置返回值为null是时输出,不写的话,null 字段 不返回。也可以设置返回空串
-        fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteMapNullValue);
+//        fastJsonConfig.setSerializerFeatures(SerializerFeature.IgnoreNonFieldGetter);
+//        fastJsonConfig.setSerializerFeatures(SerializerFeature.NotWriteDefaultValue);
+        fastJsonConfig.setSerializerFeatures(SerializerFeature.WriteNullStringAsEmpty);
+//        fastJsonConfig.setSerializerFeatures(SerializerFeature.NotWriteDefaultValue, SerializerFeature.IgnoreNonFieldGetter);
         fastJson.setFastJsonConfig(fastJsonConfig);
 
         //3、中文乱码解决方案

+ 7 - 5
src/main/java/com/fd/constant/Command.java

@@ -18,7 +18,7 @@ public class Command {
      * 输出文件:/root/gis/cesium/input/transform/@fileName/@fileName.shp
      * 坐标参数:EPSG:4326
      */
-    public static String VECTOR_TRANSFORM_GENERAL  = "docker run --rm -v /root/gis/cesium:/root/gis/cesium osgeo/gdal  ogr2ogr -t_srs EPSG:4326  @outputFile  @inputFile";
+    public static String VECTOR_TRANSFORM_GENERAL  = "c";
 
 
     /**
@@ -56,7 +56,8 @@ public class Command {
      * 输出文件:@outputFile
      *
      */
-    public static String VECTOR_SLICE_TIPPECANOE = "tippecanoe -e @outputFile --extend-zooms-if-still-dropping -cP -z20 -Z10 @inputFile";
+//    public static String VECTOR_SLICE_TIPPECANOE = "tippecanoe -e @outputFile --extend-zooms-if-still-dropping -cP -z20 -Z10 @inputFile";
+    public static String VECTOR_SLICE_TIPPECANOE = "tippecanoe -e @outputFile --extend-zooms-if-still-dropping -pC --force -z@layerMax -Z@layerMin @inputFile";
 
     /**
      * 矢量数据判断坐标
@@ -68,10 +69,11 @@ public class Command {
     /**
      * 栅格数据切片命令
      */
-    public static String RASTER_SLICE_OSGEO  = "docker run --rm -v /root/gis/cesium:/root/gis/cesium " +
-            "osgeo/gdal python3 /usr/bin/gdal2tiles.py --zoom=9-19 --processes=6 @inputFile @outputFile";
-
+//    public static String RASTER_SLICE_OSGEO  = "docker run --rm -v /root/gis/cesium:/root/gis/cesium " +
+//            "osgeo/gdal python3 /usr/bin/gdal2tiles.py --zoom=9-19 --processes=6 @inputFile @outputFile";
 
+    public static String RASTER_SLICE_OSGEO  = "docker run --rm -v /root/gis/cesium:/root/gis/cesium " +
+            "osgeo/gdal python3 /usr/bin/gdal2tiles.py --zoom=@layerMin-@layerMax --processes=6 @inputFile @outputFile";
 
     /**
      * 栅格数据判断坐标

+ 2 - 0
src/main/java/com/fd/constant/MsgCode.java

@@ -36,6 +36,8 @@ public class MsgCode {
 
     public static final String E50009 = "坐标为空,转换失败";
 
+    public static final String E50010 = "参数只接受数字";
+
 
 
 

+ 23 - 6
src/main/java/com/fd/constant/TypeCode.java

@@ -7,15 +7,32 @@ package com.fd.constant;
  */
 public class TypeCode {
 
-//    public static final String FILE_TYPE_RASTER_TIF = "tif"; // 栅格数据
-    public static final String FILE_TYPE_RASTER = "raster"; // 栅格数据
+    /**
+     * 栅格数据
+     */
+    public static final String FILE_TYPE_RASTER = "raster";
 
-//    public static final String FILE_TYPE_VECTOR_SHP = "shp"; // 转换后的矢量数据
 
-    public static final String FILE_TYPE_VECTOR = "vector"; // 矢量数据
+    /**
+     * 矢量数据
+     */
+    public static final String FILE_TYPE_VECTOR = "vector";
 
-//    public static final String FILE_TYPE_MODEL_OSGB = "osgb"; // 模型数据
-    public static final String FILE_TYPE_MODEL = "model"; // 模型数据
+
+
+    /**
+     * 模型数据
+     */
+    public static final String FILE_TYPE_MODEL = "model";
+
+    /**
+     * 不需要转坐标,显示WGS84
+     */
+    public static final String COORD_WGS84 = "WGS84";
+
+    public static final String COORD_XIAN_1980 = "Xian 1980";
+
+    public static final String COORD_SYSTEM_2000 = "CGCS 2000";
 
 
 

+ 58 - 16
src/main/java/com/fd/controller/RasterController.java

@@ -9,7 +9,6 @@ import com.fd.dto.PageDto;
 import com.fd.entity.FileEntity;
 import com.fd.entity.OutputFileEntity;
 import com.fd.server.CmdServer;
-//import com.fd.server.FileServer;
 import com.fd.server.RasterServer;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
@@ -24,7 +23,6 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.PostConstruct;
 import java.io.File;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.BlockingQueue;
@@ -47,9 +45,6 @@ public class RasterController {
     @Value("${output.file.path.raster}")
     private String OUTPUT_FILE_PATH;
 
-//    @Autowired
-//    private FileServer fileServer;
-
     @Autowired
     private CmdServer cmdServer;
 
@@ -123,14 +118,54 @@ public class RasterController {
             return new R(51006, MsgCode.E51006);
         }
 
-        return rasterServer.uploadBigFile(file);
 
+        R r = rasterServer.uploadBigFile(file);
+
+        OutputFileEntity entity = (OutputFileEntity) r.getData();
+
+        // 判断坐标
+        entity = JudgeCoord(entity);
+
+        return new R(200, entity);
+
+    }
+
+    /**
+     * 上传后判断坐标,显示原始坐标
+     * @return
+     */
+    private OutputFileEntity JudgeCoord(OutputFileEntity entity){
+
+        String cmd = Command.RASTER_JUDGE_COORD;
+        cmd = cmd.replace("@inputFile", entity.getUploadPath());
+        log.info("cmd: {}", cmd);
+
+        Integer isJudge = cmdServer.exeCmdRasterJudgeCoord(cmd);
+
+
+        if (1000 == isJudge){
+            log.info("need to transform");
+            // 严格坐标转换
+            entity.setCoordType(TypeCode.COORD_XIAN_1980);
+
+        } else if (0 == isJudge){
+            log.info("not to transform");
+            entity.setCoordType(TypeCode.COORD_WGS84);
+
+        } else {
+            log.info("error exeCmd");
+            entity.setStatus(7);
+
+        }
+
+        entity.setUpdateTime(new Date());
+        rasterServer.save(entity);
+        return entity;
     }
 
     @ApiOperation("获取栅格数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param){
-//        log.info("run list");
         return rasterServer.findByType(TypeCode.FILE_TYPE_RASTER, param);
     }
 
@@ -223,9 +258,7 @@ public class RasterController {
 
                     }
                 } catch (Exception e) {
-//                    entity.setStatus(0);
-//                    entity.setUpdateTime(new Date());
-//                    rasterServer.save(entity);
+
 
                     log.error("error  consume queue raster JudgeCoordConsumerThread: {}", e);
                     e.printStackTrace();
@@ -235,9 +268,18 @@ public class RasterController {
     }
 
     @ApiOperation("栅格数据切片命令")
-    @GetMapping("command/osgeo/{fileId}/")
-    private R cmdSlice(@PathVariable("fileId") Long fileId) {
+    @GetMapping("command/osgeo/{fileId}/{layerMin}/{layerMax}/")
+    private R cmdSlice(@PathVariable("fileId") Long fileId, @PathVariable("layerMin") String layerMin, @PathVariable("layerMax") String layerMax) {
         log.info("run cmdSlice: {}", fileId);
+
+        if (!RegexUtils.regexInt(layerMin)){
+            return new R(50010, MsgCode.E50010) ;
+        }
+        if (!RegexUtils.regexInt(layerMax)){
+            return new R(50010, MsgCode.E50010) ;
+        }
+
+
         OutputFileEntity entity = rasterServer.findById(fileId);
 
         String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
@@ -249,12 +291,16 @@ public class RasterController {
         String cmd = Command.RASTER_SLICE_OSGEO;
         cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
         cmd = cmd.replace("@outputFile", outFilePath);
+        cmd = cmd.replace("@layerMin", layerMin);
+        cmd = cmd.replace("@layerMax", layerMax);
         log.info("cmd: {}", cmd);
 
 
         // 设个默认进度给前端显示
         entity.setProgress(1);
         entity.setStatus(6);
+        entity.setLayerMin(Integer.valueOf(layerMin));
+        entity.setLayerMax(Integer.valueOf(layerMax));
         entity.setUpdateTime(new Date());
         entity.setSlicePath(outFilePath);
 
@@ -318,10 +364,6 @@ public class RasterController {
 
                 } catch (Exception e) {
 
-//                    entity.setStatus(0);
-//                    entity.setUpdateTime(new Date());
-//                    rasterServer.save(entity);
-
                     log.error("error  consume queue raster SliceConsumerThread: {}", e);
                     e.printStackTrace();
                 }

+ 64 - 27
src/main/java/com/fd/controller/VectorController.java

@@ -14,6 +14,7 @@ import com.fd.server.CmdServer;
 import com.fd.server.VectorServer;
 import com.fd.util.FileUtils;
 import com.fd.util.R;
+import com.fd.util.RegexUtils;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
@@ -104,16 +105,63 @@ public class VectorController {
         log.info("run uploadMult");
         log.info("coord: {}", coord);
 
+        R r = vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
 
+        OutputFileEntity entity = (OutputFileEntity) r.getData();
 
-        return vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
+        // 判断坐标
+        entity = JudgeCoord(entity);
+
+        return new R(200, entity);
+
+//        return vectorServer.uploadDirectoryFileMul(file, directoryName, coord);
+    }
+
+
+    /**
+     * 上传后判断坐标,显示原始坐标
+     * @return
+     */
+    private OutputFileEntity JudgeCoord(OutputFileEntity entity){
+
+        // 判断是否需要坐标转换
+        String cmd = Command.VECTOR_JUDGE_COORD;
+        cmd = cmd.replace("@inputFile", entity.getUploadPath());
+        log.info("cmd: {}", cmd);
+
+        Integer isJudge = cmdServer.exeCmdJudgeCoord(cmd);
+
+
+        // 转换坐标 普通坐标转换
+        if (isJudge == 1000){
+            // 普通坐标转换
+            log.info("need to general transform");
+            entity.setCoordType(TypeCode.COORD_SYSTEM_2000);
+        } else if (isJudge == 1001) {
+
+            // 严格坐标转换 (西安80转wgs84),需要参数
+            log.info("need to strict transform, code: {}", isJudge);
+            entity.setCoordType(TypeCode.COORD_XIAN_1980);
+
+        } else if (0 == isJudge){
+            // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
+            log.info("not to transform");
+            entity.setCoordType(TypeCode.COORD_WGS84);
+
+        } else {
+            log.info("error exeCmd");
+            entity.setStatus(7);
+        }
+
+        entity.setUpdateTime(new Date());
+        vectorServer.save(entity);
+        return entity;
     }
 
 
     @ApiOperation("获取矢量数据列表")
     @PostMapping(value = "list")
     private R list(@RequestBody PageDto param){
-//        log.info("run list");
         return vectorServer.findByType(TypeCode.FILE_TYPE_VECTOR, param);
     }
 
@@ -133,7 +181,6 @@ public class VectorController {
     @GetMapping("command/judge/coord/{fileId}/")
     private R cmdJudgeCoord(@PathVariable("fileId") Long fileId) {
         log.info("run cmdJudgeCoord: {}", fileId);
-//        FileEntity entity = fileServer.findById(fileId);
 
         OutputFileEntity entity = vectorServer.findById(fileId);
         entity.setUpdateTime(new Date());
@@ -228,24 +275,10 @@ public class VectorController {
                             // 不转换坐标 把文件信息移动到CoordStrictPath 这路径下
                             log.info("not to transform");
 
-                            // 若果改成用一张表,这里需要修改
-//                            FileEntity fileEntity = vectorServer.findByFileName(entity.getFileName());
-//
-//                            String shpPath = OUTPUT_FILE_PATH + "transform" + File.separator + fileEntity.getDirectory();
-//                            FileUtils.createDir(shpPath);
-//                            shpPath = shpPath + "transform" + File.separator + entity.getFileName();
-//                            entity.setCoordStrictPath(shpPath);
-//
-//                            try {
-//                                String uploadPath = entity.getUploadPath();
-//                                uploadPath= StringUtils.substringBeforeLast(uploadPath, "/");
-//                                org.apache.commons.io.FileUtils.copyDirectoryToDirectory(new File(uploadPath), new File(OUTPUT_FILE_PATH + "transform"));
-//                            } catch (IOException e) {
-//                                e.printStackTrace();
-//                            }
                             entity.setCoordStrictPath(entity.getUploadPath());
                             entity.setUpdateTime(new Date());
                             entity.setStatus(3);
+                            entity.setCoordType(TypeCode.COORD_WGS84);
                             vectorServer.save(entity);
                         } else {
                             log.info("error exeCmd");
@@ -254,13 +287,7 @@ public class VectorController {
                             vectorServer.save(entity);
                         }
                     }
-//                    Thread.sleep(4000);
                 } catch (Exception e) {
-                    //出现异常了,修改修改状态
-//                    entity.setStatus(7);
-//                    entity.setUpdateTime(new Date());
-//                    vectorServer.save(entity);
-
                     log.error("error vector consume queue VectorJudgeCoordConsumerThread: {}", e);
                     throw new RuntimeException(e);
 
@@ -308,10 +335,17 @@ public class VectorController {
 
 
     @ApiOperation("矢量数据切片")
-    @GetMapping("command/slice/{fileId}/")
-    private R cmdSlice (@PathVariable("fileId") Long fileId) {
+    @GetMapping("command/slice/{fileId}/{layerMin}/{layerMax}/")
+    private R cmdSlice (@PathVariable("fileId") Long fileId, @PathVariable("layerMin") String layerMin, @PathVariable("layerMax") String layerMax) {
         log.info("run cmdSlice: {}", fileId);
 
+        if (!RegexUtils.regexInt(layerMin)){
+            return new R(50010, MsgCode.E50010) ;
+        }
+        if (!RegexUtils.regexInt(layerMax)){
+            return new R(50010, MsgCode.E50010) ;
+        }
+
         OutputFileEntity entity = vectorServer.findById(fileId);
 
         String outPath = OUTPUT_FILE_PATH + "slice" + File.separator + entity.getDirectory();
@@ -320,6 +354,8 @@ public class VectorController {
         String cmd = Command.VECTOR_SLICE_TIPPECANOE;
         cmd = cmd.replace("@inputFile", entity.getGeojsonPath());
         cmd = cmd.replace("@outputFile", outPath);
+        cmd = cmd.replace("@layerMin", layerMin);
+        cmd = cmd.replace("@layerMax", layerMax);
         log.info("cmd: {}", cmd);
 
 
@@ -331,6 +367,8 @@ public class VectorController {
         entity.setSlicePath(outPath);
         entity.setUpdateTime(new Date());
         entity.setStatus(5);
+        entity.setLayerMin(Integer.valueOf(layerMin));
+        entity.setLayerMax(Integer.valueOf(layerMax));
         entity = vectorServer.save(entity);
 
         return new R(200, entity);
@@ -371,7 +409,6 @@ public class VectorController {
         cmd = cmd.replace("@inputFile", entity.getUploadPath());
         cmd = cmd.replace("@outputFile", directory);
         log.info("cmd: {}", cmd);
-//        return  runCmd(cmd, entity, directory, null);
         return  runCmd(cmd, entity, null, directory);
     }
 

+ 23 - 2
src/main/java/com/fd/entity/OutputFileEntity.java

@@ -48,8 +48,11 @@ public class OutputFileEntity extends BaseEntity implements Serializable {
     @Column
     private String type; // 文件类型
 
+    /**
+     * 坐标参数
+     */
     @Column
-    private String coord; // 坐标
+    private String coord;
 
     @Column
     private String directory; // 目录名称
@@ -59,7 +62,7 @@ public class OutputFileEntity extends BaseEntity implements Serializable {
      * 状态
      * 0:切片失败
      * 1:未解压
-     * 2:未判断坐标
+     * 2:未判断坐标 改:未转换坐标
      * 3:未转geojson
      * 4:未切片
      * 5:切片完成
@@ -72,4 +75,22 @@ public class OutputFileEntity extends BaseEntity implements Serializable {
     @Column
     private Integer status;
 
+    /**
+     * 图层最小级
+     */
+    @Column
+    private Integer layerMin;
+
+    /**
+     * 图层最大级
+     */
+    @Column
+    private Integer layerMax;
+
+    /**
+     * 坐标类型
+     */
+    @Column
+    private String coordType;
+
 }

+ 2 - 1
src/main/java/com/fd/entity/StyleEntity.java

@@ -27,8 +27,9 @@ public class StyleEntity extends BaseEntity implements Serializable {
 
     /**
      * json内容
+     *
+     * 内容多,要用文件类型,mysql
      */
-//    @Column(columnDefinition="varchar(MAX)")
     @Column(columnDefinition = "LONGTEXT")
     private String content;
 

+ 0 - 2
src/main/java/com/fd/server/impl/CmdServerImpl.java

@@ -154,7 +154,6 @@ public class CmdServerImpl implements CmdServer {
             while ((errorLine = errorBuf.readLine()) != null) {
                 errorStr.append(errorLine).append("\n");
             }
-//            log.info("error result: {}", errorStr.toString());
             if (StringUtils.isNotEmpty(errorStr)){
                 log.info("error result: {}", errorStr.toString());
             }
@@ -163,7 +162,6 @@ public class CmdServerImpl implements CmdServer {
             // success ,没有获取到信息
             String line;
             while ((line = br.readLine()) != null) {
-//                log.info("=====  br.readLine: ======== {}", br.readLine());
                 //执行结果加上回车
                 sb.append(line).append("\n");
             }

+ 5 - 1
src/main/java/com/fd/util/R.java

@@ -1,5 +1,6 @@
 package com.fd.util;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonInclude;
@@ -20,10 +21,13 @@ public class R implements Serializable {
 	private final String message;
 
 //	@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
-	@JsonInclude(value = Include.NON_NULL)
+//	@JsonInclude(value = Include.NON_NULL)
+
 	private final Object data;
 
 	@JsonInclude(value = Include.NON_EMPTY)
+//	@JsonInclude(value = Include.NON_NULL)
+	@JSONField(serialize = false)
 	private final String[] exceptions;
 
 	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")

+ 18 - 5
src/main/java/com/fd/util/RegexUtils.java

@@ -9,9 +9,12 @@ import org.apache.commons.lang3.StringUtils;
  */
 public class RegexUtils {
 
-    // 非中文
+    /** 非中文 */
     public static final String CHINESE_NAME = "^[\\u4E00-\\u9FFF\\W]+$";
 
+    /** No. */
+    public static final String INTEGER_PATTERN = "^([+-]?)\\d*\\.?\\d+$" ;
+
 
     /**  匹配中文 */
     public static boolean regexChinese(String param){
@@ -21,16 +24,26 @@ public class RegexUtils {
         return param.matches(CHINESE_NAME) ;
     }
 
+    /**  匹配数字 */
+    public static boolean regexInt(String param){
+        if(StringUtils.isEmpty(param)){
+            return Boolean.FALSE ;
+        }
+        return param.matches(INTEGER_PATTERN) ;
+    }
+
+
+
     public static void main(String[] args) {
         String a = "我是中国人";
         String a1 = "i m aaa";
         String a2 = "1245454--";
         String a3 = "1245454--中国人";
+        String a4 = "123..";
+
 
-        System.out.println(regexChinese(a));
-        System.out.println(regexChinese(a1));
-        System.out.println(regexChinese(a2));
-        System.out.println(regexChinese(a));
+        System.out.println(regexInt(a));
+        System.out.println(regexInt(a4));
 
     }
 }

+ 1 - 1
src/main/resources/application.properties

@@ -1,7 +1,7 @@
 server.port=8082
 
 # file multipart
-spring.profiles.active=dev
+spring.profiles.active=uat
 spring.servlet.multipart.enabled=true
 spring.servlet.multipart.max-file-size=51200MB
 spring.servlet.multipart.max-request-size=51200MB