How to use the pystac.STAC_IO function in pystac

To help you get started, we’ve selected a few pystac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github azavea / pystac / tests / serialization / test_migrate.py View on Github external
info = identify_stac_object(d)

                migrated_d, info = migrate_to_latest(d, info)

                migrated_info = identify_stac_object(migrated_d)

                self.assertEqual(migrated_info.object_type, info.object_type)
                self.assertEqual(migrated_info.version_range.latest_valid_version(),
                                 pystac.get_stac_version())
                self.assertEqual(set(migrated_info.common_extensions), set(info.common_extensions))
                self.assertEqual(set(migrated_info.custom_extensions), set(info.custom_extensions))

                # Test that PySTAC can read it without errors.
                if info.object_type != STACObjectType.ITEMCOLLECTION:
                    self.assertIsInstance(STAC_IO.stac_object_from_dict(migrated_d, href=path),
                                          STACObject)
github azavea / pystac / tests / serialization / test_migrate.py View on Github external
def test_migrate(self):
        collection_cache = CollectionCache()
        for example in self.examples:
            with self.subTest(example['path']):
                path = example['path']

                d = STAC_IO.read_json(path)
                if identify_stac_object_type(d) == STACObjectType.ITEM:
                    merge_common_properties(d, json_href=path, collection_cache=collection_cache)

                info = identify_stac_object(d)

                migrated_d, info = migrate_to_latest(d, info)

                migrated_info = identify_stac_object(migrated_d)

                self.assertEqual(migrated_info.object_type, info.object_type)
                self.assertEqual(migrated_info.version_range.latest_valid_version(),
                                 pystac.get_stac_version())
                self.assertEqual(set(migrated_info.common_extensions), set(info.common_extensions))
                self.assertEqual(set(migrated_info.custom_extensions), set(info.custom_extensions))

                # Test that PySTAC can read it without errors.
github azavea / pystac / tests / test_writing.py View on Github external
def validate_catalog_link_type(href, link_type, should_include_self):
            cat_dict = STAC_IO.read_json(href)
            cat = STACObject.from_file(href)
            for link in cat.get_links():
                if not link.rel == 'self':
                    self.assertEqual(link.link_type, link_type)

            rels = set([l['rel'] for l in cat_dict['links']])
            self.assertEqual('self' in rels, should_include_self)

            for child_link in cat.get_child_links():
                child_href = make_absolute_href(child_link.target, href)
                validate_catalog_link_type(child_href, link_type,
                                           catalog_type == CatalogType.ABSOLUTE_PUBLISHED)

            for item_link in cat.get_item_links():
                item_href = make_absolute_href(item_link.target, href)
                validate_item_link_type(item_href, link_type,
github azavea / pystac / tests / serialization / test_identify.py View on Github external
def test_identify(self):
        collection_cache = {}
        for example in self.examples:
            path = example['path']
            d = STAC_IO.read_json(path)

            actual = identify_stac_object(d,
                                          merge_collection_properties=True,
                                          json_href=path,
                                          collection_cache=collection_cache)

            msg = 'Failed {}:'.format(path)

            self.assertEqual(actual.object_type,
                             example['object_type'],
                             msg=msg)
            version_contained_in_range = actual.version_range.contains(
                example['stac_version'])
            self.assertTrue(version_contained_in_range, msg=msg)
            self.assertEqual(set(actual.common_extensions),
                             set(example['common_extensions']),
github azavea / pystac / tests / extensions / test_label.py View on Github external
def test_from_file_pre_081(self):
        d = STAC_IO.read_json(self.label_example_1_uri)

        d['stac_version'] = '0.8.0-rc1'
        d['properties']['label:property'] = d['properties']['label:properties']
        d['properties'].pop('label:properties')
        d['properties']['label:overview'] = d['properties']['label:overviews']
        d['properties'].pop('label:overviews')
        d['properties']['label:method'] = d['properties']['label:methods']
        d['properties'].pop('label:methods')
        d['properties']['label:task'] = d['properties']['label:tasks']
        d['properties'].pop('label:tasks')
        label_example_1 = STAC_IO.stac_object_from_dict(d)

        self.assertEqual(len(label_example_1.ext.label.label_tasks), 2)
github azavea / pystac / tests / utils / validator.py View on Github external
def get_schema(self, obj_type):
        schema_uri = SchemaValidator.schemas.get(obj_type)

        if schema_uri is None:
            raise Exception('No schema for type {}'.format(obj_type))
        schema = self.schema_cache.get(obj_type)
        if schema is None:
            schema = json.loads(STAC_IO.read_text(schema_uri))
            self.schema_cache[obj_type] = schema

        resolver = RefResolver(base_uri=schema_uri, referrer=schema)

        return (schema, resolver)
github azavea / pystac / tests / data-files / get_examples.py View on Github external
def remove_bad_collection(js):
    links = js.get('links')
    if links is not None:
        filtered_links = []
        for link in links:
            rel = link.get('rel')
            if rel is not None and rel == 'collection':
                href = link['href']
                try:
                    json.loads(STAC_IO.read_text(href))
                    filtered_links.append(link)
                except (HTTPError, FileNotFoundError, json.decoder.JSONDecodeError):
                    print('===REMOVING UNREADABLE COLLECTION AT {}'.format(href))
            else:
                filtered_links.append(link)
        js['links'] = filtered_links
    return js
github azavea / pystac / tests / extensions / test_label.py View on Github external
def test_from_file_pre_081(self):
        d = STAC_IO.read_json(self.label_example_1_uri)

        d['stac_version'] = '0.8.0-rc1'
        d['properties']['label:property'] = d['properties']['label:properties']
        d['properties'].pop('label:properties')
        d['properties']['label:overview'] = d['properties']['label:overviews']
        d['properties'].pop('label:overviews')
        d['properties']['label:method'] = d['properties']['label:methods']
        d['properties'].pop('label:methods')
        d['properties']['label:task'] = d['properties']['label:tasks']
        d['properties'].pop('label:tasks')
        label_example_1 = STAC_IO.stac_object_from_dict(d)

        self.assertEqual(len(label_example_1.ext.label.label_tasks), 2)