From 8300bfcfd58e84d27163ba94b8e026cfcf4f90a6 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期六, 16 九月 2023 08:37:48 +0800 Subject: [PATCH] 添加坐标系初始化 --- src/main/java/com/moon/server/service/data/ReadRasterService.java | 28 +++------------------------- src/main/java/com/moon/server/helper/GeoHelper.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/moon/server/helper/GeoHelper.java b/src/main/java/com/moon/server/helper/GeoHelper.java index 20ac8da..3af89e1 100644 --- a/src/main/java/com/moon/server/helper/GeoHelper.java +++ b/src/main/java/com/moon/server/helper/GeoHelper.java @@ -17,6 +17,10 @@ * @date 2023-09-14 */ public class GeoHelper { + public static SpatialReference sr4326; + + public static SpatialReference sr4490; + public static SpatialReference sr104903; public final static double MOON_RADIUS = 1738000; @@ -30,6 +34,12 @@ */ public static void initSr() { try { + sr4326 = new SpatialReference(); + sr4326.ImportFromEPSG(StaticData.I4326); + + sr4490 = new SpatialReference(); + sr4490.ImportFromEPSG(StaticData.I4490); + sr104903 = new SpatialReference(StaticData.MOON_2000_WKT); crs104903 = CRS.parseWKT(StaticData.MOON_2000_WKT); diff --git a/src/main/java/com/moon/server/service/data/ReadRasterService.java b/src/main/java/com/moon/server/service/data/ReadRasterService.java index 2f1ffaf..c88a932 100644 --- a/src/main/java/com/moon/server/service/data/ReadRasterService.java +++ b/src/main/java/com/moon/server/service/data/ReadRasterService.java @@ -2,6 +2,7 @@ import com.moon.server.entity.all.StaticData; import com.moon.server.entity.data.MetaFileEntity; +import com.moon.server.helper.GeoHelper; import com.moon.server.helper.StringHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -25,28 +26,7 @@ */ @Service public class ReadRasterService { - private SpatialReference sr4326; - - private SpatialReference sr4490; - - private SpatialReference sr104903; - private final static Log log = LogFactory.getLog(ReadRasterService.class); - - /** - * 鍒濆鍖栫┖闂村紩鐢� - */ - private void initSpatialReference() { - if (null == sr4326) { - sr4326 = new SpatialReference(); - sr4326.ImportFromEPSG(StaticData.I4326); - - sr4490 = new SpatialReference(); - sr4490.ImportFromEPSG(StaticData.I4490); - - sr104903 = new SpatialReference(StaticData.MOON_2000_WKT); - } - } /** * 璇诲彇鏍呮牸淇℃伅 @@ -204,8 +184,6 @@ * 鍧愭爣杞崲 */ private Geometry transform(Dataset ds, Geometry point) { - this.initSpatialReference(); - point.AssignSpatialReference(ds.GetSpatialRef()); if (ds.GetSpatialRef().IsGeographic() > 0) { return point; @@ -213,9 +191,9 @@ String srsName = ds.GetSpatialRef().GetName(); if (srsName.contains(StaticData.CGCS2000)) { - point.TransformTo(sr4490); + point.TransformTo(GeoHelper.sr4490); } else { - point.TransformTo(sr4326); + point.TransformTo(GeoHelper.sr4326); } point.SwapXY(); -- Gitblit v1.9.3