You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it make sense to add support for loading Collection, Item, and ItemCollection objects from pystac? It could be useful in python workflows that generate STAC metadata and load directly into pgstac.
Right now, I do something like this:
importioimportjsonfrompypgstac.dbimportPgstacDBfrompypgstac.loadimportLoader, MethodsfrompystacimportItemCollectionfromstactools.packageimportcreate_item# fire up pgstac loaderdb=PgstacDB()
loader=Loader(db=db)
# create item collectionitem_collection=ItemCollection(
create_item(href) forhrefinhrefs
)
# write to ndjson and load into pgstacbuffer=io.BytesIO()
foriteminitem_collection:
item.collection_id=COLLECTION_ID_FORMAT.format(
region=region.value, product=product.value
)
buffer.write((json.dumps(item.to_dict()) +"\n").encode("utf-8"))
buffer.seek(0)
loader.load_items(buffer, insert_mode=Methods.upsert)
It isn't that hard to write to ndjson and pass that to load_items, but it would be nice if that operation was handled by pypgstac!
The text was updated successfully, but these errors were encountered:
Yeah, that does work. I was thrown off by a bad type hint, I think. Passing a list in does in fact work but my type checker complains about list[Unknown] being incompatible with Iterator[Any]. Maybe this should include Iterable[Any] instead of Iterator[Any]:
true, for read_json that could be Iterable: the code checks for Iterable and iterates over the variable, but never calls iter() on the variable.
However, Iteratorinherits from Iterable, and load_items at least needs the parameter to be an Iterator, so unless you call read_json manually you won't be able to pass the narrower type (I have no idea how to deal with list[Unknown] vs Iterator[Any], though).
Would it make sense to add support for loading
Collection
,Item
, andItemCollection
objects frompystac
? It could be useful in python workflows that generate STAC metadata and load directly intopgstac
.Right now, I do something like this:
It isn't that hard to write to ndjson and pass that to
load_items
, but it would be nice if that operation was handled bypypgstac
!The text was updated successfully, but these errors were encountered: