Files
yjearth/src/main/java/com/yj/earth/business/controller/GdalController.java

48 lines
1.9 KiB
Java
Raw Normal View History

2025-09-29 13:56:36 +08:00
package com.yj.earth.business.controller;
2025-10-09 11:03:15 +08:00
import com.yj.earth.common.util.GdalJsonConverter;
2025-09-29 13:56:36 +08:00
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数据
2025-10-09 11:03:15 +08:00
String jsonData = GdalJsonConverter.convertToJson(path);
2025-09-29 13:56:36 +08:00
// 设置响应头
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();
}
}
}