Skip to content

Instantly share code, notes, and snippets.

@richpsharp
Created April 19, 2020 04:33
Show Gist options
  • Save richpsharp/77e390901c6c266c00f5c2333a835e48 to your computer and use it in GitHub Desktop.
Save richpsharp/77e390901c6c266c00f5c2333a835e48 to your computer and use it in GitHub Desktop.
build a local STAC to upload later
"""Generate a STAC catalog."""
import os
import subprocess
import datetime
import pystac
output = subprocess.check_output(
'gsutil ls gs://my-bucket-with-geotiffs', shell=True)
file_list = [x.rstrip() for x in output.decode('utf-8').split('\n') if x]
catalog = pystac.Catalog(
id='mygsstac',
description='mygsstac',
href='gs://my-bucket-with-geotiffs')
for gs_uri in file_list:
base_id = os.path.basename(os.path.splitext(gs_uri)[0])
item = pystac.Item(
id=base_id,
geometry=None,
bbox=None,
datetime=datetime.datetime.utcnow(),
properties={}
)
item.add_asset(
key=base_id,
asset=pystac.Asset(
href=gs_uri,
media_type=pystac.MediaType.GEOTIFF))
catalog.add_item(item)
catalog.normalize_hrefs('mygsstac')
catalog.save('SELF_CONTAINED')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment