国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Java轉(zhuǎn)換坐標(biāo)系,GPS(WGS84)大地200(CGCS200)、百度(BD-09)、高德(GCJ-02)互轉(zhuǎn),一文搞懂坐標(biāo)系、坐標(biāo)轉(zhuǎn)換

這篇具有很好參考價值的文章主要介紹了Java轉(zhuǎn)換坐標(biāo)系,GPS(WGS84)大地200(CGCS200)、百度(BD-09)、高德(GCJ-02)互轉(zhuǎn),一文搞懂坐標(biāo)系、坐標(biāo)轉(zhuǎn)換。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

1.分不清的坐標(biāo)系
WG-S84: 地理坐標(biāo)系統(tǒng),GPS儀器記錄的經(jīng)緯度信息,Google Earth采用,Google Map中國范圍外使用,高德地圖中國范圍外使用。 GCJ-02: 投影坐標(biāo)系統(tǒng),火星坐標(biāo)系,中國國家測繪局制定的坐標(biāo)系統(tǒng),由WGS-84加密后的坐標(biāo)。Google中國和搜搜地圖,arcgis地圖,高德地圖 BD-09: 投影坐標(biāo)系統(tǒng),百度坐標(biāo),GCJ-02加密后的坐標(biāo)系,只適用于百度地圖

(在國內(nèi)是不允許直接用WGS84坐標(biāo)系標(biāo)注的,必須經(jīng)過加密后才能用。必須至少使用GCJ-02坐標(biāo)系,或者使用在GCJ-02加密后再進行加密的坐標(biāo)系,如百度坐標(biāo)系)

其他:搜狗地圖:搜狗坐標(biāo)系,圖吧:圖吧坐標(biāo)等,估計也是在GCJ02基礎(chǔ)上加密而成的,這里暫不涉及

2.直接上代碼

package ft.util.gps;
// 導(dǎo)入Proj4J庫

import org.locationtech.proj4j.*;
import org.locationtech.proj4j.io.Proj4FileReader;

import java.io.IOException;

/**
 * 百度坐標(biāo)(BD09)、國測局坐標(biāo)(火星坐標(biāo),GCJ02)、和WGS84坐標(biāo)系之間的轉(zhuǎn)換的工具
 * <p>
 * 參考 https://github.com/wandergis/coordtransform 實現(xiàn)的Java版本
 *
 * @author geosmart
 */
public class CoordinateTransformUtil {
    static double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
    // π
    static double pi = 3.1415926535897932384626;
    // 長半軸
    static double a = 6378245.0;
    // 扁率
    static double ee = 0.00669342162296594323;
    /**
     * 百度坐標(biāo)系(BD-09)轉(zhuǎn)WGS坐標(biāo)
     *
     * @param lng 百度坐標(biāo)緯度
     * @param lat 百度坐標(biāo)經(jīng)度
     * @return WGS84坐標(biāo)數(shù)組
     */
    public static PointXY bd09towgs84(double lng, double lat) {
        PointXY gcj = bd09togcj02(lng, lat);
        PointXY wgs84 = gcj02towgs84(gcj.getLon(), gcj.getLat());
        return wgs84;
    }
    /**
     * WGS坐標(biāo)轉(zhuǎn)百度坐標(biāo)系(BD-09)
     *
     * @param lng WGS84坐標(biāo)系的經(jīng)度
     * @param lat WGS84坐標(biāo)系的緯度
     * @return 百度坐標(biāo)數(shù)組
     */
    public static PointXY wgs84tobd09(double lng, double lat) {
        PointXY gcj = wgs84togcj02(lng, lat);
        PointXY bd09 = gcj02tobd09(gcj.getLon(), gcj.getLat());
        return bd09;
    }
    /**
     * 火星坐標(biāo)系(GCJ-02)轉(zhuǎn)百度坐標(biāo)系(BD-09)
     * <p>
     * 谷歌、高德——>百度
     *
     * @param lng 火星坐標(biāo)經(jīng)度
     * @param lat 火星坐標(biāo)緯度
     * @return 百度坐標(biāo)數(shù)組
     */
    public static PointXY gcj02tobd09(double lng, double lat) {
        double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_pi);
        double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_pi);
        double bd_lng = z * Math.cos(theta) + 0.0065;
        double bd_lat = z * Math.sin(theta) + 0.006;
        return new PointXY(bd_lng, bd_lat);
    }

    /**
     * 百度坐標(biāo)系(BD-09)轉(zhuǎn)火星坐標(biāo)系(GCJ-02)
     * <p>
     * 百度——>谷歌、高德
     *
     * @param bd_lon 百度坐標(biāo)緯度
     * @param bd_lat 百度坐標(biāo)經(jīng)度
     * @return 火星坐標(biāo)數(shù)組
     */
    public static PointXY bd09togcj02(double bd_lon, double bd_lat) {
        double x = bd_lon - 0.0065;
        double y = bd_lat - 0.006;
        double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
        double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
        double gg_lng = z * Math.cos(theta);
        double gg_lat = z * Math.sin(theta);
        return new PointXY(gg_lng, gg_lat);
    }
    /**
     * WGS84轉(zhuǎn)GCJ02(火星坐標(biāo)系)
     *
     * @param lng WGS84坐標(biāo)系的經(jīng)度
     * @param lat WGS84坐標(biāo)系的緯度
     * @return 火星坐標(biāo)數(shù)組
     */
    public static PointXY wgs84togcj02(double lng, double lat) {
        if (out_of_china(lng, lat)) {
            return new PointXY(lng, lat);
        }
        double dlat = transformlat(lng - 105.0, lat - 35.0);
        double dlng = transformlng(lng - 105.0, lat - 35.0);
        double radlat = lat / 180.0 * pi;
        double magic = Math.sin(radlat);
        magic = 1 - ee * magic * magic;
        double sqrtmagic = Math.sqrt(magic);
        dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi);
        dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi);
        double mglat = lat + dlat;
        double mglng = lng + dlng;
        return new PointXY(mglng, mglat);
    }
    /**
     * GCJ02(火星坐標(biāo)系)轉(zhuǎn)GPS84
     *
     * @param lng 火星坐標(biāo)系的經(jīng)度
     * @param lat 火星坐標(biāo)系緯度
     * @return WGS84坐標(biāo)數(shù)組
     */
    public static PointXY gcj02towgs84(double lng, double lat) {
        if (out_of_china(lng, lat)) {
            return new PointXY(lng, lat);
        }
        double dlat = transformlat(lng - 105.0, lat - 35.0);
        double dlng = transformlng(lng - 105.0, lat - 35.0);
        double radlat = lat / 180.0 * pi;
        double magic = Math.sin(radlat);
        magic = 1 - ee * magic * magic;
        double sqrtmagic = Math.sqrt(magic);
        dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi);
        dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi);
        double mglat = lat + dlat;
        double mglng = lng + dlng;
        return new PointXY(lng * 2 - mglng, lat * 2 - mglat);
    }
    /**
     * 緯度轉(zhuǎn)換
     *
     * @param lng
     * @param lat
     * @return
     */
    public static double transformlat(double lng, double lat) {
        double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
        ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 * Math.sin(2.0 * lng * pi)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(lat * pi) + 40.0 * Math.sin(lat / 3.0 * pi)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(lat / 12.0 * pi) + 320 * Math.sin(lat * pi / 30.0)) * 2.0 / 3.0;
        return ret;
    }
    /**
     * 經(jīng)度轉(zhuǎn)換
     *
     * @param lng
     * @param lat
     * @return
     */
    public static double transformlng(double lng, double lat) {
        double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
        ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 * Math.sin(2.0 * lng * pi)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(lng * pi) + 40.0 * Math.sin(lng / 3.0 * pi)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(lng / 12.0 * pi) + 300.0 * Math.sin(lng / 30.0 * pi)) * 2.0 / 3.0;
        return ret;
    }
    /**
     * 判斷是否在國內(nèi),不在國內(nèi)不做偏移
     *
     * @param lng
     * @param lat
     * @return
     */
    public static boolean out_of_china(double lng, double lat) {
        if (lng < 72.004 || lng > 137.8347) {
            return true;
        } else if (lat < 0.8293 || lat > 55.8271) {
            return true;
        }
        return false;
    }

   

    public static PointXY wgs2cgcg(double lon, double lat) {
        Proj4FileReader proj4FileReader = new Proj4FileReader();
        String[] paramStr = new String[0];
        try {
            paramStr = proj4FileReader.readParametersFromFile("epsg","4528");
        } catch (IOException e) {
            e.printStackTrace();
        }

        CRSFactory targetFactory = new CRSFactory();
        //目標(biāo)坐標(biāo)系統(tǒng)
        CoordinateReferenceSystem cgcs = targetFactory.createFromParameters("4528", paramStr);

        //源坐標(biāo)系統(tǒng)
        CRSFactory crsFactory = new CRSFactory();
        String wgs84_param = "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degress";
        CoordinateReferenceSystem wgs84 = crsFactory.createFromParameters("WGS84", wgs84_param);

        CoordinateTransformFactory ctf = new CoordinateTransformFactory();
        CoordinateTransform transform = ctf.createTransform(wgs84, cgcs);

        ProjCoordinate projCoordinate = new ProjCoordinate(lon,lat);
        transform.transform(projCoordinate,projCoordinate);


        return new PointXY(projCoordinate.x,projCoordinate.y);
    }
    public static PointXY cgcg2wgs(double lon, double lat) {
        Proj4FileReader proj4FileReader = new Proj4FileReader();
        String[] paramStr = new String[0];
        try {
            paramStr = proj4FileReader.readParametersFromFile("epsg","4528");
        } catch (IOException e) {
            e.printStackTrace();
        }

        CRSFactory targetFactory = new CRSFactory();
        //目標(biāo)坐標(biāo)系統(tǒng)
        CoordinateReferenceSystem cgcs = targetFactory.createFromParameters("4528", paramStr);

        //源坐標(biāo)系統(tǒng)
        CRSFactory crsFactory = new CRSFactory();
        String wgs84_param = "+title=long/lat:WGS84 +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degress";
        CoordinateReferenceSystem wgs84 = crsFactory.createFromParameters("WGS84", wgs84_param);

        CoordinateTransformFactory ctf = new CoordinateTransformFactory();
        CoordinateTransform transform = ctf.createTransform(cgcs,wgs84);

        ProjCoordinate projCoordinate = new ProjCoordinate(lon,lat);
        transform.transform(projCoordinate,projCoordinate);


        return new PointXY(projCoordinate.x,projCoordinate.y);
    }


    public static void main(String[] args) {
        // 坐標(biāo)轉(zhuǎn)化api
        // https://tool.lu/coordinate/?ivk_sa=1024320u
        //
        System.out.println(wgs84togcj02(118.840344,31.99335));   // ok
        System.out.println(gcj02towgs84(107.80473041151717, 29.33190938671697));  // ok
        System.out.println(gcj02tobd09(107.80473041151717, 29.33190938671697));   // ok
        System.out.println(wgs84tobd09(107.8003647, 29.3347596));    // ok
        System.out.println(bd09togcj02(107.81129990277971, 29.337686168994296));
        System.out.println(bd09towgs84(107.81129990277971, 29.337686168994296));


        System.out.println(wgs2cgcg(118.70331743312532,32.103750473727125));
//        System.out.println(bd09towgs84(120.24794,29.72979));
//gcj02towgs84
//        System.out.println(gcj02tobd09(120.236701, 29.726141));
//
        PointXY p = wgs2cgcg(118.70331743312532,32.103750473727125);
        System.out.println(p);
        System.out.println(cgcg2wgs(p.getLon(), p.getLat()));



    }
}`在這里插入代碼片`

測試結(jié)果
lon:118.84543348019479,lat:31.99121178083339
lon:107.80037405167121,lat:29.334768526991336
lon:107.81129968211874,lat:29.337686107444082
lon:107.81129968211874,lat:29.337686107444082
lon:107.80473019794286,lat:29.33191023473475
lon:107.80037383758244,lat:29.33476937412017
lon:4.0377605981347054E7,lat:3554093.2140468676
lon:4.0377605981347054E7,lat:3554093.2140468676
lon:118.70331743312477,lat:32.10375047372694文章來源地址http://www.zghlxwxcb.cn/news/detail-769862.html

到了這里,關(guān)于Java轉(zhuǎn)換坐標(biāo)系,GPS(WGS84)大地200(CGCS200)、百度(BD-09)、高德(GCJ-02)互轉(zhuǎn),一文搞懂坐標(biāo)系、坐標(biāo)轉(zhuǎn)換的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • WGS84以及各種坐標(biāo)系

    地心地固坐標(biāo)系(Earth-Centered, Earth-Fixed,ECEF),簡稱地心坐標(biāo)系。 地理坐標(biāo)系統(tǒng)(Geographic Coordinate System,GCS)??1??,坐標(biāo)系是地心坐標(biāo)系,用經(jīng)緯度表示球面上的點。 世界大地測量系統(tǒng)(World Geodetic System, WGS),比如WGS84,是一種地理坐標(biāo)系統(tǒng),用于全球定位系統(tǒng)(

    2024年02月11日
    瀏覽(24)
  • arcgis javascript api4.x加載天地圖wgs84(wkid:4326)坐標(biāo)系

    arcgis javascript api4.x加載天地圖wgs84(wkid:4326)坐標(biāo)系

    使用arcgis javascript api4.x以basetilelayer方式加載天地圖wgs84(wkid:4326)坐標(biāo)系 效果: 提示:(下述三個文件放同一個文件夾下) 4326.js MyCustomTileLayer.js loadtdt4326.html https://www.cnblogs.com/hjyjack9563-bk/p/16067633.html

    2024年01月17日
    瀏覽(41)
  • 使用Qt/C++實現(xiàn)WGS84、高德GCJ-02、百度BD-09坐標(biāo)系間相互轉(zhuǎn)化

    使用Qt/C++實現(xiàn)WGS84、高德GCJ-02、百度BD-09坐標(biāo)系間相互轉(zhuǎn)化

    ? ? ? ? 在做地圖相關(guān)開發(fā)時候,繞不開不同坐標(biāo)系間的轉(zhuǎn)化,因此我根據(jù)查閱相關(guān)資料后將不同坐標(biāo)系間的轉(zhuǎn)換封裝到一個GeoTranslate類中,該類轉(zhuǎn)換函數(shù)不僅支持Qt/C++調(diào)用,同時可在QML中直接調(diào)用,配合上QML/Map很方便,我將該類做了個Demo,方便使用者使用,效果如圖: 在

    2024年02月12日
    瀏覽(26)
  • c#大地測量學(xué)各坐標(biāo)系坐標(biāo)轉(zhuǎn)換(窗體應(yīng)用程序)

    c#大地測量學(xué)各坐標(biāo)系坐標(biāo)轉(zhuǎn)換(窗體應(yīng)用程序)

    大地坐標(biāo)系 空間直角坐標(biāo)系 子午面直角坐標(biāo)系

    2024年02月06日
    瀏覽(28)
  • GPS學(xué)習(xí)(一):在ROS2中將GPS經(jīng)緯度數(shù)據(jù)轉(zhuǎn)換為機器人ENU坐標(biāo)系,在RVIZ中顯示坐標(biāo)軌跡

    GPS學(xué)習(xí)(一):在ROS2中將GPS經(jīng)緯度數(shù)據(jù)轉(zhuǎn)換為機器人ENU坐標(biāo)系,在RVIZ中顯示坐標(biāo)軌跡

    本文記錄在Ubuntu22.04-Humbel中使用NMEA協(xié)議GPS模塊的過程,使用國產(chǎn)ROS開發(fā)板魯班貓(LubanCat )進行調(diào)試。 在淘寶找了款性價比較高的輪趣科技GPS北斗雙模定位模塊作為入門學(xué)習(xí)使用,支持GNSS系統(tǒng)(北斗、GPS、GLONASS、日本的QZSS以及衛(wèi)星增強系統(tǒng)SBAS),定位精度在2.5m左右,屬于民用

    2024年02月03日
    瀏覽(40)
  • arcgis自定義坐標(biāo)系,以WGS 1984 Albers投影坐標(biāo)系為例

    arcgis自定義坐標(biāo)系,以WGS 1984 Albers投影坐標(biāo)系為例

    最近在使用arcgis中遇到了很多的問題,其中印象最深刻的就是坐標(biāo)系的問題,如果arcgis中自帶的坐標(biāo)系中沒有找到想要的坐標(biāo)系,該怎么自定義一個新的坐標(biāo)系。在使用過程中,我發(fā)現(xiàn)arcgis并沒有我所需要的albers投影坐標(biāo)系,所以我嘗試著自定義一個albers投影坐標(biāo)系,具體步

    2024年02月04日
    瀏覽(214)
  • R語言 百度坐標(biāo)轉(zhuǎn)換至WGS84坐標(biāo)

    提示:本文利用R語言封裝了百度坐標(biāo)轉(zhuǎn)換至WGS84坐標(biāo)的函數(shù),親測有效,提供了便捷的百度坐標(biāo)轉(zhuǎn)換方法。 《利用R語言通過百度地圖API進行批量地理編碼》一文介紹了利用R語言通過百度地圖API來批量獲取地理坐標(biāo)的方法,但結(jié)果是百度坐標(biāo)系,對于地理分析來講,直接導(dǎo)入

    2024年02月13日
    瀏覽(23)
  • Java+GeoTools實現(xiàn)WKT數(shù)據(jù)根據(jù)EPSG編碼進行坐標(biāo)系轉(zhuǎn)換

    Java+GeoTools實現(xiàn)WKT數(shù)據(jù)根據(jù)EPSG編碼進行坐標(biāo)系轉(zhuǎn)換

    Java+GeoTools(開源的Java GIS工具包)快速入門-實現(xiàn)讀取shp文件并顯示: Java+GeoTools(開源的Java GIS工具包)快速入門-實現(xiàn)讀取shp文件并顯示_霸道流氓氣質(zhì)的博客-CSDN博客 在上面實現(xiàn)Java中集成Geotools之后,需求是將WKT數(shù)據(jù)轉(zhuǎn)換成其他坐標(biāo)系的WKT。 比如說將EPSG:4524的坐標(biāo)系轉(zhuǎn)換成EPSG:2

    2023年04月25日
    瀏覽(16)
  • 機器人坐標(biāo)系轉(zhuǎn)換從局部坐標(biāo)系轉(zhuǎn)換到世界坐標(biāo)系

    機器人坐標(biāo)系轉(zhuǎn)換從局部坐標(biāo)系轉(zhuǎn)換到世界坐標(biāo)系

    矩陣方式: 下面是代碼: 函數(shù)方式: 根據(jù)三角函數(shù)的特性,可以進行一下簡化: 下面是簡化前的代碼示例:

    2024年04月16日
    瀏覽(21)
  • 坐標(biāo)轉(zhuǎn)換(相機坐標(biāo)系、世界坐標(biāo)系、圖像物理坐標(biāo)系、圖像像素坐標(biāo)系)

    坐標(biāo)轉(zhuǎn)換(相機坐標(biāo)系、世界坐標(biāo)系、圖像物理坐標(biāo)系、圖像像素坐標(biāo)系)

    一般情況下我們所涉及到的坐標(biāo)包括四個,即相機坐標(biāo)系、世界坐標(biāo)系、圖像物理坐標(biāo)系、圖像像素坐標(biāo)系。我們本文的講解思路是在講解每個坐標(biāo)轉(zhuǎn)換之前先講清楚每個坐標(biāo)系所表示的含義。本文主要參考由高翔主編的視覺SLAM十四講第五章相機模型。 相機將三維世界的坐

    2024年02月09日
    瀏覽(23)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包