百度地图bd09II坐标转换天地图CGCS2000坐标

// 百度坐标系转大地坐标系
export const coordinateTransformation: any = {
	BD09II2WGS84(bdLon: number, bdLat: number) {
		let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
		//百度坐标转成火星坐标
		let mars_point = { lat: 0, lon: 0,};
		let x = bdLon - 0.0065;
		let y = bdLat - 0.006;
		let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
		let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
		mars_point.lat = z * Math.sin(theta);
		mars_point.lon = z * Math.cos(theta);

		//把火星坐标GCJ02转地球坐标系WGS84
		let gcjLat =  mars_point.lat;
		let gcjLon = mars_point.lon;
		let d = this.delta(gcjLat, gcjLon)
		return {
			'lat': ( gcjLat - d.lat ),
			'lon': ( gcjLon - d.lon )
		}
	},
	delta(lat: number, lon: number) {
		let PI = 3.14159265358979324;
		let a = 6378245.0 
		let ee = 0.00669342162296594323 
		let dLat = this.transformLat(lon - 105.0, lat - 35.0)
		let dLon = this.transformLon(lon - 105.0, lat - 35.0)
		let radLat = lat / 180.0 * PI
		let magic = Math.sin(radLat)
		magic = 1 - ee * magic * magic
		let sqrtMagic = Math.sqrt(magic)
		dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI)
		dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * PI)
		return {
			'lat': dLat,
			'lon': dLon
		}
	},
	transformLat(x: number, y: number) {
		let PI = 3.14159265358979324;
		let ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x))
		ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0
		ret += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0
		ret += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0
		return ret
	},
	transformLon(x: number, y: number) {
		let PI = 3.14159265358979324;
		let ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x))
		ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0
		ret += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0
		ret += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0
		return ret
	}
}

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
WSG84(World Geodetic System 1984)和CGCS2000(中国大地坐标系统2000)是两种常用的地理坐标系。在Java中将WSG84转换为CGCS2000可以通过使用坐标转换库来实现。 首先,我们需要确定所使用的坐标转换库。Java中有许多开源的坐标转换库可以使用,例如Geotools和Proj4j。这里以使用Geotools为例进行说明。 在使用Geotools进行坐标转换之前,我们需要先导入相关的库文件。可以在Maven项目中的pom.xml文件中添加以下依赖项: ```xml <dependency> <groupId>org.geotools</groupId> <artifactId>gt-epsg-hsql</artifactId> <version>24.1</version> </dependency> ``` 接下来,我们可以使用以下代码将WSG84坐标转换CGCS2000坐标: ```java import org.geotools.geometry.DirectPosition2D; import org.geotools.referencing.CRS; import org.opengis.referencing.FactoryException; import org.opengis.referencing.NoSuchAuthorityCodeException; import org.opengis.referencing.crs.CoordinateReferenceSystem; public class CoordinateConversion { public static void main(String[] args) { // 输入的坐标点(WSG84) double longitude = 116.3975; double latitude = 39.9085; // 设置源坐标系(WSG84) CoordinateReferenceSystem sourceCRS; try { sourceCRS = CRS.decode("EPSG:4326"); } catch (NoSuchAuthorityCodeException | FactoryException e) { e.printStackTrace(); return; } // 设置目标坐标系(CGCS2000) CoordinateReferenceSystem targetCRS; try { targetCRS = CRS.decode("EPSG:4490"); } catch (NoSuchAuthorityCodeException | FactoryException e) { e.printStackTrace(); return; } // 创建源坐标点 DirectPosition2D sourcePosition = new DirectPosition2D(sourceCRS, longitude, latitude); // 坐标转换 try { DirectPosition2D targetPosition = (DirectPosition2D) CRS.transform(sourcePosition, targetCRS); double targetLongitude = targetPosition.x; double targetLatitude = targetPosition.y; System.out.println("转换后的坐标CGCS2000):"); System.out.println("经度:" + targetLongitude); System.out.println("纬度:" + targetLatitude); } catch (Exception e) { e.printStackTrace(); } } } ``` 上述代码中,首先设置源坐标系为WSG84(EPSG:4326)和目标坐标系为CGCS2000(EPSG:4490),然后创建源坐标点并利用`CRS.transform()`方法进行坐标转换。 运行上述代码后,将输出转换后的CGCS2000坐标,包括经度和纬度。 需要注意的是,WSG84和CGCS2000坐标系定义可能因使用的地理坐标转换库而有所不同,可以根据实际情况进行相应的调整。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值