示例#1
0
def pystac_workaround(uri):
    if uri.startswith('/vsizip/') and not uri.startswith('/vsizip//'):
        uri = uri.replace('/vsizip/', '/vsizip//')
    if uri.startswith(
            '/vsitar/vsigzip/') and not uri.startswith('/vsitar/vsigzip//'):
        uri = uri.replace('/vsitar/vsigzip/', '/vsitar/vsigzip//')

    return uri
    return VsiFileSystem.read_str(uri)
示例#2
0
def root_of_tarball(tarball: str) -> str:
    catalog_root = pystac_workaround(tarball)
    while not (catalog_root.endswith('catalog.json')
               and catalog_root is not None):
        paths = VsiFileSystem.list_paths(catalog_root)
        if len(paths) > 1:
            paths = list(filter(lambda s: s.endswith('catalog.json'), paths))
        if len(paths) != 1:
            raise Exception('Unrecognizable Tarball')
        catalog_root = f'{paths[0]}'
    return catalog_root
def image_sources(item: Item, channel_order: [int]):
    image_keys = [key for key in item.assets.keys() if key.startswith("image")]
    image_keys.sort()
    image_uris = [
        VsiFileSystem.uri_to_vsi_path(item.assets[key].href)
        for key in image_keys
    ]
    return RasterioSourceConfig(
        uris=image_uris,
        channel_order=channel_order,
        transformers=[
            NanTransformerConfig(),
            StatsTransformerConfig(),
        ],
    )
def noop_write_method(uri, txt):
    pass


def pystac_workaround(uri):
    if uri.startswith('/vsizip/') and not uri.startswith('/vsizip//'):
        uri = uri.replace('/vsizip/', '/vsizip//')
    if uri.startswith(
            '/vsitar/vsigzip/') and not uri.startswith('/vsitar/vsigzip//'):
        uri = uri.replace('/vsitar/vsigzip/', '/vsitar/vsigzip//')

    return uri

STAC_IO.read_text_method = \
    lambda uri: VsiFileSystem.read_str(pystac_workaround(uri))
STAC_IO.write_text_method = noop_write_method


def image_sources(item: Item, channel_order: [int]):
    image_keys = [key for key in item.assets.keys() if key.startswith("image")]
    image_keys.sort()
    image_uris = [
        VsiFileSystem.uri_to_vsi_path(item.assets[key].href)
        for key in image_keys
    ]
    return RasterioSourceConfig(
        uris=image_uris,
        channel_order=channel_order,
        transformers=[
            NanTransformerConfig(),
示例#5
0
 def read_text(self, source, *args, **kwargs) -> str:
     return VsiFileSystem.read_str(pystac_workaround(source))