• prj坐标转换


    同一参考椭球下不同坐标系转换

    投影坐标转经纬度

    经纬度转投影坐标

    头文件和宏定义

    #include <proj_api.h>
    #include <string>
    
    #define RAD_TO_DEG 57.295779513082321
    #define DEG_TO_RAD .017453292519943296

    定义坐标系

    projPJ pj_from_;
    projPJ pj_to_;
     
     int zone = 51;
    //UTM
     std::string to_coordinate = "+proj=utm +zone=" + std::to_string(zone) + " +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
    //WGS84
     std::string from_coordinate = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";

    坐标系赋值函数

    bool CoordinateConvertTool::SetConvertParam(from_coordinate,to_coordinat)
    {

    if (pj_from_)
    {   pj_free(pj_from_);   pj_from_
    = nullptr; } if (pj_to_) { pj_free(pj_to_); pj_to_ = nullptr; } if (!(pj_from_ = pj_init_plus(from_coordinate.c_str())))  {return false; } if (!(pj_to_ = pj_init_plus(to_coordinate.c_str()))) { pj_free(pj_from_); pj_from_ = nullptr; return false; } return true; }

    坐标转换函数

    bool CoordinateConvertTool::CoordiateConvertToLatLong(const double utm_x, const double utm_y,
                              const double utm_z, double* longitude,
                              double* latitude, double* height_ellipsoid)
    {
    if (!pj_from_ || !pj_to_)
     {
        return false; } double gps_longitude = utm_x; double gps_latitude = utm_y; double gps_alt = utm_z; if (pj_is_latlong(pj_from_))
    { gps_longitude
    *= DEG_TO_RAD; gps_latitude *= DEG_TO_RAD; gps_alt = utm_z; } if (0 != pj_transform(pj_from_,pj_to_, 1, 1, &gps_longitude, &gps_latitude, &gps_alt))
    {
    return false; } if (pj_is_latlong(pj_to_))
    { gps_longitude
    *= RAD_TO_DEG; gps_latitude *= RAD_TO_DEG; } *longitude = gps_longitude; *latitude = gps_latitude; *height_ellipsoid = gps_alt; return ture; }
  • 相关阅读:
    win10 Administrator
    笔记
    一步一步建MVC
    安装mysql数据库
    为什么工具监测不出内存泄漏
    实现客户端服务端编译分离
    session
    JavasScript基数排序
    asp.net C# 导出EXCEL数据
    (Excel导出失败)检索COM类工厂中CLSID为{00024500-0000-0000-C000-000000000046}的组件时失
  • 原文地址:https://www.cnblogs.com/geospatial/p/14266649.html
Copyright © 2020-2023  润新知