| | |
| | | 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.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Api(tags = "Test") |
| | | @Slf4j |
| | |
| | | |
| | | @Resource |
| | | ResultService resultService; |
| | | |
| | | @Resource |
| | | RegionMapper regionMapper; |
| | | |
| | | @ApiOperation(value = "当前时间 *") |
| | | @GetMapping("/getTime") |
| | |
| | | |
| | | @ApiOperation(value = "testNsl *") |
| | | @GetMapping("/testNsl") |
| | | public R<Object> 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 = "type", value = "坐标系ID", dataType = "Integer", paramType = "query", example = "4548") |
| | | }) |
| | | public R<Object> testNsl(String inPath, String startTime, Integer epsg) { |
| | | try { |
| | | DataPo data = new DataPo(); |
| | | data.setEpsg(4548); |
| | | data.setInPath("20250412"); |
| | | data.setStartTime(StringHelper.YMDHMS_FORMAT.parse("2025-04-12 00:00:00")); |
| | | data.setInPath(inPath); |
| | | data.setStartTime(StringHelper.YMDHMS_FORMAT.parse(startTime)); |
| | | data.setEpsg(epsg); |
| | | |
| | | testService.test(data); |
| | | |
| | |
| | | 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); |
| | | } |
| | | } |