geopro/tests/core/test_crs_transform.cpp

27 lines
1.3 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <gtest/gtest.h>
#include "geo/CrsTransform.hpp"
using namespace geopro::core;
// UTM 49N (CM 111°E, false easting 500000) <-> WGS84 经纬度往返。
// 输入 easting≈516868 仅比中央经线偏东 ~16.9km,故经度落在 ~111.16°E非 114°
// normalize_for_visualization 后forward 输出 (lon, lat)inverse 输入 (lon, lat)。
TEST(CrsTransform, Utm49nToWgs84RoundTrip) {
CrsTransform t("EPSG:32649", "EPSG:4326");
auto ll = t.forward(516868.0, 2494259.0); // (east,north) -> (lon,lat)
EXPECT_NEAR(ll.x, 111.16, 0.05); // lon
EXPECT_NEAR(ll.y, 22.55, 0.05); // lat
auto en = t.inverse(ll.x, ll.y); // (lon,lat) -> (east,north)
EXPECT_NEAR(en.x, 516868.0, 1.0);
EXPECT_NEAR(en.y, 2494259.0, 1.0);
}
// WebMercator -> UTM 49N 异源重投影(设计 §5 影像重投影)。
// tfw 原点经度真实约 114.16°E距 49N 中央经线 111°E 偏东 ~3.16°,
// 故其 49N easting 远大于 false easting落在 ~825km 处(合理且 < UTM 带宽上限)。
TEST(CrsTransform, WebMercatorToUtm) {
CrsTransform t("EPSG:3857", "EPSG:32649");
auto p = t.forward(12708343.88, 2577685.90); // tfw 原点
EXPECT_GT(p.x, 800000.0); EXPECT_LT(p.x, 850000.0); // UTM 49N 合理 Easting
EXPECT_GT(p.y, 2400000.0); EXPECT_LT(p.y, 2600000.0); // 合理 Northing
}