使用GDAL库重新投影坐标

时间:2015-02-09 16:03:49

标签: c++ gdal coordinate-systems mingw-w64

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

使用GDAL,我开始将已知的utm坐标更改为同一坐标系(29 N)中的lat / lon对应,只是为了检查我是否编写了正确的代码(我在这里省略了错误检查):

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。前后转换似乎正常工作:lat / lon coordiantes是正确的,当投射回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米的差异(原点由表示。我的"后重新投影& #34; point由 dagger 表示。

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

1 个答案:

答案 0 :(得分:3)

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

设置此功能应该有效。

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

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