gpt4 book ai didi

c++ - 使用 GDAL 库重新投影坐标

转载 作者:太空狗 更新时间:2023-10-29 21:19:06 25 4
gpt4 key购买 nike

我正在尝试将 WGS84 系统中的 lat/lon 坐标重新投影到 SIRGAS 2000 中的 UTM 坐标 坐标系。

使用 GDAL,我开始将已知的 utm 坐标更改为 在相同 坐标系 (29 N) 中的纬度/经度坐标,只是为了检查我写的正确的代码(我在这里省略了错误检查):

OGRSpatialReference monUtm;
monUtm.SetWellKnownGeogCS("WGS84");
monUtm.SetUTM(29, true);

OGRSpatialReference monGeo;
monGeo.SetWellKnownGeogCS("WGS84");

OGRCoordinateTransformation* coordTrans = OGRCreateCoordinateTransformation(&monUtm, &monGeo);

double x = 621921.3413490148;
double y = 4794536.070196861;

int reprojected = coordTrans->Transform(1, &x, &y);
// If OK, print the coords.

delete coordTrans;
coordTrans = OGRCreateCoordinateTransformation(&monGeo, &monUtm);
reprojected = coordTrans->Transform(1, &x, &y);

// If OK, Print the coords.
delete coordTrans;

坐标621921.3413490148, 4794536.070196861 correspond to the Moncelos region in northern Galicia .来回变换似乎工作正常:纬度/经度坐标是正确的,当投影回 UTM 时,我得到与原始坐标相同的坐标:

UTM:          621921.34135 , 4794536.0702
Lat/lon: 43.293779579 , -7.4970160261
Back to UTM: 621921.34135 , 4794536.0702

现在,从 WGS84 lat/long 重新投影到 SIRGAS 2000 UTM:

// Rodovia dos Tamoios, Brazil:
// - UTM -> 23 S
// - WGS 84 -> EPSG:32723
// - SIRGAS 2000 -> EPSG:31983

OGRSpatialReference wgs;
wgs.SetWellKnownGeogCS("WGS84");

OGRSpatialReference sirgas;
sirgas.importFromEPSG(31983);

coordTrans = OGRCreateCoordinateTransformation(&wgs, &sirgas);

double x = -23.57014667;
double y = -45.49159617;

reprojected = coordTrans->Transform(1, &x, &y);
// If OK, print results
delete coordTrans;

coordTrans = OGRCreateCoordinateTransformation(&sirgas, &wgs);
reprojected = coordTrans->Transform(1, &x, &y);
// If OK, print results.

这不会给出相同的结果:

WGS84 Lat/Lon input:      -23.57014667  ,  -45.49159617
SIRGAS 2000 UTM output: 2173024.0216 , 4734004.2131
Back to WGS84 Lat/Lon: -23.570633824 , -45.491627598

如您所见,原始 WGS84 lat/lonback-to_WGS84 lat/lon 坐标并不完全相同,这与第一个测试用例不同。此外,UTM x-coord 有 7 位数字(我认为它被限制为 6 (?) )。

In Google Maps ,我们可以看到两点之间相差 27 米(原始点用表示。我的“反向投影”点用 Dagger 表示).

最后,问题是:我做的重投影正确吗?如果是这样,为什么第二个测试用例中的重投影之间有 27 米的差异?

最佳答案

问题是您需要交换轴顺序以使用笛卡尔 X/Y 空间或 Lon/Lat,而不是“Lat/Lon”顺序。

设置它应该有效。

double x = -45.49159617;  // Lon
double y = -23.57014667; // Lat

您从往返转换中看到的差异是由于交换轴顺序而投影到 UTM 区域的边界之外。

关于c++ - 使用 GDAL 库重新投影坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28413970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com