| | |
| | | package com.se.nsl.controller; |
| | | |
| | | import com.se.nsl.domain.po.DataPo; |
| | | import com.se.nsl.domain.po.Region; |
| | | import com.se.nsl.domain.vo.R; |
| | | import com.se.nsl.helper.GdalHelper; |
| | | import com.se.nsl.helper.ShpHelper; |
| | | import com.se.nsl.helper.StringHelper; |
| | | import com.se.nsl.mapper.RegionMapper; |
| | | import com.se.nsl.service.*; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.ogr.*; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.StandardCopyOption; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Api(tags = "Test") |
| | | @Slf4j |
| | |
| | | UwService uwService; |
| | | |
| | | @Resource |
| | | TestService testService; |
| | | |
| | | @Resource |
| | | GedbService gedbService; |
| | | |
| | | @Resource |
| | | SimuService simuService; |
| | | SimuPoService simuPoService; |
| | | |
| | | @Resource |
| | | Hdf5Service hdf5Service; |
| | | |
| | | @Resource |
| | | ResultService resultService; |
| | | |
| | | @Resource |
| | | RegionMapper regionMapper; |
| | | |
| | | @ApiOperation(value = "当前时间 *") |
| | | @GetMapping("/getTime") |
| | |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "testNsl <") |
| | | @GetMapping("/testNsl") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "inPath", value = "输入路径", dataType = "String", paramType = "query", example = "20250412"), |
| | | @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "Integer", paramType = "query", example = "2025-04-12 00:00:00"), |
| | | @ApiImplicitParam(name = "epsg", value = "坐标系ID", dataType = "Integer", paramType = "query", example = "4548") |
| | | }) |
| | | public R<Object> testNsl(String inPath, String startTime, Integer epsg) { |
| | | try { |
| | | DataPo data = new DataPo(); |
| | | data.setInPath(inPath); |
| | | data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(startTime)); |
| | | data.setEpsg(epsg); |
| | | |
| | | testService.test(data); |
| | | |
| | | return success("ok"); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "insertRegion <") |
| | | @GetMapping("/insertRegion") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "fileName", value = "文件名", dataType = "String", paramType = "query", example = "5.beijing.geoJson"), |
| | | @ApiImplicitParam(name = "type", value = "类型", dataType = "Integer", paramType = "query", example = "1") |
| | | }) |
| | | public R<Object> insertRegion(String fileName, Integer type) { |
| | | return insertNsl(fileName, type); |
| | | } |
| | | |
| | | private R<Object> insertNsl(String fileName, Integer type) { |
| | | // 孙胡沟geometry.json,7.nsl_area.geojson,4.10000.geoJson,5.beijing.geoJson |
| | | String path = "D:\\terrait\\NslServer\\data\\" + fileName; |
| | | if (!new File(path).exists()) return fail(path + ",文件不存在", null); |
| | | |
| | | org.gdal.ogr.Driver driver = ogr.GetDriverByName("GeoJSON"); |
| | | if (null == driver) return fail("null"); |
| | | DataSource ds = driver.Open(path); |
| | | if (null == ds) return fail("null"); |
| | | |
| | | List<Region> list = new ArrayList<>(); |
| | | for (int i = 0, c = ds.GetLayerCount(); i < c; i++) { |
| | | Layer layer = ds.GetLayer(i); |
| | | for (long j = 0, d = layer.GetFeatureCount(); j <= d; j++) { |
| | | Feature f = layer.GetFeature(j); |
| | | if (null == f || null == f.GetGeometryRef()) continue; |
| | | |
| | | String wkt = f.GetGeometryRef().ExportToWkt().toUpperCase(); |
| | | if (!wkt.contains("POLYGON")) |
| | | continue; // g.GetGeometryType() == ogr.wkbPolygon || g.GetGeometryType() == ogr.wkbMultiPolygon |
| | | |
| | | if (!wkt.contains("MULTIPOLYGON")) wkt = wkt.replace("POLYGON (", "MULTIPOLYGON ((") + ")"; |
| | | list.add(new Region(f.GetFieldAsString("name"), type.shortValue(), wkt)); |
| | | if (path.contains("孙胡沟")) list.add(new Region(f.GetFieldAsString("name"), (short) 3, wkt)); |
| | | } |
| | | } |
| | | ds.delete(); |
| | | driver.delete(); |
| | | |
| | | return success(list.size() > 0 ? regionMapper.inserts(list) : 0); |
| | | } |
| | | |
| | | @ApiOperation(value = "testDepthFiles <") |
| | | @GetMapping("/testDepthFiles") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "oldPath", value = "输入路径", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago"), |
| | | @ApiImplicitParam(name = "newPath", value = "开始时间", dataType = "Integer", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago\\depth"), |
| | | @ApiImplicitParam(name = "year", value = "年", dataType = "Integer", paramType = "query", example = "2025"), |
| | | @ApiImplicitParam(name = "month", value = "月", dataType = "Integer", paramType = "query", example = "4"), |
| | | @ApiImplicitParam(name = "day", value = "日", dataType = "Integer", paramType = "query", example = "21") |
| | | }) |
| | | public R<Object> testDepthFiles(String oldPath, String newPath, Integer year, Integer month, Integer day) { |
| | | try { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(new Date(year - 1900, month - 1, day, 0, 0, 0)); |
| | | SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | |
| | | for (File file : new File(oldPath).listFiles()) { |
| | | if (!file.exists() || !file.isDirectory()) continue; |
| | | |
| | | File tif = new File(oldPath + "\\" + file.getName() + "\\depth.tif"); |
| | | if (!tif.exists() || tif.isDirectory()) continue; |
| | | |
| | | /*int second = Integer.parseInt(fileName); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR, 0); |
| | | calendar.add(Calendar.SECOND, second);*/ |
| | | calendar.add(Calendar.SECOND, 1); |
| | | String newName = df.format(calendar.getTime()); |
| | | String newFile = newPath + File.separator + newName + ".tif"; |
| | | |
| | | System.out.println(newFile); |
| | | tif.renameTo(new File(newFile)); |
| | | file.delete(); |
| | | } |
| | | |
| | | return success("ok"); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "testTifFiles <") |
| | | @GetMapping("/testTifFiles") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "oldPath", value = "输入路径", dataType = "String", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago\\depth"), |
| | | @ApiImplicitParam(name = "newPath", value = "开始时间", dataType = "Integer", paramType = "query", example = "D:\\other\\simu\\uwsolver\\chicago\\depth2"), |
| | | @ApiImplicitParam(name = "step", value = "步长", dataType = "Integer", paramType = "query", example = "20") |
| | | }) |
| | | public R<Object> testTifFiles(String oldPath, String newPath, Integer step) { |
| | | try { |
| | | File[] files = new File(oldPath).listFiles(); |
| | | for (int i = 0, c = files.length; i < c; i += step) { |
| | | File file = files[i]; |
| | | if (!file.exists() || !file.isFile() || !file.getName().endsWith(".tif")) continue; |
| | | |
| | | String newFile = newPath + File.separator + file.getName(); |
| | | |
| | | System.out.println(newFile); |
| | | file.renameTo(new File(newFile)); |
| | | //Files.copy(file.toPath(), Paths.get(newFile), StandardCopyOption.REPLACE_EXISTING); |
| | | file.delete(); |
| | | } |
| | | |
| | | return success("ok"); |
| | | } catch (Exception ex) { |
| | | return fail(ex, null); |
| | | } |
| | | } |
| | | } |