标签:new java jdk intel file code sts 坐标 经纬度坐标
假设我们拥有了一个栅格边长为5米的栅格的中心点经纬度坐标,如何计算栅格的最大最小经纬度呢?
1)首先,需要把经纬度转化为mercator米坐标:
1 class Geometry(_x: Double, _y: Double) { 2 def x: Double = _x 3 4 def y: Double = _y 5 } 6 7 def lonLat2Mercator_(lon: Double, lat: Double): Geometry = { 8 val x = lon * 20037508.34 / 180; 9 var y = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180) 10 y = y * 20037508.34 / 180 11 new Geometry(x, y) 12 }
2)把栅格中心点换算为mercator米坐标后,可以根据栅格边长算出经、纬度最大、最小mercator坐标值:
var longitude: Double = 120.099878323 var latitude: Double = 30.876723923 var abc = lonLat2Mercator_(longitude, latitude) var dfs: Geometry = mercator2lonLat(new Geometry(abc.x, abc.y)) println(dfs.x) println(dfs.y) var mercatorLngLat = lonLat2Mercator_(longitude, latitude) var minX: Double = mercatorLngLat.x - 2.5 var maxX: Double = mercatorLngLat.x + 2.5 var minY: Double = mercatorLngLat.y - 2.5 var maxY: Double = mercatorLngLat.y + 2.5
3)把米坐标的最大最小经纬度转化为经纬度的最大最小经纬度,即为:栅格的最大最小经纬度。
var leftUpLngLat: Geometry = mercator2lonLat(new Geometry(minX, maxY)) var rightDownLngLat: Geometry = mercator2lonLat(new Geometry(maxX, minY)) var minLng: Double = leftUpLngLat.x var maxLat: Double = leftUpLngLat.y var maxLng: Double = rightDownLngLat.x var minLat: Double = rightDownLngLat.y println(minLng) println(maxLng) println(minLat) println(maxLat)
1 def mercator2lonLat(mercator: Geometry): Geometry = { 2 val x: Double = mercator.x / 20037508.34 * 180 3 var y: Double = mercator.y / 20037508.34 * 180 4 y = 180 / Math.PI * (2 * Math.atan(Math.exp(y * Math.PI / 180)) - Math.PI / 2) 5 6 new Geometry(x, y) 7 }
验证数据结果:
"D:\Program Files\Java\jdk1.8.0_111\bin\java。。。" com.intellij.rt.execution.application.AppMain TestScalaMain 120.099878323 30.876723923000004 120.09985586511787 120.09990078088211 30.87670464799393 30.876743198002185 Process finished with exit code 0
拥有栅格(正方形)经纬度中心点、栅格边长,如何计算最大最小经纬度?
标签:new java jdk intel file code sts 坐标 经纬度坐标
原文地址:http://www.cnblogs.com/yy3b2007com/p/7380797.html