瓦片行列号与坐标转换(经纬度、墨卡托)

1.坐标转行列号(经纬度)

def deg2num4490(lon, lat, zoom):
    """
    Lon./lat. to tile numbers
    :param lat: latitude degree
    :param lon: longitude degree
    :param zoom: zoom level
    :return:
    """
    n = 2.0 ** zoom
    x = int((lon + 180.0) / 360.0 * n)
    y = int((90 - lat) / 360.0 * n )
    return x, y

2.行列号转坐标(经纬度)

def num2deg4490(x, y, zoom):
    """
    tile number to lon./lat
    :param x: x tile num
    :param y: y tile num
    :param zoom: zoom level
    :return:the NW-corner of the square. use the function with xtile+1 and ytile+1 to get the other corners.
    """
    n = 2.0 ** zoom
    lon_min = (x / n) * 360.0 - 180.0
    lat_min = 90.0 - (((y + 1) / n) * 360.0)
    lon_max = ((x + 1) / n) * 360.0 - 180.0
    lat_max = 90.0 - ((y / n) * 360.0)
    return lon_min, lat_min, lon_max, lat_max

3.坐标转行列号(墨卡托)

def deg2num3857(lon, lat, zoom):
    """
    Lon./lat. to tile numbers
    :param lat: latitude degree
    :param lon: longitude degree
    :param zoom: zoom level
    :return:
    """
    lat_rad = math.radians(lat)
    n = 2.0 ** zoom
    x = int((lon + 180.0) / 360.0 * n)
    y = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
    return x, y

4.行列号转坐标(墨卡托)

def num2deg3857(x, y, zoom):
    """
    tile number to lon./lat
    :param x: x tile num
    :param y: y tile num
    :param zoom: zoom level
    :return:the NW-corner of the square. use the function with xtile+1 and ytile+1 to get the other corners.
    """
    n = 2.0 ** zoom
    lon_min = x / n * 360.0 - 180.0
    rad_min = math.atan(math.sinh(math.pi * (1 - 2 * (y + 1) / n)))
    lat_min = math.degrees(rad_min)
    lon_max = ((x + 1) / n) * 360.0 - 180.0
    rad_max = math.atan(math.sinh(math.pi * (1 - 2 * y / n)))
    lat_max = math.degrees(rad_max)
    return lon_min, lat_min, lon_max, lat_max
  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值