最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++實(shí)現(xiàn)百度坐標(biāo)(BD09)及GCJ02與WGS84之間的轉(zhuǎn)換

 更新時(shí)間:2023年03月03日 09:55:28   作者:毓樹(shù)麟風(fēng)  
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)百度坐標(biāo)(BD09)及GCJ02與WGS84之間的轉(zhuǎn)換的方法,文中的示例代碼講解詳細(xì),希望對(duì)大家有所幫助

實(shí)現(xiàn)代碼

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <math.h>
typedef struct _POSITION
{
    double longitude;
    double latitude;
}POSITION;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
    double translate_lon(double lon,double lat);
    double translate_lat(double lon,double lat);
    bool outof_China(double lon,double lat);
    POSITION bd09togcj02(double bd_lon, double bd_lat);
    POSITION gcj02tobd09(double gcj_lon,double gcj_lat);
    POSITION gcj02towgs84(double gcj_lon,double gcj_lat);
    POSITION wgs84togcj02(double wgs_lon,double wgs_lat);
    void pushbutton1();
    void pushbutton2();
    void pushbutton3();
private:
    Ui::MainWindow *ui;
    POSITION bd_pos;
    POSITION gcj_pos;
    POSITION wgs_pos;
    double x_PI = 3.14159265358979323846 * 3000.0 / 180.0;
    double PI = 3.1415926535897932384626;
    double a = 6378245.0;
    double ee = 0.00669342162296594323;
};

#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("Position Translate");
    connect(ui->pushButton  ,SIGNAL(clicked()),this,SLOT(pushbutton1()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(pushbutton2()));
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(pushbutton3()));
}
MainWindow::~MainWindow()
{
    delete ui;
}
bool MainWindow::outof_China(double lon, double lat)
{
    return(lon<72.004 || lon>137.8374 || lat<0.8293 || lat >55.8271 || false);
}
POSITION MainWindow::bd09togcj02(double bd_lon, double bd_lat)
{
    double x = bd_lon - 0.0065;
    double y = bd_lat - 0.006;
    double z = sqrt(x*x + y*y) - 0.00002*sin(y*x_PI);
    double theta = atan2(y,x) - 0.000003*cos(x*x_PI);
    gcj_pos.longitude = z*cos(theta);
    gcj_pos.latitude = z*sin(theta);
    return gcj_pos;
}
POSITION MainWindow::gcj02tobd09(double gcj_lon, double gcj_lat)
{
     double z = sqrt(gcj_lon*gcj_lon + gcj_lat*gcj_lat) + 0.00002*sin(gcj_lat * x_PI);
     double theta = atan2(gcj_lat,gcj_lon) + 0.000003 * cos(gcj_lon * x_PI);
     bd_pos.longitude = z*cos(theta) + 0.0065;
     bd_pos.latitude = z*sin(theta) + 0.006;
     return bd_pos;
}
double MainWindow::translate_lon(double lon, double lat)
{
    double ret = 300.0 + lon +2.0*lat + 0.1*lon*lon +0.1*lon*lat + 0.1*sqrt(abs(lon));
    ret += (20.0 * sin(6.0*lon*PI) + 20.0*sin(2.0*lon*PI)) *2.0 / 3.0;
    ret += (20.0 * sin(lon*PI) + 40.0*sin(lon/3.0 *PI)) *2.0 /3.0;
    ret += (150 * sin(lon/12.0 *PI) + 300.0*sin(lon/30.0 * PI)) *2.0 /3.0;
    return ret;
}
double MainWindow::translate_lat(double lon, double lat)
{
    double ret = -100 + 2.0*lon + 3.0*lat + 0.2*lat*lat + 0.1*lon*lat + 0.2*sqrt((abs(lon)));
    ret += (20.0 *sin(6.0*lon*PI) + 20*sin(2.0*lon*PI)) *2.0 /3.0;
    ret += (20.0 *sin(lat*PI) + 40.0*sin(lat/3.0*PI)) *2.0 /3.0;
    ret += (160.0*sin(lat/12.0*PI) + 320.0*sin(lat/30.0 *PI)) *2.0 /3.0;
    return ret;
}
POSITION MainWindow::gcj02towgs84(double gcj_lon, double gcj_lat)
{
    if(outof_China(gcj_lon,gcj_lat))
    {
        wgs_pos.longitude = gcj_lon;
        wgs_pos.latitude = gcj_lat;
        return wgs_pos;
    }
    else
    {
        double dlat = translate_lat(gcj_lon - 105.0,gcj_lat -35.0);
        double dlon = translate_lon(gcj_lon - 105.0,gcj_lat -35.0);
        double radlat = gcj_lat/180.0 *PI;
        double magic = sin(radlat);
        magic = 1 - ee*magic*magic;
        double squrtmagic = sqrt(magic);
        dlon = (dlon *180.0)/(a/squrtmagic*cos(radlat)*PI);
        dlat = (dlat *180.0)/((a*(1-ee))/(magic * squrtmagic)*PI);
        wgs_pos.longitude = gcj_lon - dlon;
        wgs_pos.latitude = gcj_lat - dlat;
        return wgs_pos;
    }
}
POSITION MainWindow::wgs84togcj02(double wgs_lon, double wgs_lat)
{
    if(outof_China(wgs_lon,wgs_lat))
    {
        gcj_pos.longitude = wgs_lon;
        gcj_pos.latitude = wgs_lat;
        return gcj_pos;
    }
    else
    {
        double dlat = translate_lat(wgs_lon - 105.0,wgs_lat - 35.0);
        double dlon = translate_lon(wgs_lon - 105.0,wgs_lat - 35.0);
        double radlat = wgs_lat/180.0 * PI;
        double magic = sin(radlat);
        magic = 1 - ee*magic*magic;
        double squrtmagic = sqrt(magic);
        dlon = (dlon *180.0)/(a/squrtmagic*cos(radlat)*PI);
        dlat = (dlat *180.0)/((a*(1-ee))/(magic * squrtmagic)*PI);
        gcj_pos.longitude = wgs_lon + dlon;
        gcj_pos.latitude = wgs_lat +dlat;
        return gcj_pos;
    }
}
/*************************************************************************
 *
 * 讀取 BD09 坐標(biāo),轉(zhuǎn)換為 WGS84 和 GCJ02 坐標(biāo)
 *
 ***********************************************************************/
void MainWindow::pushbutton1()
{
    double bd09_lon = ui->lineEdit_bd09lon->text().toDouble();
    double bd09_lat = ui->lineEdit_bd09lat->text().toDouble();
    double gcj02_lon = bd09togcj02(bd09_lon,bd09_lat).longitude;
    double gcj02_lat = bd09togcj02(bd09_lon,bd09_lat).latitude;
    double wgs84_lon = gcj02towgs84(gcj02_lon,gcj02_lat).longitude;
    double wgs84_lat =gcj02towgs84(gcj02_lon,gcj02_lat).latitude;
    ui->lineEdit_gcj02lon->setText(QString::number(gcj02_lon,'d',9));
    ui->lineEdit_gcj02lat->setText(QString::number(gcj02_lat,'d',9));
    ui->lineEdit_wgs84lon->setText(QString::number(wgs84_lon,'d',9));
    ui->lineEdit_wgs84lat->setText(QString::number(wgs84_lat,'d',9));
}
/*************************************************************************
 *
 * 讀取 GCJ02 坐標(biāo),轉(zhuǎn)換為 WGS84 和 BD09 坐標(biāo)
 *
 ***********************************************************************/
void MainWindow::pushbutton2()
{
    double gcj02_lon = ui->lineEdit_gcj02lon->text().toDouble();
    double gcj02_lat = ui->lineEdit_gcj02lat->text().toDouble();
    double bd09_lon = gcj02tobd09(gcj02_lon,gcj02_lat).longitude;
    double bd09_lat = gcj02tobd09(gcj02_lon,gcj02_lat).latitude;
    double wgs84_lon = gcj02towgs84(gcj02_lon,gcj02_lat).longitude;
    double wgs84_lat = gcj02towgs84(gcj02_lon,gcj02_lat).latitude;
    ui->lineEdit_bd09lon->setText(QString::number(bd09_lon,'d',9));
    ui->lineEdit_bd09lat->setText(QString::number(bd09_lat,'d',9));
    ui->lineEdit_wgs84lon->setText(QString::number(wgs84_lon,'d',9));
    ui->lineEdit_wgs84lat->setText(QString::number(wgs84_lat,'d',9));
}
/*************************************************************************
 *
 * 讀取 WGS84 坐標(biāo),轉(zhuǎn)換為 GCJ02 和 BD09 坐標(biāo)
 *
 ***********************************************************************/
void MainWindow::pushbutton3()
{
    double wgs84_lon = ui->lineEdit_wgs84lon->text().toDouble();
    double wgs84_lat = ui->lineEdit_wgs84lat->text().toDouble();
    double gcj02_lon = wgs84togcj02(wgs84_lon,wgs84_lat).longitude;
    double gcj02_lat = wgs84togcj02(wgs84_lon,wgs84_lat).latitude;
    double bd09_lon = gcj02tobd09(gcj02_lon,gcj02_lat).longitude;
    double bd09_lat = gcj02tobd09(gcj02_lon,gcj02_lat).latitude;
    ui->lineEdit_bd09lon->setText(QString::number(bd09_lon,'d',9));
    ui->lineEdit_bd09lat->setText(QString::number(bd09_lat,'d',9));
    ui->lineEdit_gcj02lon->setText(QString::number(gcj02_lon,'d',9));
    ui->lineEdit_gcj02lat->setText(QString::number(gcj02_lat,'d',9));
}

算法來(lái)源于網(wǎng)上搜集,運(yùn)行結(jié)果如下:

到此這篇關(guān)于C++實(shí)現(xiàn)百度坐標(biāo)(BD09)及GCJ02與WGS84之間的轉(zhuǎn)換的文章就介紹到這了,更多相關(guān)C++坐標(biāo)轉(zhuǎn)換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 枚舉和宏的區(qū)別詳細(xì)解析

    枚舉和宏的區(qū)別詳細(xì)解析

    枚舉常量具有類(lèi)型,但宏沒(méi)有類(lèi)型,枚舉變量具有與普通變量相同的諸如作用域、值等性質(zhì),但宏沒(méi)有,宏不是語(yǔ)言的一部分,它是一種預(yù)處理替換符
    2013-09-09
  • 淺談C#中List<T>對(duì)象的深度拷貝問(wèn)題

    淺談C#中List<T>對(duì)象的深度拷貝問(wèn)題

    下面小編就為大家?guī)?lái)一篇淺談C#中List<T>對(duì)象的深度拷貝問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-01-01
  • Qt?TCP網(wǎng)絡(luò)通信學(xué)習(xí)

    Qt?TCP網(wǎng)絡(luò)通信學(xué)習(xí)

    用于數(shù)據(jù)傳輸?shù)牡蛯泳W(wǎng)絡(luò)協(xié)議,多個(gè)物聯(lián)網(wǎng)協(xié)議都是基于TCP協(xié)議的,這篇文章為大家介紹了Qt?TCP網(wǎng)絡(luò)通信,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • C語(yǔ)言實(shí)現(xiàn)貪吃蛇游戲代碼

    C語(yǔ)言實(shí)現(xiàn)貪吃蛇游戲代碼

    大家好,本篇文章主要講的是C語(yǔ)言實(shí)現(xiàn)貪吃蛇游戲代碼,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-02-02
  • C++ LeetCode543題解二叉樹(shù)直徑

    C++ LeetCode543題解二叉樹(shù)直徑

    這篇文章主要為大家介紹了C++ LeetCode543題解二叉樹(shù)直徑,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • C++如何獲取鼠標(biāo)點(diǎn)擊位置

    C++如何獲取鼠標(biāo)點(diǎn)擊位置

    這篇文章主要介紹了C++如何獲取鼠標(biāo)點(diǎn)擊位置問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • C++使用read()和write()讀寫(xiě)二進(jìn)制文件

    C++使用read()和write()讀寫(xiě)二進(jìn)制文件

    以文本形式讀寫(xiě)文件和以二進(jìn)制形式讀寫(xiě)文件的區(qū)別,并掌握了用重載的?>>?和?<<?運(yùn)算符實(shí)現(xiàn)以文本形式讀寫(xiě)文件,在此基礎(chǔ)上,本節(jié)將講解如何以二進(jìn)制形式讀寫(xiě)文件
    2023-10-10
  • C語(yǔ)言中的字符型數(shù)據(jù)與ASCII碼表

    C語(yǔ)言中的字符型數(shù)據(jù)與ASCII碼表

    這篇文章主要介紹了C語(yǔ)言中的字符型數(shù)據(jù)與ASCII碼表,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • cin.get()和cin.getline()之間的區(qū)別

    cin.get()和cin.getline()之間的區(qū)別

    以下是對(duì)cin.get()和cin.getline()的區(qū)別進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助
    2013-09-09
  • 淺析C語(yǔ)言字中的符串格式化顯示

    淺析C語(yǔ)言字中的符串格式化顯示

    以下是對(duì)C語(yǔ)言字中的符串格式化顯示進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下
    2013-08-08

最新評(píng)論

屏山县| 吴桥县| 东海县| 嘉定区| 旅游| 芦山县| 东乌珠穆沁旗| 新竹县| 得荣县| 顺义区| 内丘县| 长沙市| 通江县| 辽源市| 兴城市| 同江市| 云和县| 土默特右旗| 龙陵县| 托里县| 乌拉特前旗| 湖口县| 寿阳县| 滕州市| 社旗县| 封丘县| 北宁市| 库尔勒市| 屏东市| 通河县| 新兴县| 龙陵县| 平果县| 黑水县| 连云港市| 汉中市| 彭州市| 晋城| 水富县| 安阳市| 彭阳县|