From 3417cf014a65765e02696c1d121ce58b2b4a8aed Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 08 四月 2025 15:55:36 +0800 Subject: [PATCH] 修改pom.xml --- src/main/java/com/se/simu/helper/GdalHelper.java | 63 ++++++------------------------- 1 files changed, 13 insertions(+), 50 deletions(-) diff --git a/src/main/java/com/se/simu/helper/GdalHelper.java b/src/main/java/com/se/simu/helper/GdalHelper.java index 536b226..3ea0ba9 100644 --- a/src/main/java/com/se/simu/helper/GdalHelper.java +++ b/src/main/java/com/se/simu/helper/GdalHelper.java @@ -12,12 +12,6 @@ import java.io.File; -/** - * GDAL甯姪绫� - * - * @author WWW - * @date 2024-09-12 - */ @Slf4j @SuppressWarnings("ALL") public class GdalHelper { @@ -52,29 +46,20 @@ } } - // 鏀寔涓枃璺緞 gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); - // 灞炴�ц〃鏀寔涓枃锛欳P936 gdal.SetConfigOption("SHAPE_ENCODING", ""); gdal.SetConfigOption("PGEO_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s"); gdal.SetConfigOption("MDB_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s"); - // 娉ㄥ唽鎵�鏈夌殑椹卞姩 gdal.AllRegister(); ogr.RegisterAll(); initSr(); } - /** - * 鍒濆鍖栧潗鏍囩郴 - * <p> - * https://blog.csdn.net/CallmeAdo/article/details/127558139 - */ public static void initSr() { try { SR4326 = new SpatialReference(); SR4326.ImportFromEPSG(I4326); - // 瀵逛簬lat/long椤哄簭鐨勫湴鐞咰RS锛屾暟鎹粛鐒舵槸long/lat椤哄簭鐨� SR4326.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER); SR4490 = new SpatialReference(); @@ -93,9 +78,6 @@ return sr; } - /** - * 鍒涘缓閲戝瓧濉� - */ public static void createPyramid(String file) { Dataset ds = null; try { @@ -109,7 +91,6 @@ return; } - // 鍒涘缓閲戝瓧濉� Band band = ds.GetRasterBand(1); if (0 == band.GetOverviewCount()) { ds.BuildOverviews("nearest", new int[]{2, 4, 6, 8, 16}, null); @@ -123,9 +104,6 @@ } } - /** - * 閿�姣佽祫婧� - */ public static void delete(Layer layer, DataSource dataSource, Driver driver) { try { if (null != layer) { @@ -150,8 +128,7 @@ } } - public static Geometry getMinPoint(Dataset ds) - { + public static Geometry getMinPoint(Dataset ds) { double[] transform = new double[6]; ds.GetGeoTransform(transform); @@ -164,17 +141,7 @@ return Transform(ds, point); } - public static Geometry getMaxPoint(Dataset ds) - { - /* - * transform[0] 宸︿笂瑙抶鍧愭爣 - * transform[1] 涓滆タ鏂瑰悜鍒嗚鲸鐜� - * transform[2] 鏃嬭浆瑙掑害, 0琛ㄧず鍥惧儚 "鍖楁柟鏈濅笂" - * - * transform[3] 宸︿笂瑙抷鍧愭爣 - * transform[4] 鏃嬭浆瑙掑害, 0琛ㄧず鍥惧儚 "鍖楁柟鏈濅笂" - * transform[5] 鍗楀寳鏂瑰悜鍒嗚鲸鐜� - */ + public static Geometry getMaxPoint(Dataset ds) { double[] transform = new double[6]; ds.GetGeoTransform(transform); @@ -187,11 +154,9 @@ return Transform(ds, point); } - public static Geometry Transform(Dataset ds, Geometry point) - { + public static Geometry Transform(Dataset ds, Geometry point) { point.AssignSpatialReference(ds.GetSpatialRef()); - if (ds.GetSpatialRef().IsGeographic() > 0) - { + if (ds.GetSpatialRef().IsGeographic() > 0) { return point; } @@ -209,9 +174,6 @@ return point; } - /** - * 杞崲涓篧GS84鍧愭爣 - */ public static Geometry toWgs84(SpatialReference sr, double x, double y) { Geometry point = new Geometry(ogr.wkbPoint); point.AssignSpatialReference(sr); @@ -223,11 +185,16 @@ return point; } - /** - * WGS84杞崲涓虹洰鏍囧潗鏍� - */ + public static int toWgs84(SpatialReference sr, Geometry g) { + CoordinateTransformation ct = new CoordinateTransformation(sr, GdalHelper.SR4326); + if (sr.IsProjected() != 1) { + sr.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER); + } + + return g.TransformTo(GdalHelper.SR4326); + } + public static double[] fromWgs84(SpatialReference sr, double x, double y) { - // https://blog.csdn.net/weixin_34910922/article/details/129208661 CoordinateTransformation ct = new CoordinateTransformation(GdalHelper.SR4326, sr); if (sr.IsProjected() != 1) { sr.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER); @@ -236,11 +203,7 @@ return ct.TransformPoint(x, y); } - /** - * WGS84杞崲涓虹洰鏍囧潗鏍� - */ public static int fromWgs84(SpatialReference sr, Geometry g) { - // https://blog.csdn.net/weixin_34910922/article/details/129208661 CoordinateTransformation ct = new CoordinateTransformation(GdalHelper.SR4326, sr); if (sr.IsProjected() != 1) { sr.SetAxisMappingStrategy(osr.OAMS_TRADITIONAL_GIS_ORDER); -- Gitblit v1.9.3