给定纬度、经度和距离,我想找到一个边界框
给定纬度、经度和距离,我想找到一个距离小于给定距离的边界框。
这里提出了这个问题:如何计算给定纬度/经度位置的边界框?
我不希望它特别准确,因此我将其修改并简化为
def boundingBox(latitudeInDegrees, longitudeInDegrees, halfSideInKm):
lat = math.radians(latitudeInDegrees)
lon = math.radians(longitudeInDegrees)
halfSide = 1000*halfSideInKm
RADIUS_OF_EARTH = 6371
# Radius of the parallel at given latitude
pradius = radius*math.cos(lat)
latMin = lat - halfSide/radius
latMax = lat + halfSide/radius
lonMin = lon - halfSide/pradius
lonMax = lon + halfSide/pradius
rad2deg = math.degrees
return (rad2deg(latMin), rad2deg(lonMin), rad2deg(latMax), rad2deg(lonMax))
但我无法理解这是如何工作的,特别是这条线对我来说没有任何意义 <代码>halfSide = 1000*halfSideInKm
Given a latitude and longitude, and distance, I want to find a bounding box where the distances are less than the given distance.
This questions was asked here: How to calculate the bounding box for a given lat/lng location?
I donot want this partcularly accurate, so I have modified and simplified it to
def boundingBox(latitudeInDegrees, longitudeInDegrees, halfSideInKm):
lat = math.radians(latitudeInDegrees)
lon = math.radians(longitudeInDegrees)
halfSide = 1000*halfSideInKm
RADIUS_OF_EARTH = 6371
# Radius of the parallel at given latitude
pradius = radius*math.cos(lat)
latMin = lat - halfSide/radius
latMax = lat + halfSide/radius
lonMin = lon - halfSide/pradius
lonMax = lon + halfSide/pradius
rad2deg = math.degrees
return (rad2deg(latMin), rad2deg(lonMin), rad2deg(latMax), rad2deg(lonMax))
But I cant understand how this is working, in particular this line makes no sense to me halfSide = 1000*halfSideInKm
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这段代码不太有效,它在 KM 和 M 之间跳转。
修复了代码,使名称更加 PEP8 风格,并添加了一个简单的框对象:
This code didn't quite work, it jumps between KM and M.
Fixed code, made names more PEP8 style, and added a simple box object:
该线将边界框单位从公里转换为米。
That line is converting the bounding box units from kilometres to metres.