天地图根据经纬度坐标计算瓦片行列号(python)

  • Post author:
  • Post category:python


def get_tianditu_info(rect_pts, zoom):
    """
    根据经纬度计算行列号
    :param rect_pts: 矩形框坐标 例[a,b,c,d]左上点,右下点
    :param zoom:地图层级
    :return:
    """

    resolution = {18: 5.36441802978515E-06,
                  17: 1.07288360595703E-05,
                  16: 2.1457672119140625E-05,
                  15: 4.29153442382814E-05,
                  14: 8.58306884765629E-05,
                  13: 0.000171661376953125,
                  12: 0.00034332275390625,
                  11: 0.0006866455078125,
                  10: 0.001373291015625,
                  9: 0.00274658203125,
                  8: 0.0054931640625,
                  7: 0.010986328125,
                  6: 0.02197265625,
                  5: 0.0439453125,
                  4: 0.087890625,
                  3: 0.17578125,
                  2: 0.3515625,
                  1: 0.703125}
    # 经纬度反算切片行列号
    start_x = math.floor((rect_pts[0] + 180.0) / (resolution[zoom] * 256))
    start_y = math.floor((90.0 - rect_pts[1]) / (resolution[zoom] * 256))
    end_x = math.ceil((rect_pts[2] + 180.0) / (resolution[zoom] * 256))
    end_y = math.ceil((90.0 - rect_pts[3]) / (resolution[zoom] * 256))
    result = [start_x, start_y, end_x, end_y]
    return result



版权声明:本文为yhj101096原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。