模型库、矢量文件
This commit is contained in:
@ -0,0 +1,47 @@
|
||||
package com.yj.earth.business.controller;
|
||||
|
||||
import com.yj.earth.common.util.GdalUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@Tag(name = "矢量数据管理")
|
||||
@RestController
|
||||
@RequestMapping("/gdal")
|
||||
public class GdalController {
|
||||
|
||||
@Operation(summary = "导入矢量数据")
|
||||
@PostMapping("/import")
|
||||
public void importDataStreamGzip(@Parameter(description = "矢量文件路径", required = true) @RequestParam("path") String path, HttpServletResponse response) throws IOException {
|
||||
|
||||
// 解析矢量文件、得到JSON数据
|
||||
String jsonData = GdalUtil.readVectorToJson(path);
|
||||
|
||||
// 设置响应头
|
||||
String filename = URLEncoder.encode("data.gz", StandardCharsets.UTF_8);
|
||||
response.setContentType("application/gzip");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
|
||||
// 使用GZIP压缩并输出
|
||||
try (OutputStream outputStream = response.getOutputStream();
|
||||
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream)) {
|
||||
gzipOutputStream.write(jsonData.getBytes(StandardCharsets.UTF_8));
|
||||
gzipOutputStream.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user