utm坐标和经纬度相互转换
项⽬中⽤到经纬度相互转换,⾃⼰写感觉太⿇烦,查询后发现利⽤geos和proj4可以完成坐标转换,现在记录⼀下⽅便以后⾃⼰查询。
//经纬度转utm坐标
int convert_lonlat_utm(const new3s_PointXYZ &lon_lat_coord, new3s_PointXYZ &utm_coord)
{
OGRSpatialReference *RefSource = new OGRSpatialReference;
RefSource->SetWellKnownGeogCS("WGS84");
OGRSpatialReference *RefTarget = new OGRSpatialReference;
RefTarget = RefSource->CloneGeogCS();
int utmzone = lon__x() / 6 + 31;
RefTarget->SetProjCS("UTM(WGS84) in northern hemisphere.");
RefTarget->SetUTM(utmzone, TRUE);
OGRCoordinateTransformation *poTransform = OGRCreateCoordinateTransformation(RefSource, RefTarget);
double tempX = lon__x();transform和convert的区别
double tempY = lon__y();
double tempZ = lon__z();
poTransform->Transform(1, &tempX, &tempY, &tempZ);
utm_coord.set_x(tempX);
utm_coord.set_y(tempY);
utm_coord.set_z(tempZ);
return utmzone;
}
这⾥返回的是条带数,因为在下⾯UTM坐标转经纬度的时需要条带数。
//utm转经纬度
void convert_utm_lonlat(const new3s_PointXYZ &utm_coord, const int &utmzone, new3s_PointXYZ &lon_lat_coord)
{
//建⽴投影坐标系到经纬度坐标系的转换
OGRSpatialReference *RefSource = new OGRSpatialReference;
RefSource->SetWellKnownGeogCS("WGS84");
RefSource->SetProjCS("UTM(WGS84) in northern hemisphere.");
RefSource->SetUTM(utmzone, TRUE);
OGRSpatialReference *RefTarget = new OGRSpatialReference;
RefTarget = RefSource->CloneGeogCS();
OGRCoordinateTransformation *poTranform = OGRCreateCoordinateTransformation(RefSource, RefTarget);
OGRPoint *poPoint = new OGRPoint();
double tempx = _x();
double tempy = _y();
double tempz = _z();
poTranform->Transform(1, &tempx, &tempy, NULL);
lon_lat_coord = new3s_PointXYZ(tempx, tempy, tempz);
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论