在Java中计算距离经纬度一定距离的边界框 [英] Calculating bounding box a certain distance away from a lat/long coordinate in Java

查看:555
本文介绍了在Java中计算距离经纬度一定距离的边界框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个坐标(纬度,长度),我试图计算一个方形边界框,该框与该坐标相距给定距离(例如50公里).因此,作为输入,我有纬度,经度和距离,作为输出,我想有两个坐标;一个是西南角(左下角),另一个是东北角(右上角).我在这里看到了几个答案,试图用Python解决这个问题,但是我正在特别寻找Java实现.

Given a coordinate (lat, long), I am trying to calculate a square bounding box that is a given distance (e.g. 50km) away from the coordinate. So as input I have lat, long and distance and as output I would like two coordinates; one being the south-west (bottom-left) corner and one being the north-east (top-right) corner. I have seen a couple of answers on here that try to address this question in Python, but I am looking for a Java implementation in particular.

请明确一点,我打算仅在地球上使用该算法,因此不需要容纳可变半径.

Just to be clear, I intend on using the algorithm on Earth only and so I don't need to accommodate a variable radius.

它不必非常精确(+/- 20%可以),它仅用于计算小距离(不超过150公里)的边界框.因此,我很高兴为有效的算法牺牲一些准确性.非常感谢您的帮助.

It doesn't have to be hugely accurate (+/-20% is fine) and it'll only be used to calculate bounding boxes over small distances (no more than 150km). So I'm happy to sacrifice some accuracy for an efficient algorithm. Any help is much appreciated.

我应该更清楚一些,我的确是正方形,而不是圆形.我了解到,正方形的中心与沿着正方形的周长的各个点之间的距离并不是一个恒定值,就像带圆圈一样.我想我的意思是一个正方形,如果您从中心到外围的四个点中的任何一条画一条线,导致一条线垂直于外围的一侧,那么这四条线的长度相同. /p>

I should have been clearer, I really am after a square, not a circle. I understand that the distance between the center of a square and various points along the square's perimeter is not a constant value like it is with a circle. I guess what I mean is a square where if you draw a line from the center to any one of the four points on the perimeter that results in a line perpendicular to a side of the perimeter, then those 4 lines have the same length.

推荐答案

我写了一篇有关寻找边界坐标的文章:

I wrote an article about finding the bounding coordinates:

http://JanMatuschek.de/LatitudeLongitudeBoundingCoordinates

本文介绍了这些公式,还提供了Java实现. (这也说明了为什么IronMan的最小/最大经度公式不正确.)

The article explains the formulae and also provides a Java implementation. (It also shows why IronMan's formula for the min/max longitude is inaccurate.)

这篇关于在Java中计算距离经纬度一定距离的边界框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆