app.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:posm-imagery-api 作者: mojodna 项目源码 文件源码
def read_tile(id, tile, scale=1):
    meta = get_metadata(id)
    approximate_zoom = meta['meta']['approximateZoom']
    bounds = meta['bounds']
    height = meta['meta']['height']
    width = meta['meta']['width']
    zoom_offset = get_zoom_offset(width, height, approximate_zoom)
    min_zoom = approximate_zoom - zoom_offset

    if not min_zoom <= tile.z <= MAX_ZOOM:
        raise InvalidTileRequest('Invalid zoom: {} outside [{}, {}]'.format(tile.z, min_zoom, MAX_ZOOM))

    sw = mercantile.tile(*bounds[0:2], zoom=tile.z)
    ne = mercantile.tile(*bounds[2:4], zoom=tile.z)

    if not sw.x <= tile.x <= ne.x:
        raise InvalidTileRequest('Invalid x coordinate: {} outside [{}, {}]'.format(tile.x, sw.x, ne.x))

    if not ne.y <= tile.y <= sw.y:
        raise InvalidTileRequest('Invalid y coordinate: {} outside [{}, {}]'.format(tile.y, sw.y, ne.y))

    data = render_tile(meta, tile, scale=scale)
    imgarr = np.ma.transpose(data, [1, 2, 0]).astype(np.byte)

    out = StringIO()
    im = Image.fromarray(imgarr, 'RGBA')
    im.save(out, 'png')

    return out.getvalue()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号