File size: 1,243 Bytes
7f0f541
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
805f17c
7f0f541
 
 
 
 
 
 
 
 
 
 
9ec8204
 
 
805f17c
7f0f541
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json

import numpy as np
import pyproj


def get_metadata(item):
    metadata = item["metadata"]
    if isinstance(metadata, str):
        metadata = json.loads(metadata)
    return metadata


def lat_lon_mid_pixel(item, subset: str):
    metadata = get_metadata(item)
    if subset == "satellogic":
        crs = metadata["crs"][0]
        bounds_crs = metadata["bounds"]
    elif subset == "sentinel_1":
        crs = metadata["crs"]
        bounds_crs = metadata["coordinates"][0]
        assert len(bounds_crs) == 5
        # bounds are a polygon with same first & last vertex
        bounds_crs = (
            bounds_crs[0][0],
            bounds_crs[0][1],
            bounds_crs[2][0],
            bounds_crs[2][1],
        )
    elif subset == "neon":
        crs = metadata["epsg"]
        bounds_crs = metadata["bounds"]

    else:
        raise ValueError("subset not known")

    bounds = pyproj.Transformer.from_crs(crs, "EPSG:4326").transform_bounds(*bounds_crs)
    # dumb average for now
    return np.array([bounds[0] + bounds[2], bounds[1] + bounds[3]]) / 2


def get_google_map_link(item, subset: str):
    lat, lon = lat_lon_mid_pixel(item, subset)
    return f"https://www.google.com/maps?ll={lat},{lon}&z=16&t=k"