From 1686db280b8bad0944adddb93b9e4387e6101c43 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期一, 28 八月 2023 16:01:39 +0800 Subject: [PATCH] 修改坐标转换功能 --- DataLoader/CS/GdalHelper.cs | 57 +++++++++++++--------------- DataLoader/CS/StaticData.cs | 4 +- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/DataLoader/CS/GdalHelper.cs b/DataLoader/CS/GdalHelper.cs index 18c23c6..083bc87 100644 --- a/DataLoader/CS/GdalHelper.cs +++ b/DataLoader/CS/GdalHelper.cs @@ -108,23 +108,20 @@ try { ds = Gdal.Open(vd.FilePath, Access.GA_ReadOnly); - if (null == ds || ds.RasterCount == 0) return; + if (null == ds || ds.RasterCount == 0 || null == ds.GetSpatialRef()) return; vd.Meta.gridsize = string.Format("{0},{1}", ds.RasterXSize, ds.RasterYSize); // 琛屽垪鏁� SpatialReference sr = ds.GetSpatialRef(); - if (sr != null) + vd.Meta.coor_sys = sr.GetName(); // 鍧愭爣绯荤粺 + if (MOON200 == vd.Meta.coor_sys) { - vd.Meta.coor_sys = sr.GetName(); // 鍧愭爣绯荤粺 - if (MOON200 == vd.Meta.coor_sys) - { - vd.Meta.epsg = "ESRI:104903"; // EPSG缂栫爜 - } - else - { - string code = sr.GetAuthorityCode(null); - vd.Meta.epsg = string.IsNullOrEmpty(code) ? null : "EPSG:" + code; // EPSG缂栫爜 - } + vd.Meta.epsg = "ESRI:104903"; // EPSG缂栫爜 + } + else + { + string code = sr.GetAuthorityCode(null); // PROJCS銆丟EOGCS銆丟EOGCS|UNIT 鎴� NULL + vd.Meta.epsg = string.IsNullOrEmpty(code) ? null : "EPSG:" + code; // EPSG缂栫爜 } vd.Meta.bands = ds.RasterCount.ToString(); // 娉㈡鏁� @@ -133,11 +130,11 @@ vd.Meta.ct = null == ct ? null : ct.ToString(); // 鏁版嵁棰滆壊琛� vd.Meta.h_datum = null; // 楂樼▼鍩哄噯 - double[] transform = new double[6]; - ds.GetGeoTransform(transform); - vd.Meta.resolution = string.Format("{0},{1}", transform[1], transform[5]); // 鍒嗚鲸鐜� + double[] tr = new double[6]; + ds.GetGeoTransform(tr); + vd.Meta.resolution = string.Format("{0},{1}", tr[1], tr[5]); // 鍒嗚鲸鐜� - if (!EPSGS.Contains(vd.Meta.epsg)) return; + if (tr[0] == 0.0 && tr[1] == 1.0 && tr[2] == 0.0 && tr[3] == 0.0 && tr[4] == 0.0 && tr[5] == 1.0) return; Geometry minPoint = GetMinPoint(ds); Geometry maxPoint = GetMaxPoint(ds); @@ -182,6 +179,15 @@ /// </summary> private Geometry GetMaxPoint(Dataset ds) { + /** + * transform[0] 宸︿笂瑙抶鍧愭爣 + * transform[1] 涓滆タ鏂瑰悜鍒嗚鲸鐜� + * transform[2] 鏃嬭浆瑙掑害, 0琛ㄧず鍥惧儚 "鍖楁柟鏈濅笂" + * + * transform[3] 宸︿笂瑙抷鍧愭爣 + * transform[4] 鏃嬭浆瑙掑害, 0琛ㄧず鍥惧儚 "鍖楁柟鏈濅笂" + * transform[5] 鍗楀寳鏂瑰悜鍒嗚鲸鐜� + */ double[] transform = new double[6]; ds.GetGeoTransform(transform); @@ -200,24 +206,14 @@ /// </summary> private Geometry Transform(Dataset ds, Geometry point, string epsg) { - if (string.IsNullOrEmpty(epsg)) + point.AssignSpatialReference(ds.GetSpatialRef()); + if (ds.GetSpatialRef().IsGeographic() > 0) { - point.AssignSpatialReference(sr104903); - return point; - } - if ("4326" == epsg) - { - point.AssignSpatialReference(sr4326); - return point; - } - if ("4490" == epsg) - { - point.AssignSpatialReference(sr4490); return point; } - point.AssignSpatialReference(ds.GetSpatialRef()); - if (ds.GetSpatialRef().GetName().Contains("CGCS2000")) + string srsName = ds.GetSpatialRef().GetName(); + if (srsName.Contains("CGCS2000")) { point.TransformTo(sr4490); } @@ -225,6 +221,7 @@ { point.TransformTo(sr4326); } + point.SwapXY(); return point; } diff --git a/DataLoader/CS/StaticData.cs b/DataLoader/CS/StaticData.cs index b3686d8..9e1e5c0 100644 --- a/DataLoader/CS/StaticData.cs +++ b/DataLoader/CS/StaticData.cs @@ -45,7 +45,7 @@ /// <summary> /// 鏍呮牸鏁版嵁鎵╁睍鍚� /// </summary> - public static readonly List<String> RASTER_EXT = new List<String> { ".img", ".tif", ".tiff", "jpg", "jp2" }; + public static readonly List<String> RASTER_EXT = new List<String> { ".img", ".tif", ".tiff", ".jpg", ".jp2" }; /// <summary> /// 16杩涘埗 @@ -95,7 +95,7 @@ /// <summary> /// Mapper鎺掗櫎鎵╁睍鍚� /// </summary> - public readonly static List<String> MAPPER_EXCLUDE_EXT = new List<String> { ".jpg.aux.xml", ".jpg.xml", ".jp2.aux.xml", ".jp2.xml", ".jp2.html", ".jp2.txt", ".img.aux.xml", ".img.xml", ".tif.aux.xml", ".tif.xml", ".tiff.aux.xml", ".tiff.xml", ".shp.xml" }; + public readonly static List<String> MAPPER_EXCLUDE_EXT = new List<String> { ".jpg.aux.xml", ".jpg.xml", ".jp2.aux.xml", ".jp2.xml", ".jp2.html", ".jp2.txt", ".img.aux.xml", ".img.xml", ".tif.aux.xml", ".tif.xml", ".tiff.aux.xml", ".tiff.xml", ".shp.xml", ".ecw.xml", "ecw.aux.xml" }; /// <summary> /// 鎵�鏈夋枃浠舵墿灞曞悕 -- Gitblit v1.9.3