Last active
November 9, 2021 16:00
-
-
Save pomadchin/7c4c8365e1d3098956acc974f39a4cb6 to your computer and use it in GitHub Desktop.
PySTAC SELF_CONTAINED catalog generation with absolute links in items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "Feature", | |
"stac_version": "1.0.0", | |
"id": "example-item-id", | |
"properties": { | |
"datetime": "2021-11-01T00:00:00Z" | |
}, | |
"geometry": { | |
"type": "Polygon", | |
"coordinates": [ | |
[ | |
[ | |
90.0, | |
0.0 | |
], | |
[ | |
90.0, | |
90.0 | |
], | |
[ | |
0.0, | |
90.0 | |
], | |
[ | |
0.0, | |
0.0 | |
], | |
[ | |
90.0, | |
0.0 | |
] | |
] | |
] | |
}, | |
"links": [ | |
{ | |
"rel": "root", | |
"href": "/fullpath/data/catalog/example-catalog/example-collection-id/collection.json", | |
"type": "application/json" | |
}, | |
{ | |
"rel": "collection", | |
"href": "/fullpath/data/catalog/example-catalog/example-collection-id/collection.json", | |
"type": "application/json" | |
}, | |
{ | |
"rel": "parent", | |
"href": "/fullpath/data/catalog/example-catalog/example-collection-id/collection.json", | |
"type": "application/json" | |
} | |
], | |
"assets": {}, | |
"bbox": [ | |
0, | |
0, | |
90, | |
90 | |
], | |
"stac_extensions": [], | |
"collection": "example-collection-id" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pystac | |
from datetime import datetime, timezone | |
from shapely.geometry import box, mapping | |
def tiny(): | |
# Create a catalog | |
catalog = pystac.Catalog(id="example-catalog-id", description="descr") | |
collection = pystac.Collection( | |
"example-collection-id", | |
"descr", | |
pystac.Extent( | |
spatial=pystac.SpatialExtent([[-180, -90, 180, 90]]), | |
temporal=pystac.TemporalExtent( | |
[[datetime(2020,7,3, tzinfo=timezone.utc), None]] | |
), | |
), | |
license='proprietary' | |
) | |
item = pystac.Item( | |
id="example-item-id", | |
stac_extensions=[], | |
geometry=mapping(box(0, 0, 90, 90)), | |
bbox=[0, 0, 90, 90], | |
datetime=datetime(2021,11,1), | |
properties={} | |
) | |
collection.add_item(item) | |
catalog.add_child(collection) | |
catalog_path = './data/catalog/example-catalog' | |
catalog.normalize_hrefs(catalog_path) | |
catalog.validate_all() | |
print(f'Saving catalog to {catalog_path}...') | |
catalog.save(catalog_type=pystac.CatalogType.SELF_CONTAINED) | |
print("Done!") | |
if __name__ == "__main__": | |
tiny() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jsonschema==4.1.2 | |
pystac==1.1.0 | |
shapely==1.8.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment