各种坐标系转换工具类[java版]
来源:互联网 发布:office mac中缺失字体 编辑:程序博客网 时间:2024/06/01 07:45
package com.sprucetec.gis_service.util;import static java.lang.StrictMath.*;/** * Group: com.xx.xx * Created by wangxihe. * Date and Time : 11:19 05/05/2017 * Email: wangxihe@xx.cn */class Coordinate { private double latitude; private double longitude; public double getLatitude() { return latitude; } public void setLatitude(double latitude) { this.latitude = latitude; } public double getLongitude() { return longitude; } public void setLongitude(double longitude) { this.longitude = longitude; }}public class CoordinateUtil { private static final double pi = 3.14159265358979324; private static final double a = 6378245.0; private static final double ee = 0.00669342162296594323; private static final double x_pi = 3.14159265358979324 * 3000.0 / 180.0; private static boolean outOfChina(double lat, double lon) { return lon < 72.004 || lon > 137.8347 || lat < 0.8293 || lat > 55.8271; } private static double transformLat(double x, double y) { double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x)); ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0; ret += (20.0 * sin(y * pi) + 40.0 * sin(y / 3.0 * pi)) * 2.0 / 3.0; ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0; return ret; } private static double transformLon(double x, double y) { double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x)); ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0; ret += (20.0 * sin(x * pi) + 40.0 * sin(x / 3.0 * pi)) * 2.0 / 3.0; ret += (150.0 * sin(x / 12.0 * pi) + 300.0 * sin(x / 30.0 * pi)) * 2.0 / 3.0; return ret; } /** * 地球坐标转换为火星坐标 * World Geodetic System ==> Mars Geodetic System * Map: latitude,longitude * * @param wgs Coordinate 地球坐标 * @return Coordinate 火星坐标 */ public static Coordinate transform2Mars(Coordinate wgs) { Coordinate marsCoordinate = new Coordinate(); double wgLat = wgs.getLatitude(); double wgLon = wgs.getLongitude(); if (CoordinateUtil.outOfChina(wgLat, wgLon)) { marsCoordinate.setLongitude(wgLon); marsCoordinate.setLatitude(wgLat); return marsCoordinate; } // 地球坐标转火星坐标算法 double dLat = transformLat(wgLon - 105.0, wgLat - 35.0); double dLon = transformLon(wgLon - 105.0, wgLat - 35.0); double radLat = wgLat / 180.0 * pi; double magic = sin(radLat); magic = 1 - ee * magic * magic; double sqrtMagic = sqrt(magic); dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi); marsCoordinate.setLongitude(wgLon + dLon); marsCoordinate.setLatitude(wgLat + dLat); return marsCoordinate; } /** * 火星坐标转换为百度坐标 * Mars Geodetic System ==> BaiDu Geodetic System * Map: latitude,longitude * * @param mgs Coordinate 火星坐标 * @return Coordinate 百度坐标 */ public static Coordinate bdEncrypt(Coordinate mgs) { Coordinate bdCoordinate = new Coordinate(); double x = mgs.getLongitude(); double y = mgs.getLatitude(); double z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi); double theta = atan2(y, x) + 0.000003 * cos(x * x_pi); bdCoordinate.setLongitude(z * cos(theta) + 0.0065); bdCoordinate.setLatitude(z * sin(theta) + 0.006); return bdCoordinate; } /** * 百度坐标转火星坐标 * BaiDu Geodetic System ==> Mars Geodetic System * * @param bgs Coordinate 百度坐标 * @return Coordinate 火星坐标 */ public static Coordinate bdDecrypt(Coordinate bgs) { Coordinate marsCoordinate = new Coordinate(); double x = bgs.getLongitude() - 0.0065; double y = bgs.getLatitude() - 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); marsCoordinate.setLongitude(z * cos(theta)); marsCoordinate.setLatitude(z * sin(theta)); return marsCoordinate; } public static void main(String[] args) { // 百度坐标// 116.40727,39.978862 // 高德坐标// 116.400897,39.972546 Coordinate coordinate = new Coordinate(); coordinate.setLongitude(116.40727); coordinate.setLatitude(39.978862); Coordinate marsCoordinate = bdDecrypt(coordinate); System.out.println(marsCoordinate.getLongitude()); System.out.println(marsCoordinate.getLatitude()); }}
0 0
- 各种坐标系转换工具类[java版]
- 常用坐标系转换工具(Java实现)
- 各种经纬度坐标系转换-百度坐标系、火星坐标系、国际坐标系
- 北京54坐标系转换工具
- 西安80坐标系转换工具
- 西安80坐标系转换工具
- iOS开发中的火星坐标系及各种坐标系转换算法
- Jackson工具类(各种转换)
- java版坐标系转换(火星坐标、GPS坐标、百度坐标)
- 工具类,Java转换
- java中各种类型转换成Byte[]的工具方法
- 常用GPS坐标系转换类
- 坐标系转换
- 坐标系转换
- 坐标系转换
- 转换坐标系
- 坐标系转换
- 日期工具,各种相互转换
- 09 操作符重载
- Oracle查询任意时间段内的所有日期,无需建表
- 制定直线方程式和多项式方程式并显示:Django + js + highcharts
- 1093. Count PAT's 解析
- 备份数据库脚本_MySQL
- 各种坐标系转换工具类[java版]
- 转:第一章 常用的缓存技术
- 野指针----内存回收本子----僵尸对象
- es6基础回顾--解构赋值
- Memcache控制台操作获取值
- pptv电话面试
- python处理输入和输出
- H5 CSS基础(1)
- 编写函数: unsigned int reverse_bit(unsigned int value); 这个函数的返回 值value的二进制位模式从左到右翻转后的值。 如: 在32位机器上25