gpt4 book ai didi

openstreetmap - 计算 OpenStreetMap 的边界框

转载 作者:行者123 更新时间:2023-12-04 05:21:13 27 4
gpt4 key购买 nike

是否可以从坐标(纬度、经度)、缩放级别和大小(屏幕)获取边界框?我只找到了 calculating bounding box from tile .我需要它,因为 OpenStreetMap 只接受导出模式下的 bbox。我没有这方面的经验,所以我很乐意提供任何建议。谢谢。

编辑:

对不起,我描述错了。我写这样的东西:

(伪代码)
`

x = getX(longitude, zoom); //X Tile - return 41870
y = getY(latitude, zoom); //Y Tile - return 22226
north = getXToLongitude(x, zoom); //return 49.998779
south = getXToLongitude(x + 1, zoom); //return 50.004272
west = getYToLatitude(y, zoom); //return 49.997078
east = getYToLatitude(y + 1, zoom); //return 50.000609

`

但这非常不准确,并且会移动 100 m 的中心。

最佳答案

是的,是的。我遇到了类似的问题,所以我写了它。像这样:

use Math::Trig;

sub getTileNumber {
my ($lat,$lon,$zoom) = @_;
my $xtile = int( ($lon+180)/360 * 2**$zoom ) ;
my $ytile = int( (1 - log(tan(deg2rad($lat)) + sec(deg2rad($lat)))/pi)/2 * 2**$zoom ) ;
return ($xtile, $ytile);
}

sub getLonLat {
my ($xtile, $ytile, $zoom) = @_;
my $n = 2 ** $zoom;
my $lon_deg = $xtile / $n * 360.0 - 180.0;
my $lat_deg = rad2deg(atan(sinh(pi * (1 - 2 * $ytile / $n))));
return ($lon_deg, $lat_deg);
}

# convert from permalink OSM format like:
# http://www.openstreetmap.org/?lat=43.731049999999996&lon=15.79375&zoom=13&layers=M
# to OSM "Export" iframe embedded bbox format like:
# http://www.openstreetmap.org/export/embed.html?bbox=15.7444,43.708,15.8431,43.7541&layer=mapnik

sub LonLat_to_bbox {
my ($lat, $lon, $zoom) = @_;

my $width = 425; my $height = 350; # note: must modify this to match your embed map width/height in pixels
my $tile_size = 256;

my ($xtile, $ytile) = getTileNumber ($lat, $lon, $zoom);

my $xtile_s = ($xtile * $tile_size - $width/2) / $tile_size;
my $ytile_s = ($ytile * $tile_size - $height/2) / $tile_size;
my $xtile_e = ($xtile * $tile_size + $width/2) / $tile_size;
my $ytile_e = ($ytile * $tile_size + $height/2) / $tile_size;

my ($lon_s, $lat_s) = getLonLat($xtile_s, $ytile_s, $zoom);
my ($lon_e, $lat_e) = getLonLat($xtile_e, $ytile_e, $zoom);

my $bbox = "$lon_s,$lat_s,$lon_e,$lat_e";
return $bbox;
}

我也将此信息添加到 OSM wiki ,所以以后会更容易找到......

关于openstreetmap - 计算 OpenStreetMap 的边界框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13669960/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com