仅使用OSM地图中心和变焦因子的坐标来计算面积边界

发布于 2025-01-29 05:19:46 字数 847 浏览 3 评论 0原文

我正在使用 mapscii (由rastapasta)与Python和Nodejs一起进行项目。我需要在MAPSCII输出中通过其位置渲染一些对象。 MAPSCII使用OSM瓷砖层生成ASCII地图。我只知道地图中心的坐标,变焦级别以及ASCII地图的行/列数。

您是否有有关如何计算边界(左上和右下角)的提示,以便我可以将局部坐标系映射到ACSII数据上?

以这些变量为例:

def calculate_boundaries(lat, lng, zoom, width, height) -> tuple:
    ...

lat = 51.5252178
lng = -0.0925642
zoom = 17
width = 80
height = 24
upper_left, lower_right = calculate_boundaries(lat, lng, zoom, width, height)

我偶然发现了 wiki noreferrer“有帮助,因为我不使用瓷砖数字,而是在纬度/经度上。

// 编辑 这甚至可行吗?还是在每个缩放级别的2D MAPSCII数组中移动时更容易注意到多少LAT/LNG更改?

I'm using MapSCII (by rastapasta) for a project with python and nodejs. I need to render some objects by their location within the MapSCII output. MapSCII uses OSM tile layers to generate the ASCII map. I only know the coordinates of the center of the map, the zoom level as well as the number of rows/columns of the ASCII map.

Do you have any hints on how to calculate the boundaries (upper left and lower right corner), so that I can map a local coordinate system onto the ACSII data?

Take these variables for example:

def calculate_boundaries(lat, lng, zoom, width, height) -> tuple:
    ...

lat = 51.5252178
lng = -0.0925642
zoom = 17
width = 80
height = 24
upper_left, lower_right = calculate_boundaries(lat, lng, zoom, width, height)

I stumbled across this wiki entry, but it does not seem to be helpful, as I do not work with the tile numbers but with latitude/longitude.

// Edit
Is this even feasible? Or would it be easier to note down, how much lat/lng change when moving in the 2D MapSCII array on each zoom level?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2025-02-05 05:19:46

让我们考虑像素的宽度和高度。

计算每个像素的仪表(m/px)
由01(一个)像素表示的距离由:

s = c*cos(y)/2^(z+8)
其中:

c是赤道上地球的圆周;
z是变焦级别;
Y是您想要获得比例的纬度。

来源:

是一个错误,同时转换为Radian。所以我进口了pi和转换。

from math import cos, pi

def calculate_boundaries(lat, lng, zoom, width, height): # -> tuple:
    upper_left, lower_right = {}, {}
    C = 40075 # km - Equator distance around the world
    y = pi * lat / 180 # convert latitude degree to radian
    S = C * cos(y) / 2 ** (zoom + 8) # km distance of 1 px - https://wiki.openstreetmap.org/wiki/Pt:Zoom_levels
    S_deg = S * cos(y) / 100 # convert km (distance of 1 px) to degrees (coordinates)

    upper_left['lat'] = lat + height / 2 * S_deg
    upper_left['lng'] = lng - width / 2 * S_deg

    lower_right['lat'] = lat - height / 2 * S_deg
    lower_right['lng'] = lng + width / 2 * S_deg

    return upper_left, lower_right

# main
lat = 51.5252178
lng = -0.0925642
zoom = 17 # zoom
width = 80 # considered as pixels
height = 24
upper_left, lower_right = calculate_boundaries(lat, lng, zoom, width, height)

print(upper_left, lower_right)

Let's consider width and height in pixels.

Calculation of Meters per Pixel (m/px)
The distance (S) represented by 01 (one) pixel is given by:

S=C*cos(y)/2^(z+8)
Where:

C is the circumference of the Earth at the Equator;
z is the zoom level;
y is the latitude where you want to get the scale.

Source: https://wiki.openstreetmap.org/wiki/Pt:Zoom_levels

There were a mistake while converting degree to radian. So I imported pi and convertion.

from math import cos, pi

def calculate_boundaries(lat, lng, zoom, width, height): # -> tuple:
    upper_left, lower_right = {}, {}
    C = 40075 # km - Equator distance around the world
    y = pi * lat / 180 # convert latitude degree to radian
    S = C * cos(y) / 2 ** (zoom + 8) # km distance of 1 px - https://wiki.openstreetmap.org/wiki/Pt:Zoom_levels
    S_deg = S * cos(y) / 100 # convert km (distance of 1 px) to degrees (coordinates)

    upper_left['lat'] = lat + height / 2 * S_deg
    upper_left['lng'] = lng - width / 2 * S_deg

    lower_right['lat'] = lat - height / 2 * S_deg
    lower_right['lng'] = lng + width / 2 * S_deg

    return upper_left, lower_right

# main
lat = 51.5252178
lng = -0.0925642
zoom = 17 # zoom
width = 80 # considered as pixels
height = 24
upper_left, lower_right = calculate_boundaries(lat, lng, zoom, width, height)

print(upper_left, lower_right)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文