|
@@ -7,6 +7,7 @@ import com.fd.dto.PageDto;
|
|
|
import com.fd.entity.FileEntity;
|
|
|
import com.fd.server.CmdServer;
|
|
|
import com.fd.server.FileServer;
|
|
|
+import com.fd.server.VectorServer;
|
|
|
import com.fd.util.FileUtils;
|
|
|
import com.fd.util.R;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -40,17 +41,95 @@ public class VectorController {
|
|
|
private FileServer fileServer;
|
|
|
|
|
|
@Autowired
|
|
|
+ private VectorServer vectorServer;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private CmdServer cmdServer;
|
|
|
|
|
|
|
|
|
|
|
|
- @ApiOperation("上传矢量数据")
|
|
|
- @PostMapping(value = "upload/{directoryName}/", consumes = { "multipart/form-data" })
|
|
|
- private R upload(@RequestParam("file") MultipartFile file, @PathVariable("directoryName") String directoryName){
|
|
|
+// @ApiOperation("上传矢量数据,coord:坐标, directoryName:目录名称")
|
|
|
+// @PostMapping(value = "upload/{directoryName}/", consumes = { "multipart/form-data" })
|
|
|
+// private R upload(@RequestParam("file") MultipartFile file, @PathVariable("directoryName") String directoryName,
|
|
|
+// @RequestParam(value = "coord",required = false) String coord){
|
|
|
+// log.info("run upload");
|
|
|
+// return fileServer.uploadFile(file, directoryName, TypeCode.FILE_TYPE_VECTOR);
|
|
|
+// }
|
|
|
+
|
|
|
+ @ApiOperation("上传矢量数据,只能上传zip文件,里面的文件名必须跟压缩包一致, coord:坐标(可以为空), 坐标格式:0,0,0,0,0,0,0")
|
|
|
+ @PostMapping(value = "upload", consumes = { "multipart/form-data" })
|
|
|
+ private R upload(@RequestParam("file") MultipartFile file,
|
|
|
+ @RequestParam(value = "coord",required = false) String coord){
|
|
|
log.info("run upload");
|
|
|
- return fileServer.uploadFile(file, directoryName, TypeCode.FILE_TYPE_VECTOR);
|
|
|
+
|
|
|
+ // 文件名全名
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ String s = StringUtils.substringAfterLast(fileName, ".");
|
|
|
+
|
|
|
+ if (!"zip".equals(s)) {
|
|
|
+ return new R(50007,MsgCode.E50007);
|
|
|
+ }
|
|
|
+
|
|
|
+ return vectorServer.uploadFile(file, coord);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @ApiOperation("解压zip文件")
|
|
|
+ @GetMapping("unzip/{fileId}/")
|
|
|
+ private R fileUnzip(@PathVariable("fileId") Long fileId) {
|
|
|
+ log.info("run fileUnzip: {}", fileId);
|
|
|
+ FileEntity entity = fileServer.findById(fileId);
|
|
|
+
|
|
|
+ boolean unzip = FileUtils.unzip(entity.getFileUrl(), INPUT_FILE_PATH);
|
|
|
+
|
|
|
+ if (!unzip) {
|
|
|
+ return new R(50006, MsgCode.E50006);
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
+
|
|
|
+ FileEntity fileEntity = new FileEntity();
|
|
|
+
|
|
|
+ // 添加文件夹到数据库
|
|
|
+ fileEntity.setFileName(fileName);
|
|
|
+ fileEntity.setFileUrl(INPUT_FILE_PATH + fileName);
|
|
|
+ fileEntity.setCreateTime(new Date());
|
|
|
+ fileEntity.setUpdateTime(new Date());
|
|
|
+ fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+ fileEntity.setCoord(entity.getCoord());
|
|
|
+ fileEntity = fileServer.save(fileEntity);
|
|
|
+
|
|
|
+ // xxx.shp到数据库
|
|
|
+// String sName = StringUtils.substringAfter(fileName, "_");
|
|
|
+// sName = sName + ".shp";
|
|
|
+ fileEntity = new FileEntity();
|
|
|
+// fileEntity.setFileName(sName);
|
|
|
+// fileEntity.setFileUrl(INPUT_FILE_PATH + fileName + File.separator + sName);
|
|
|
+
|
|
|
+ fileEntity.setFileName(fileName + ".shp");
|
|
|
+ fileEntity.setFileUrl(INPUT_FILE_PATH + fileName + File.separator + fileName + ".shp");
|
|
|
+
|
|
|
+ fileEntity.setCreateTime(new Date());
|
|
|
+ fileEntity.setUpdateTime(new Date());
|
|
|
+ fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+ fileEntity.setCoord(entity.getCoord());
|
|
|
+ fileEntity = fileServer.save(fileEntity);
|
|
|
+
|
|
|
+ return new R(200, fileEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// @ApiOperation("test")
|
|
|
+// @PostMapping(value = "test/{directoryName}/", consumes = { "multipart/form-data" })
|
|
|
+// private R test(@RequestParam("file") MultipartFile file, @PathVariable("directoryName") String directoryName, @RequestParam(value = "str",required = false) String str){
|
|
|
+// log.info("run upload");
|
|
|
+// log.info("directoryName: {}", directoryName);
|
|
|
+// log.info("str: {}", str);
|
|
|
+// return new R(200, "123");
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@ApiOperation("获取矢量数据列表")
|
|
|
@PostMapping(value = "list")
|
|
|
private R list(@RequestBody PageDto param){
|
|
@@ -70,6 +149,9 @@ public class VectorController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
// @ApiOperation("矢量数据判断坐标")
|
|
|
// @GetMapping("command/judge/coord/{fileId}/")
|
|
|
// private R cmdJudgeCoord(@PathVariable("fileId") Long fileId) {
|
|
@@ -98,6 +180,8 @@ public class VectorController {
|
|
|
private R cmdJudgeCoord(@PathVariable("fileId") Long fileId) {
|
|
|
log.info("run cmdJudgeCoord: {}", fileId);
|
|
|
FileEntity entity = fileServer.findById(fileId);
|
|
|
+ String coord = entity.getCoord();
|
|
|
+ log.info("coord: {}", coord);
|
|
|
|
|
|
// 判断是否需要坐标转换
|
|
|
String cmd = Command.VECTOR_JUDGE_COORD;
|
|
@@ -109,33 +193,22 @@ public class VectorController {
|
|
|
FileEntity fileEntity = null;
|
|
|
// 转换坐标 普通坐标转换
|
|
|
if (isJudge == 1000){
|
|
|
- log.info("need to transform");
|
|
|
-
|
|
|
- String fileName = StringUtils.substringBefore(entity.getFileName(), ".");
|
|
|
- // 截取目录名称
|
|
|
- String fileUrl = entity.getFileUrl();
|
|
|
- String directoryName = StringUtils.substring(fileUrl, fileUrl.indexOf("input/") + 6, fileUrl.lastIndexOf("/"));
|
|
|
- cmd = Command.VECTOR_TRANSFORM_OGR2OGR;
|
|
|
- cmd = cmd.replace("@fileName", fileName);
|
|
|
- cmd = cmd.replace("@directory", directoryName);
|
|
|
- log.info("cmd: {}", cmd);
|
|
|
-
|
|
|
- // 创建个目录,用来存转换后的文件,目录以文件名命名
|
|
|
- String directoryPath = INPUT_FILE_PATH + "transform" + File.separator + directoryName;
|
|
|
- FileUtils.createDir(directoryPath);
|
|
|
-
|
|
|
- Integer integer = cmdServer.exeCmdInt(cmd);
|
|
|
- if (integer != 0) {
|
|
|
- return new R(50005, MsgCode.E50005);
|
|
|
+ // 普通坐标转换
|
|
|
+ log.info("need to general transform");
|
|
|
+ if (coord == null) {
|
|
|
+ // 没有坐标参数,执行普通坐标转换(ogrinfo)
|
|
|
+ fileEntity = generalCoordTransform(entity, Command.VECTOR_TRANSFORM_GENERAL);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 有坐标参数,执行严格坐标转换(CGCS2000转wgs80)
|
|
|
+ fileEntity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS80);
|
|
|
}
|
|
|
|
|
|
- fileEntity = new FileEntity();
|
|
|
- fileEntity.setFileName(entity.getFileName());
|
|
|
- fileEntity.setFileUrl(directoryPath + File.separator + entity.getFileName());
|
|
|
- fileEntity.setCreateTime(new Date());
|
|
|
- fileEntity.setUpdateTime(new Date());
|
|
|
- fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
- fileEntity = fileServer.save(fileEntity);
|
|
|
+ } else if (isJudge == 1001 && coord != null) {
|
|
|
+ // 严格坐标转换 (西安80转wgs84),需要参数
|
|
|
+ log.info("need to strict transform");
|
|
|
+ fileEntity = strictCoordTransform(entity, Command.VECTOR_TRANSFORM_STRICT_WGS84);
|
|
|
+
|
|
|
} else if (0 == isJudge){ // 不转换坐标
|
|
|
log.info("not to transform");
|
|
|
fileEntity = entity;
|
|
@@ -213,4 +286,60 @@ public class VectorController {
|
|
|
|
|
|
return new R(200, fileEntity);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // 普通坐标转换
|
|
|
+ private FileEntity generalCoordTransform(FileEntity entity, String cmd){
|
|
|
+
|
|
|
+ String directory = createDirectory(entity);
|
|
|
+ directory = directory + File.separator + entity.getFileName();
|
|
|
+
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getFileUrl());
|
|
|
+ cmd = cmd.replace("@outputFile", directory);
|
|
|
+ log.info("cmd: {}", cmd);
|
|
|
+ return runCmd(cmd, entity, directory);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 严格坐标转换
|
|
|
+ private FileEntity strictCoordTransform(FileEntity entity, String cmd){
|
|
|
+
|
|
|
+ String directory = createDirectory(entity);
|
|
|
+ directory = directory + File.separator + entity.getFileName();
|
|
|
+
|
|
|
+ cmd = cmd.replace("@coord", entity.getCoord());
|
|
|
+ cmd = cmd.replace("@inputFile", entity.getFileUrl());
|
|
|
+ cmd = cmd.replace("@outputFile", directory);
|
|
|
+ log.info("cmd: {}", cmd);
|
|
|
+
|
|
|
+ return runCmd(cmd, entity, directory);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建目录
|
|
|
+ private String createDirectory(FileEntity entity){
|
|
|
+ String fileName = StringUtils.substringBeforeLast(entity.getFileName(), ".");
|
|
|
+ String directory = INPUT_FILE_PATH + "transform" + File.separator + fileName;
|
|
|
+ FileUtils.createDir(directory);
|
|
|
+ return directory;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行命令,创建对象
|
|
|
+ private FileEntity runCmd(String cmd, FileEntity entity, String filePath){
|
|
|
+ Integer integer = cmdServer.exeCmdInt(cmd);
|
|
|
+ if (integer != 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ FileEntity fileEntity = new FileEntity();
|
|
|
+ fileEntity.setFileName(entity.getFileName());
|
|
|
+ fileEntity.setFileUrl(filePath);
|
|
|
+ fileEntity.setCreateTime(new Date());
|
|
|
+ fileEntity.setUpdateTime(new Date());
|
|
|
+ fileEntity.setType(TypeCode.FILE_TYPE_VECTOR);
|
|
|
+ fileEntity = fileServer.save(fileEntity);
|
|
|
+ return fileEntity;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|