zoukankan      html  css  js  c++  java
  • 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; }
  • 相关阅读:
    java spring Validator
    jwt生成token
    java最大子序列
    在chrome下让网页显示12号以下的字体
    父元素position: relative;子元素position: absolute;子元素要超出父元素,但宽度不确定(自适应)
    行内元素和块级元素
    js打开新窗口方法整理
    浏览器加载、解析、渲染的过程
    Web前端优化,提高加载速度
    HTMl5的sessionStorage和localStorage
  • 原文地址:https://www.cnblogs.com/geospatial/p/14266649.html
Copyright © 2011-2022 走看看