Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable normalize_hrefs to use flexible layouts. #219

Merged
merged 3 commits into from
Oct 28, 2020

Conversation

lossyrob
Copy link
Member

This PR adds the pystac.layout module which enables STACs to layout their HREFs in several ways. Prior to this change, normalize_href would always generate object HREFs according to the best practices documentation - catalogs, collections and items would always have their own directory, with no additional or alternate file structure allowed.

normalize_hrefs now takes an optional HrefLayoutStrategy that can alter its behavior. The default keeps the existing functionality through the BestPracticesLayoutStrategy. Users can supply functions to modify the behavior of one or all of Catalog, Collection or Item HREFs, with a fallback to the default strategy. Additionally there is a TemplateLayoutStrategy which allows users to supply a template string to determine HREFs based on properties of the stac objects.

This templating is also used in a new method on catalogs, generate_subcatalogs. This method uses the same templating logic to generate subdirectories in between an item and its existing parent, which allows for logical grouping of items into subcatalogs based on shared property values.

Additionally, normalize_hrefs was rewritten in such a way that made the recursive fully_resolve unnecessary. The repeated calls to fully_resolve caused unnecessary walks through the catalog, so this change should speed up calls to normalize_hrefs. The method was removed and replaced with resolve_links, which resolves STAC object links (as determined by the _object_links() method on the STAC object, which can be contributed to by extensions) for only that STAC object and does not recurse through the links.

normalize_hrefs was removed from Item, as the method is intended for Catalogs and Collections.

Also included are the addition of two convenience methods - Catalog.add_children and Item.get_collection. Catatlog.clear_children's behavior changes so that the children's parent and root was reset to make it consistent with Catalog.remove_child.

Fixes #151

This commit refactors normalize_hrefs to be based on a layout
strategy. This does not change the default behavior.

normalize_hrefs is removed from Item as the method is intended for use
on a Catalog.

The "fully_resolve" method was causing performance issues and is no
longer needed based on this refactor, and so is dropped. A
"resolve_links" method takes its place, which only resolves the stac
object links of the target object (and does not recurse down to
connected objects).
This method utilizes the new LayoutTemplate functionality to create
subcatalogs based on item properties. This matches functionality that
exists in sat-stac. See issue #151
This adds some test cases and two convenience methods: add_children to
Catalog and get_collection to Item.

It also ensures that when clear_children is called, the items are
modified such that they no longer have parent catalogs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamically create sub-catalogs based on user supplied parameters
1 participant