Pārlūkot izejas kodu

完成了raster 模块

wuweihao 5 gadi atpakaļ
vecāks
revīzija
c7e126da32

+ 12 - 0
README.md

@@ -0,0 +1,12 @@
+#git_cesium
+
+
+
+##测试服务器
+    四维内网:
+    192.168.0.248
+    
+    /root/java/apache-tomcat-8.5.47_8082_cesium
+    
+    
+linux 命令不会自动创建目录,云行是记得检查目录是否创建

+ 8 - 0
pom.xml

@@ -21,6 +21,7 @@
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
         <maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
         <swagger2.version>2.9.2</swagger2.version>
+        <lang3.version>3.7</lang3.version>
     </properties>
 
     <dependencies>
@@ -62,6 +63,13 @@
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
         </dependency>
+
+        <!--StringUtils -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>${lang3.version}</version>
+        </dependency>
     </dependencies>
 
     <build>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 33 - 0
src/main/java/com/fd/constant/Command.java


+ 34 - 0
src/main/java/com/fd/controller/RasterController.java

@@ -1,11 +1,15 @@
 package com.fd.controller;
 
+import com.fd.constant.Command;
 import com.fd.constant.TypeCode;
 import com.fd.dto.PageDto;
+import com.fd.entity.FileEntity;
+import com.fd.server.CmdServer;
 import com.fd.server.FileServer;
 import com.fd.util.R;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -23,6 +27,9 @@ public class RasterController {
     @Autowired
     private FileServer fileServer;
 
+    @Autowired
+    private CmdServer cmdServer;
+
 
     @ApiOperation("上传栅格数据")
     @PostMapping(value = "upload", consumes = { "multipart/form-data" })
@@ -48,4 +55,31 @@ public class RasterController {
         log.info("run deleteFile: {}", fileId);
         return fileServer.deleteById(fileId);
     }
+
+    @ApiOperation("栅格数据切片命令")
+    @GetMapping("command/osgeo/{fileId}/")
+    private R cmdOsgeo(@PathVariable("fileId") Long fileId) {
+        log.info("run cmdOsgeo: {}", fileId);
+        FileEntity entity = fileServer.findById(fileId);
+
+        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
+
+        String cmd = Command.RASTER_OSGEO;
+        cmd = cmd.replace("@fileName",fileName);
+        log.info("cmd: {}", cmd);
+
+        return cmdServer.exeCmd(cmd);
+    }
+
+
+    private String getPrefix() {
+        return null;
+    }
+
+    public static void main(String[] args) {
+        String a = "112222.aa";
+        System.out.println(StringUtils.stripStart(a,"."));
+        System.out.println(StringUtils.substringAfter(a,"."));
+        System.out.println(StringUtils.substringBefore(a,"."));
+    }
 }

+ 55 - 1
src/main/java/com/fd/controller/TranslationController.java

@@ -1,6 +1,16 @@
 package com.fd.controller;
 
+import com.fd.constant.Command;
+import com.fd.entity.FileEntity;
+import com.fd.server.CmdServer;
+import com.fd.server.FileServer;
+import com.fd.util.R;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -10,7 +20,51 @@ import org.springframework.web.bind.annotation.RestController;
  * 坐标转换
  */
 @Log4j2
-@RequestMapping
+@RequestMapping("api/transform")
 @RestController
 public class TranslationController {
+
+
+    @Autowired
+    private FileServer fileServer;
+
+    @Autowired
+    private CmdServer cmdServer;
+
+
+    @ApiOperation("栅格数据普通坐标转换")
+    @GetMapping("command/raster/gdalwarp/{fileId}/")
+    private R cmdRasterGdalwarp(@PathVariable("fileId") Long fileId) {
+        log.info("run cmdRasterGdalwarp: {}", fileId);
+        FileEntity entity = fileServer.findById(fileId);
+
+        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
+
+        String cmd = Command.RASTER_GDALWARP;
+        cmd = cmd.replace("@fileName",fileName);
+        log.info("cmd: {}", cmd);
+
+        return cmdServer.exeCmd(cmd);
+    }
+
+
+    @ApiOperation("栅格数据严格坐标转换")
+    @GetMapping("command/raster/gdalwarp/strict/{fileId}/")
+    private R cmdRasterGdalwarpStrict(@PathVariable("fileId") Long fileId) {
+        log.info("run cmdRasterGdalwarpStrict: {}", fileId);
+        FileEntity entity = fileServer.findById(fileId);
+
+        String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
+
+        String step_1 = Command.RASTER_GDALWARP_STRICT_1;
+        String step_2 = Command.RASTER_GDALWARP_STRICT_2;
+        step_1 = step_1.replace("@fileName",fileName);
+        step_2 = step_2.replace("@fileName",fileName);
+        log.info("cmd1: {}", step_1);
+        log.info("cmd2: {}", step_2);
+
+        return cmdServer.exeCmd(step_1, step_2);
+    }
+
+
 }

+ 17 - 0
src/main/java/com/fd/server/CmdServer.java

@@ -0,0 +1,17 @@
+package com.fd.server;
+
+
+import com.fd.util.R;
+
+/**
+ * Created by Owen on 2019/10/30 0030 17:16
+ */
+public interface CmdServer {
+
+    R exeCmd(String commandStr);
+
+    R exeCmd(String cmd1, String cmd2);
+
+    R exeCmd(String commandStr, Long id);
+
+}

+ 3 - 0
src/main/java/com/fd/server/FileServer.java

@@ -1,6 +1,7 @@
 package com.fd.server;
 
 import com.fd.dto.PageDto;
+import com.fd.entity.FileEntity;
 import com.fd.util.R;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -22,4 +23,6 @@ public interface FileServer {
     R deleteById(Long fileId);
 
     R getGeoData(HttpServletResponse response, String filePath);
+
+    FileEntity findById(Long fileId);
 }

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

@@ -0,0 +1,136 @@
+package com.fd.server.impl;
+
+import com.fd.constant.MsgCode;
+import com.fd.server.CmdServer;
+import com.fd.util.R;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.stereotype.Service;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+/**
+ * Created by Owen on 2019/11/14 0014 15:33
+ */
+@Log4j2
+@Service
+public class CmdServerImpl implements CmdServer {
+
+
+
+    @Override
+    public R exeCmd(String commandStr) {
+        Integer isCmd = exeCmdSingle(commandStr);
+//        Integer isCmd = null; // 命令运行结果 1:失败, 0:成功
+//        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");
+//            }
+//            log.info("error result: {}", errorStr.toString());
+//
+//            // success ,没有获取到信息
+//            String line;
+//            while ((line = br.readLine()) != null) {
+////                log.info("=====  br.readLine: ======== {}", br.readLine());
+//                //执行结果加上回车
+//                sb.append(line).append("\n");
+//            }
+//            log.info("result: {}", sb.toString());
+//
+//            // 结束命令行
+//            isCmd = ps.waitFor();
+//
+//            // 关闭流
+//            br.close();
+//            errorBuf.close();
+//
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+
+        if (isCmd == 0) {
+            return new R(200, MsgCode.SUCCESS);
+        } else {
+            return new R(200, MsgCode.E50005);
+        }
+    }
+
+    // 复杂坐标转换
+    @Override
+    public R exeCmd(String cmd1, String cmd2) {
+
+        exeCmdSingle(cmd1);
+        Integer isCmd = exeCmdSingle(cmd2);
+        if (isCmd == 0) {
+            return new R(200, MsgCode.SUCCESS);
+        } else {
+            return new R(200, MsgCode.E50005);
+        }
+    }
+
+    @Override
+    public R exeCmd(String commandStr, Long id) {
+        return null;
+    }
+
+
+
+    private Integer exeCmdSingle(String commandStr) {
+
+        Integer isCmd = null; // 命令运行结果 1:失败, 0:成功
+        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");
+            }
+            log.info("error result: {}", errorStr.toString());
+
+            // success ,没有获取到信息
+            String line;
+            while ((line = br.readLine()) != null) {
+//                log.info("=====  br.readLine: ======== {}", br.readLine());
+                //执行结果加上回车
+                sb.append(line).append("\n");
+            }
+            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);
+        } else {
+            log.info("wsitFore cmd run error : {}", isCmd);
+        }
+        return isCmd;
+    }
+}

+ 14 - 0
src/main/java/com/fd/server/impl/FileServerImpl.java

@@ -78,6 +78,7 @@ public class FileServerImpl implements FileServer {
         entity.setType(type);
         fileRepository.save(entity);
 
+        log.info("end uploadBigFile");
         return new R(200, entity);
     }
 
@@ -119,6 +120,7 @@ public class FileServerImpl implements FileServer {
         entity.setType(type);
         fileRepository.save(entity);
 
+        log.info("end uploadBigFile");
         return new R(200, entity);
     }
 
@@ -172,4 +174,16 @@ public class FileServerImpl implements FileServer {
         // 文件下载,不能有返回值
         return null;
     }
+
+    @Override
+    public FileEntity findById(Long fileId) {
+        Optional<FileEntity> o = fileRepository.findById(fileId);
+        if (!o.isPresent()) {
+            log.info("id:{} 不存在");
+            return null;
+        }
+
+        FileEntity entity = o.get();
+        return entity;
+    }
 }

+ 10 - 0
src/main/resources/application-dev.properties

@@ -0,0 +1,10 @@
+#DB
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://localhost:3306/gis_cesium?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+spring.datasource.username=root
+spring.datasource.password=123456
+
+logging.file=log/cesium.log
+
+input.file.path=F:\\test\\cesium\\input\\
+output.file.path=F:\\test\\cesium\\output\\

+ 11 - 0
src/main/resources/application-pro.properties

@@ -0,0 +1,11 @@
+
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+spring.datasource.url=jdbc:mysql://192.168.0.248:3306/gis_cesium?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8
+spring.datasource.username=root
+spring.datasource.password=4dage
+
+logging.file=/root/java/apache-tomcat-8.5.47_8082_cesium/log/cesium.log
+
+input.file.path=/root/gis/cesium/input/
+output.file.path=/root/gis/cesium/output/
+

+ 12 - 0
src/main/resources/application.properties

@@ -0,0 +1,12 @@
+server.port=8083
+
+# file multipart
+spring.profiles.active=pro
+spring.servlet.multipart.enabled=true
+spring.servlet.multipart.max-file-size=51200MB
+spring.servlet.multipart.max-request-size=51200MB
+
+#jpa
+spring.jpa.hibernate.ddl-auto=update
+spring.jpa.hibernate.naming.implicit-strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
+