From 03d4fc607b5df795a4319120036ef138cde70896 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 19 九月 2023 20:00:23 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/controller/data/PublishController.java | 16 ++++++++ src/main/java/com/lf/server/entity/all/StaticData.java | 2 + src/main/java/com/lf/server/service/data/RasterService.java | 45 ++++++++++++++++++++++ 3 files changed, 63 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/lf/server/controller/data/PublishController.java b/src/main/java/com/lf/server/controller/data/PublishController.java index 324c94d..283780f 100644 --- a/src/main/java/com/lf/server/controller/data/PublishController.java +++ b/src/main/java/com/lf/server/controller/data/PublishController.java @@ -294,6 +294,22 @@ } @SysLog() + @ApiOperation(value = "鏌ヨ鍧愭爣杞崲") + @ApiImplicitParams({ + @ApiImplicitParam(name = "x", value = "X鍧愭爣", dataType = "double", paramType = "query", example = "40476573.02"), + @ApiImplicitParam(name = "y", value = "Y鍧愭爣", dataType = "double", paramType = "query", example = "3391108.90"), + @ApiImplicitParam(name = "epsg", value = "EPSG缂栫爜", dataType = "int", paramType = "query", example = "4528") + }) + @GetMapping(value = "/selectCsTransform") + public Object selectCsTransform(double x, double y, int epsg) { + try { + return rasterService.csTransform(x, y, epsg); + } catch (Exception ex) { + return null; + } + } + + @SysLog() @ApiOperation(value = "鎻掑叆鍙戝竷鏁版嵁") @ApiImplicitParams({ @ApiImplicitParam(name = "entity", value = "瀹炰綋绫�", dataType = "PubEntity", paramType = "body") diff --git a/src/main/java/com/lf/server/entity/all/StaticData.java b/src/main/java/com/lf/server/entity/all/StaticData.java index 02e7cfc..a24464a 100644 --- a/src/main/java/com/lf/server/entity/all/StaticData.java +++ b/src/main/java/com/lf/server/entity/all/StaticData.java @@ -156,6 +156,8 @@ public final static String COMPOUNDCURVE = "COMPOUNDCURVE"; + public final static String CGCS2000 = "CGCS2000"; + public static final String NO_FILE = JSON.toJSONString(new ResponseMsg<String>(HttpStatus.NOT_FOUND, "鏂囦欢鎵句笉鍒�")); /** diff --git a/src/main/java/com/lf/server/service/data/RasterService.java b/src/main/java/com/lf/server/service/data/RasterService.java index b5117d7..72cb5c5 100644 --- a/src/main/java/com/lf/server/service/data/RasterService.java +++ b/src/main/java/com/lf/server/service/data/RasterService.java @@ -1,11 +1,15 @@ package com.lf.server.service.data; +import com.lf.server.entity.all.StaticData; import com.lf.server.helper.StringHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.gdal.gdal.Dataset; import org.gdal.gdal.gdal; import org.gdal.gdalconst.gdalconst; +import org.gdal.ogr.Geometry; +import org.gdal.ogr.ogr; +import org.gdal.osr.SpatialReference; import org.springframework.stereotype.Service; import java.io.File; @@ -17,7 +21,25 @@ */ @Service public class RasterService { + private SpatialReference sr4326; + + private SpatialReference sr4490; + private final static Log log = LogFactory.getLog(RasterService.class); + + /** + * 鍒濆鍖栫┖闂村弬鑰� + */ + public void initSr() { + if (null == sr4326) { + sr4326 = new SpatialReference(); + sr4326.ImportFromEPSG(StaticData.I4326); + } + if (null == sr4490) { + sr4490 = new SpatialReference(); + sr4490.ImportFromEPSG(StaticData.I4490); + } + } /** * 鑾峰彇鏍呮牸鏁版嵁鐨凟PSG缂栫爜 @@ -55,4 +77,27 @@ } } } + + /** + * 鏌ヨ鍧愭爣杞崲 + */ + public Object csTransform(double x, double y, int epsg) { + this.initSr(); + + SpatialReference srs = new SpatialReference(); + srs.ImportFromEPSG(epsg); + + Geometry point = new Geometry(ogr.wkbPoint); + point.AddPoint(x, y, 0); + point.AssignSpatialReference(srs); + + if (srs.GetName().contains(StaticData.CGCS2000)) { + point.TransformTo(sr4490); + } else { + point.TransformTo(sr4326); + } + point.SwapXY(); + + return new double[]{point.GetX(), point.GetY()}; + } } -- Gitblit v1.9.3