Browse Source

add wfs model

wuweihao 5 years ago
parent
commit
2c564b8c0f

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

@@ -23,7 +23,7 @@ public class Command {
      * 输出文件:/root/gis/cesium/input/transform/@fileName/@fileName.shp
      * 坐标参数:EPSG:4326
      */
-    public static String VECTOR_TRANSFORM_GENERAL  = DOCKER_GDAL + "ogr2ogr -t_srs EPSG:4326  @outputFile  @inputFile";
+    public static String VECTOR_TRANSFORM_GENERAL  = DOCKER_GDAL + "ogr2ogr -lco \"encoding=utf-8\" -t_srs EPSG:4326  @outputFile  @inputFile";
 
 
 
@@ -34,7 +34,7 @@ public class Command {
      * 输入文件:
      * 输出文件:
      */
-    public static String VECTOR_TRANSFORM_STRICT_WGS80  = DOCKER_GDAL + "ogr2ogr -overwrite  -s_srs \"+proj=longlat +ellps=GRS80 +no_defs +towgs84=@coord\" -t_srs EPSG:4326 @outputFile @inputFile";
+    public static String VECTOR_TRANSFORM_STRICT_WGS80  = DOCKER_GDAL + "ogr2ogr -lco \"encoding=utf-8\" -overwrite  -s_srs \"+proj=longlat +ellps=GRS80 +no_defs +towgs84=@coord\" -t_srs EPSG:4326 @outputFile @inputFile";
 
     /**
      * 矢量数据 严格坐标转换
@@ -43,7 +43,7 @@ public class Command {
      * 输入文件:
      * 输出文件:
      */
-    public static String VECTOR_TRANSFORM_STRICT_WGS84  = DOCKER_GDAL + "ogr2ogr -overwrite  -s_srs \"+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=38500000 +y_0=0 +ellps=IAU76 +units=m +no_defs +towgs84=@coord\" -t_srs EPSG:4326 @outputFile @inputFile";
+    public static String VECTOR_TRANSFORM_STRICT_WGS84  = DOCKER_GDAL + "ogr2ogr -lco \"encoding=utf-8\" -overwrite  -s_srs \"+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=38500000 +y_0=0 +ellps=IAU76 +units=m +no_defs +towgs84=@coord\" -t_srs EPSG:4326 @outputFile @inputFile";
 
     /**
      * 矢量数据切片 step1
@@ -90,6 +90,12 @@ public class Command {
     public static String VECTOR_WFS_SCOPE = DOCKER_GDAL + "ogr2ogr -overwrite -fieldTypeToString Date -f geojson -spat @xMin @yMin @xMax @yMax @outputFile @inputFile";
 
     /**
+     * 矢量数据要素查询
+     * 获取字段名称
+     */
+    public static String VECTOR_WFS_FIELD = DOCKER_GDAL + "ogrinfo -al -so @inputFile";
+
+    /**
      * 栅格数据切片命令
      */
 
@@ -147,9 +153,9 @@ public class Command {
      * WGS84 转 CGCS2000坐标系
      * 矢量数据 step1 step2
      */
-    public static String convert_TRANSFORM_coord_vector_step1 = DOCKER_GDAL + "ogr2ogr -s_srs epsg:4326 -t_srs \"+proj=longlat +ellps=GRS80 +towgs84=@coord +no_defs\" @outputFile @inputFile";
+    public static String convert_TRANSFORM_coord_vector_step1 = DOCKER_GDAL + "ogr2ogr -lco \"encoding=utf-8\" -s_srs epsg:4326 -t_srs \"+proj=longlat +ellps=GRS80 +towgs84=@coord +no_defs\" @outputFile @inputFile";
 
-    public static String convert_TRANSFORM_coord_vector_step2 = DOCKER_GDAL + "ogr2ogr -a_srs epsg:4490 @outputFile @inputFile";
+    public static String convert_TRANSFORM_coord_vector_step2 = DOCKER_GDAL + "ogr2ogr -lco \"encoding=utf-8\"  -a_srs epsg:4490 @outputFile @inputFile";
 
     /**
      * WGS84 转 CGCS2000坐标系

+ 1 - 1
src/main/java/com/fd/controller/UserController.java

@@ -65,7 +65,7 @@ public class UserController {
         resultMap.put("userName", username);
 
         log.warn("end login");
-        return new R(200, (Object) token);
+        return new R(200, resultMap);
     }
 
 

+ 22 - 22
src/main/java/com/fd/controller/VectorController.java

@@ -92,28 +92,28 @@ public class VectorController {
 
     private static AtomicInteger sliceCount = new AtomicInteger();
 
-    @ApiOperation("精准查询, fileName:字段名,value:字段值")
-    @GetMapping("wfs/accurate/{fileId}/{fileName}/{value}/")
-    public R wfsAccurate(@PathVariable("fileName") String fileName, @PathVariable("value") String value, @PathVariable("fileId") Long fileId){
-        return vectorServer.wfsAccurate(fileId, fileName, value);
-    }
-
-    @ApiOperation("模糊查询, fileName:字段名,value:字段值")
-    @GetMapping("wfs/like/{fileId}/{fileName}/{value}/")
-    public R wfsLike(@PathVariable("fileName") String fileName, @PathVariable("value") String value, @PathVariable("fileId") Long fileId){
-        return vectorServer.wfsLike(fileId, fileName, value);
-    }
-
-    // @xMin @yMin @xMax @yMax
-    @ApiOperation("范围查询, xMin,yMin:最小值,xMax,yMax:最大值")
-    @GetMapping("wfs/scope/{fileId}/{xMin}/{yMin}/{xMax}/{yMax}/")
-    public R wfsScope(@PathVariable("fileId") Long fileId,
-                      @PathVariable("xMin") String xMin,
-                      @PathVariable("yMin") String yMin,
-                      @PathVariable("xMax") String xMax,
-                      @PathVariable("yMax") String yMax){
-        return vectorServer.wfsScope(fileId, xMin, yMin, xMax, yMax);
-    }
+//    @ApiOperation("精准查询, fileName:字段名,value:字段值")
+//    @GetMapping("wfs/accurate/{fileId}/{fileName}/{value}/")
+//    public R wfsAccurate(@PathVariable("fileName") String fileName, @PathVariable("value") String value, @PathVariable("fileId") Long fileId){
+//        return vectorServer.wfsAccurate(fileId, fileName, value);
+//    }
+//
+//    @ApiOperation("模糊查询, fileName:字段名,value:字段值")
+//    @GetMapping("wfs/like/{fileId}/{fileName}/{value}/")
+//    public R wfsLike(@PathVariable("fileName") String fileName, @PathVariable("value") String value, @PathVariable("fileId") Long fileId){
+//        return vectorServer.wfsLike(fileId, fileName, value);
+//    }
+//
+//    // @xMin @yMin @xMax @yMax
+//    @ApiOperation("范围查询, xMin,yMin:最小值,xMax,yMax:最大值")
+//    @GetMapping("wfs/scope/{fileId}/{xMin}/{yMin}/{xMax}/{yMax}/")
+//    public R wfsScope(@PathVariable("fileId") Long fileId,
+//                      @PathVariable("xMin") String xMin,
+//                      @PathVariable("yMin") String yMin,
+//                      @PathVariable("xMax") String xMax,
+//                      @PathVariable("yMax") String yMax){
+//        return vectorServer.wfsScope(fileId, xMin, yMin, xMax, yMax);
+//    }
 
 
 

+ 54 - 0
src/main/java/com/fd/controller/WfsController.java

@@ -0,0 +1,54 @@
+package com.fd.controller;
+
+import com.fd.server.WfsServer;
+import com.fd.util.R;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+
+/**
+ * Created by Owen on 2020/1/2 0002 10:27
+ *
+ * 要素查询,针对矢量数据
+ * manage:是不需要登录的
+ */
+@RequestMapping("manage/wfs")
+@RestController
+public class WfsController {
+
+
+
+    @Autowired
+    private WfsServer wfsServer;
+
+    @ApiOperation("获取图层字段名称, fileId:图层id")
+    @GetMapping("getField/{fileId}/")
+    public R getField(@PathVariable("fileId") Long fileId){
+        return wfsServer.getField(fileId);
+    }
+
+    @ApiOperation("精准查询, fieldName:字段名,value:字段值")
+    @GetMapping("accurate/{fileId}/{fieldName}/{value}/")
+    public R wfsAccurate(@PathVariable("fieldName") String fieldName, @PathVariable("value") String value, @PathVariable("fileId") Long fileId){
+        return wfsServer.wfsAccurate(fileId, fieldName, value);
+    }
+
+    @ApiOperation("模糊查询, fieldName:字段名,value:字段值")
+    @GetMapping("like/{fileId}/{fieldName}/{value}/")
+    public R wfsLike(@PathVariable("fieldName") String fieldName, @PathVariable("value") String value, @PathVariable("fileId") Long fileId){
+        return wfsServer.wfsLike(fileId, fieldName, value);
+    }
+
+    // @xMin @yMin @xMax @yMax
+    @ApiOperation("范围查询, xMin,yMin:最小值,xMax,yMax:最大值")
+    @GetMapping("scope/{fileId}/{xMin}/{yMin}/{xMax}/{yMax}/")
+    public R wfsScope(@PathVariable("fileId") Long fileId,
+                      @PathVariable("xMin") String xMin,
+                      @PathVariable("yMin") String yMin,
+                      @PathVariable("xMax") String xMax,
+                      @PathVariable("yMax") String yMax){
+        return wfsServer.wfsScope(fileId, xMin, yMin, xMax, yMax);
+    }
+
+}

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

@@ -23,5 +23,7 @@ public interface BaseServer {
 
     R deleteById(Long id);
 
+    OutputFileEntity getOutputFileEntity(Long id);
+
 
 }

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

@@ -76,17 +76,4 @@ public interface VectorServer extends BaseServer {
 
     Integer exeCmd(String cmd);
 
-    R wfsAccurate(Long id, String fileName, String value);
-
-    R wfsLike(Long fileId, String fileName, String value);
-
-    R wfsScope(Long fileId, String xMin, String yMin, String xMax, String yMax);
-
-//    /**
-//     * 根据用户权限查询
-//     * @param param
-//     * @param token
-//     * @return
-//     */
-//    Page<OutputFileEntity> findByList(PageDto param, String token);
 }

+ 15 - 0
src/main/java/com/fd/server/WfsServer.java

@@ -0,0 +1,15 @@
+package com.fd.server;
+
+import com.fd.util.R;
+
+public interface WfsServer {
+
+
+    R wfsAccurate(Long id, String fileName, String value);
+
+    R wfsLike(Long fileId, String fileName, String value);
+
+    R wfsScope(Long fileId, String xMin, String yMin, String xMax, String yMax);
+
+    R getField(Long fileId);
+}

+ 10 - 0
src/main/java/com/fd/server/impl/BaseServerImpl.java

@@ -100,8 +100,18 @@ public class BaseServerImpl implements BaseServer {
     }
 
     @Override
+    public OutputFileEntity getOutputFileEntity(Long id) {
+        Optional<OutputFileEntity> o = outputFileRepository.findById(id);
+        if (o.isPresent()) {
+            return o.get();
+        }
+        return null;
+    }
+
+    @Override
     public R findByType(String type, PageDto pageDto) {
         Page<OutputFileEntity> page = outputFileRepository.findByTypeAndResStatus(type, 0,PageRequest.of(pageDto.getPageNum(), pageDto.getPageSize(), Sort.by("createTime").descending()));
         return new R(200, page);
     }
+
 }

+ 7 - 7
src/main/java/com/fd/server/impl/ConvertServerImpl.java

@@ -387,13 +387,13 @@ public class ConvertServerImpl extends BaseServerImpl implements ConvertServer {
         return new R(200, MsgCode.SUCCESS);
     }
 
-    private OutputFileEntity getOutputFileEntity(Long id) {
-        Optional<OutputFileEntity> o = outputFileRepository.findById(id);
-        if (o.isPresent()) {
-            return o.get();
-        }
-        return null;
-    }
+//    private OutputFileEntity getOutputFileEntity(Long id) {
+//        Optional<OutputFileEntity> o = outputFileRepository.findById(id);
+//        if (o.isPresent()) {
+//            return o.get();
+//        }
+//        return null;
+//    }
 
 
 

+ 7 - 7
src/main/java/com/fd/server/impl/DemServerImpl.java

@@ -322,13 +322,13 @@ public class DemServerImpl extends BaseServerImpl implements DemServer {
         return new R(200, MsgCode.SUCCESS);
     }
 
-    private OutputFileEntity getOutputFileEntity(Long id) {
-        Optional<OutputFileEntity> o = outputFileRepository.findById(id);
-        if (o.isPresent()) {
-            return o.get();
-        }
-        return null;
-    }
+//    private OutputFileEntity getOutputFileEntity(Long id) {
+//        Optional<OutputFileEntity> o = outputFileRepository.findById(id);
+//        if (o.isPresent()) {
+//            return o.get();
+//        }
+//        return null;
+//    }
 
     /**
      * 修改config.json

+ 4 - 134
src/main/java/com/fd/server/impl/VectorServerImpl.java

@@ -576,132 +576,6 @@ public class VectorServerImpl extends BaseServerImpl implements VectorServer {
         return isCmd;
     }
 
-    /**
-     * 精准查询
-     *
-     * @param fileId
-     * @param fileName 字段名
-     * @param value 字段值
-     * @return
-     */
-    @Override
-    public R wfsAccurate(Long fileId, String fileName, String value) {
-        log.warn("run wfsAccurate");
-
-        OutputFileEntity entity = getOutputFileEntity(fileId);
-        if (entity == null){
-            new R(50002, MsgCode.E50002);
-        }
-
-        String cmd = Command.VECTOR_WFS_ACCURATE;
-        String outFile = OUTPUT_FILE_PATH + "wfs" + File.separator + entity.getDirectory();
-        FileUtils.createDir(outFile);
-        String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
-        timeName = outFile + File.separator + timeName + ".json";
-
-        // 需要坐标转换后的shp文件
-        cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
-        cmd = cmd.replace("@outputFile", timeName);
-        cmd = cmd.replace("@fileName", fileName);
-        cmd = cmd.replace("@value", value);
-
-        Integer integer = CmdUtil.exeCmdSingle(cmd);
-        JSONObject original = null;
-        if (integer == 0) {
-            String s = FileUtils.readJsonLinux(timeName);
-            original = JSON.parseObject(s);
-
-            if (entity.getWfsPath() == null) {
-                //保存信息
-                entity.setWfsPath(outFile);
-                entity.setUpdateTime(new DateTime());
-                outputFileRepository.save(entity);
-            }
-
-        }
-        log.warn("end wfsAccurate");
-        return new R(200, original);
-    }
-
-    @Override
-    public R wfsLike(Long fileId, String fileName, String value) {
-        log.warn("run wfsLike");
-
-        OutputFileEntity entity = getOutputFileEntity(fileId);
-        if (entity == null){
-            new R(50002, MsgCode.E50002);
-        }
-
-        String cmd = Command.VECTOR_WFS_LIKE;
-        String outFile = OUTPUT_FILE_PATH + "wfs" + File.separator + entity.getDirectory();
-        FileUtils.createDir(outFile);
-        String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
-        timeName = outFile + File.separator + timeName + ".json";
-
-        // 需要坐标转换后的shp文件
-        cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
-        cmd = cmd.replace("@outputFile", timeName);
-        cmd = cmd.replace("@fileName", fileName);
-        cmd = cmd.replace("@value", value);
-
-        Integer integer = CmdUtil.exeCmdSingle(cmd);
-        JSONObject original = null;
-        if (integer == 0) {
-            String s = FileUtils.readJsonLinux(timeName);
-            original = JSON.parseObject(s);
-
-            if (entity.getWfsPath() == null) {
-                //保存信息
-                entity.setWfsPath(outFile);
-                entity.setUpdateTime(new DateTime());
-                outputFileRepository.save(entity);
-            }
-
-        }
-        log.warn("end wfsLike");
-        return new R(200, original);
-    }
-
-    @Override
-    public R wfsScope(Long fileId, String xMin, String yMin, String xMax, String yMax) {
-        log.warn("run wfsScope");
-
-        OutputFileEntity entity = getOutputFileEntity(fileId);
-        if (entity == null){
-            new R(50002, MsgCode.E50002);
-        }
-
-        String cmd = Command.VECTOR_WFS_SCOPE;
-        String outFile = OUTPUT_FILE_PATH + "wfs" + File.separator + entity.getDirectory();
-        FileUtils.createDir(outFile);
-        String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
-        timeName = outFile + File.separator + timeName + ".json";
-
-        // 需要坐标转换后的shp文件
-        cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
-        cmd = cmd.replace("@outputFile", timeName);
-        cmd = cmd.replace("@xMin", xMin);
-        cmd = cmd.replace("@yMin", yMin);
-        cmd = cmd.replace("@xMax", xMax);
-        cmd = cmd.replace("@yMax", yMax);
-
-        Integer integer = CmdUtil.exeCmdSingle(cmd);
-        JSONObject original = null;
-        if (integer == 0) {
-            String s = FileUtils.readJsonLinux(timeName);
-            original = JSON.parseObject(s);
-
-            if (entity.getWfsPath() == null) {
-                //保存信息
-                entity.setWfsPath(outFile);
-                entity.setUpdateTime(new DateTime());
-                outputFileRepository.save(entity);
-            }
-        }
-        log.warn("end wfsScope");
-        return new R(200, original);
-    }
-
 
     private Integer exeCmdSingle(String commandStr) {
 
@@ -819,6 +693,10 @@ public class VectorServerImpl extends BaseServerImpl implements VectorServer {
         JSONObject subJson = new JSONObject();
         long cu = System.currentTimeMillis();
         String name = "vector_" + cu;
+
+        // 新增id字段,为要素查询使用
+        subJson.put("id", entity.getId());
+
         // 需要唯一
         subJson.put("name", name);
 
@@ -919,14 +797,6 @@ public class VectorServerImpl extends BaseServerImpl implements VectorServer {
 
     }
 
-    private OutputFileEntity getOutputFileEntity(Long id) {
-        Optional<OutputFileEntity> o = outputFileRepository.findById(id);
-        if (o.isPresent()) {
-            return o.get();
-        }
-        return null;
-    }
-
 
     public static void main(String[] args) throws IOException {
 

+ 310 - 0
src/main/java/com/fd/server/impl/WfsServerImpl.java

@@ -0,0 +1,310 @@
+package com.fd.server.impl;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fd.constant.Command;
+import com.fd.constant.MsgCode;
+import com.fd.constant.TypeCode;
+import com.fd.dto.ConfigJsonDto;
+import com.fd.entity.FileEntity;
+import com.fd.entity.OutputFileEntity;
+import com.fd.entity.StyleEntity;
+import com.fd.entity.User;
+import com.fd.repository.FileRepository;
+import com.fd.repository.OutputFileRepository;
+import com.fd.repository.StyleRepository;
+import com.fd.repository.UserRepository;
+import com.fd.server.DemServer;
+import com.fd.server.WfsServer;
+import com.fd.shiro.JWTUtil;
+import com.fd.thread.AsyncTask;
+import com.fd.util.*;
+import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.PostConstruct;
+import javax.servlet.http.HttpServletRequest;
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+/**
+ * Created by Owen on 2020/01/19 0021 15:29
+ */
+@Log4j2
+@Service
+public class WfsServerImpl extends BaseServerImpl implements WfsServer {
+
+    private String INPUT_PATH;
+
+    private String OUTPUT_PATH;
+
+    @Value("${base.path}")
+    private String BASE_PATH;
+
+    // config.json 地址
+    @Value("${config.path}")
+    private String CONFIG_JSON_PATH;
+
+    @PostConstruct
+    private void init(){
+        this.INPUT_PATH = BASE_PATH  + "/input/wfs/";
+        this.OUTPUT_PATH = BASE_PATH + "/output/wfs/";
+    }
+
+
+
+    @Autowired
+    private OutputFileRepository outputFileRepository;
+
+
+
+
+
+
+    /**
+     * 精准查询
+     *
+     * @param fileId
+     * @param fileName 字段名
+     * @param value 字段值
+     * @return
+     */
+    @Override
+    public R wfsAccurate(Long fileId, String fileName, String value) {
+        log.warn("run wfsAccurate");
+
+        OutputFileEntity entity = getOutputFileEntity(fileId);
+        if (entity == null){
+            new R(50002, MsgCode.E50002);
+        }
+
+        String cmd = Command.VECTOR_WFS_ACCURATE;
+        String outFile = OUTPUT_PATH + entity.getDirectory();
+        FileUtils.createDir(outFile);
+        String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
+        timeName = outFile + File.separator + timeName + ".json";
+
+        // 需要坐标转换后的shp文件
+        cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
+        cmd = cmd.replace("@outputFile", timeName);
+        cmd = cmd.replace("@fileName", fileName);
+        cmd = cmd.replace("@value", value);
+
+        Integer integer = CmdUtil.exeCmdSingle(cmd);
+        if (integer == 0) {
+            // 返回文件地址给前端自己读文件
+            timeName = timeName.replace(BASE_PATH, "");
+            log.info("url: {}", timeName);
+
+            if (entity.getWfsPath() == null) {
+                //保存信息
+                entity.setWfsPath(outFile);
+                entity.setUpdateTime(new DateTime());
+                outputFileRepository.save(entity);
+            }
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("url", timeName);
+            log.warn("end wfsAccurate");
+            return new R(200, map);
+
+
+        }
+
+        log.warn("end wfsAccurate");
+        return new R(200, "");
+    }
+
+    @Override
+    public R wfsLike(Long fileId, String fileName, String value) {
+        log.warn("run wfsLike");
+
+        OutputFileEntity entity = getOutputFileEntity(fileId);
+        if (entity == null){
+            new R(50002, MsgCode.E50002);
+        }
+
+        String cmd = Command.VECTOR_WFS_LIKE;
+//        String outFile = OUTPUT_FILE_PATH + "wfs" + File.separator + entity.getDirectory();
+        String outFile = OUTPUT_PATH + entity.getDirectory();
+        FileUtils.createDir(outFile);
+        String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
+        timeName = outFile + File.separator + timeName + ".json";
+
+        // 需要坐标转换后的shp文件
+        cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
+        cmd = cmd.replace("@outputFile", timeName);
+        cmd = cmd.replace("@fileName", fileName);
+        cmd = cmd.replace("@value", value);
+
+        Integer integer = CmdUtil.exeCmdSingle(cmd);
+        if (integer == 0) {
+            // 返回文件地址给前端自己读文件
+            timeName = timeName.replace(BASE_PATH, "");
+            log.info("url: {}", timeName);
+
+            if (entity.getWfsPath() == null) {
+                //保存信息
+                entity.setWfsPath(outFile);
+                entity.setUpdateTime(new DateTime());
+                outputFileRepository.save(entity);
+            }
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("url", timeName);
+            log.warn("end wfsLike");
+            return new R(200, map);
+
+
+        }
+
+        log.warn("end wfsLike");
+        return new R(200, "");
+    }
+
+    @Override
+    public R wfsScope(Long fileId, String xMin, String yMin, String xMax, String yMax) {
+        log.warn("run wfsScope");
+
+        OutputFileEntity entity = getOutputFileEntity(fileId);
+        if (entity == null){
+            new R(50002, MsgCode.E50002);
+        }
+
+        String cmd = Command.VECTOR_WFS_SCOPE;
+//        String outFile = OUTPUT_FILE_PATH + "wfs" + File.separator + entity.getDirectory();
+        String outFile = OUTPUT_PATH + entity.getDirectory();
+        FileUtils.createDir(outFile);
+        String timeName = DateUtil.format(new DateTime(), "yyyyMMdd_HHmmss");
+        timeName = outFile + File.separator + timeName + ".json";
+
+        // 需要坐标转换后的shp文件
+        cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
+        cmd = cmd.replace("@outputFile", timeName);
+        cmd = cmd.replace("@xMin", xMin);
+        cmd = cmd.replace("@yMin", yMin);
+        cmd = cmd.replace("@xMax", xMax);
+        cmd = cmd.replace("@yMax", yMax);
+
+        Integer integer = CmdUtil.exeCmdSingle(cmd);
+        if (integer == 0) {
+            // 返回文件地址给前端自己读文件
+            timeName = timeName.replace(BASE_PATH, "");
+            log.info("url: {}", timeName);
+
+            if (entity.getWfsPath() == null) {
+                //保存信息
+                entity.setWfsPath(outFile);
+                entity.setUpdateTime(new DateTime());
+                outputFileRepository.save(entity);
+            }
+            HashMap<String, Object> map = new HashMap<>();
+            map.put("url", timeName);
+            log.warn("end wfsScope");
+            return new R(200, map);
+
+
+        }
+
+        log.warn("end wfsScope");
+        return new R(200, "");
+    }
+
+    @Override
+    public R getField(Long fileId) {
+        log.warn("run getField");
+
+        OutputFileEntity entity = getOutputFileEntity(fileId);
+        if (entity == null){
+            new R(50002, MsgCode.E50002);
+        }
+
+        String cmd = Command.VECTOR_WFS_FIELD;
+        cmd = cmd.replace("@inputFile", entity.getCoordStrictPath());
+        List list = cmdSubField(cmd);
+
+        log.warn("end getField");
+        return new R(200, list);
+    }
+
+
+    /**
+     * 解析获取字段
+     * @param commandStr
+     * @return
+     */
+    private static List cmdSubField(String commandStr) {
+        log.info("cmd: {}", commandStr );
+
+        // 命令运行结果 1:失败, 0:成功
+        Integer isCmd = null;
+        List<String> list = new ArrayList<>();
+        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()));
+
+
+            StringBuffer sb = new StringBuffer();
+            StringBuffer errorStr = new StringBuffer();
+
+            // 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 (RegexUtils.regexInclude(line)) {
+                    String s = StringUtils.substringBefore(line, ":");
+                    list.add(s);
+                }
+            }
+            log.info("result: {}", sb.toString());
+
+            // 结束命令行
+            isCmd = ps.waitFor();
+
+            // 关闭流
+            br.close();
+            errorBuf.close();
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        if (isCmd == 0) {
+            log.info("end exeCmd : {}", isCmd);
+            return list;
+        } else {
+            log.info("wsitFore cmd run error : {}", isCmd);
+            return null;
+        }
+    }
+
+
+
+
+
+
+}

+ 11 - 0
src/main/java/com/fd/util/RegexUtils.java

@@ -17,6 +17,17 @@ public class RegexUtils {
 
     public static final String INT_DECIMAL = "\\d*\\.?\\d+$" ;
 
+    /**  NAME: String (50.0)*/
+    public static final String INCLUDE_STR = ".*(\\(\\d*\\.\\d*\\)$)+" ;
+
+    /**  NAME: String (50.0) */
+    public static boolean regexInclude(String param){
+        if(StringUtils.isEmpty(param)){
+            return Boolean.FALSE ;
+        }
+        return param.matches(INCLUDE_STR) ;
+    }
+
 
     /**  匹配中文 */
     public static boolean regexChinese(String param){