How to use the pystac.Extensions 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 / extensions / test_commons.py View on Github external
def test_doesnt_common_metadata_if_not_enabled(self):
        # Test reading from collection
        collection = pystac.read_file(
            TestCases.get_path('data-files/commons/example-collection-without-commons.json'))

        self.assertFalse(collection.ext.implements(pystac.Extensions.COMMONS))

        item = collection.get_item("item-without")

        self.assertFalse(item.ext.implements(pystac.Extensions.COMMONS))
        self.assertTrue(item.ext.implements(pystac.Extensions.EO))

        # Should fail since required EO properties weren't inherited.
        with self.assertRaises(STACValidationError):
            self.validator.validate_object(item)

        # Test reading item directly

        item2 = pystac.read_file(
            TestCases.get_path('data-files/commons/example-item-without-commons.json'))

        self.assertFalse(item2.ext.implements(pystac.Extensions.COMMONS))
github azavea / pystac / tests / extensions / test_commons.py View on Github external
def test_reads_common_metadata_if_enabled(self):
        # Test reading from collection
        collection = pystac.read_file(
            TestCases.get_path('data-files/commons/example-collection-with-commons.json'))

        self.assertTrue(collection.ext.implements(pystac.Extensions.COMMONS))

        item = collection.get_item("item-with")

        self.assertTrue(item.ext.implements(pystac.Extensions.COMMONS))
        self.assertTrue(item.ext.implements(pystac.Extensions.EO))

        self.validator.validate_object(item)

        # Test reading item directly

        item2 = pystac.read_file(
            TestCases.get_path('data-files/commons/example-item-with-commons.json'))

        self.assertTrue(item2.ext.implements(pystac.Extensions.COMMONS))
        self.assertTrue(item2.ext.implements(pystac.Extensions.EO))
github azavea / pystac / tests / extensions / test_view.py View on Github external
def test_apply(self):
        item = next(TestCases.test_case_2().get_all_items())
        with self.assertRaises(ExtensionError):
            item.ext.view

        item.ext.enable(Extensions.VIEW)
        item.ext.view.apply(off_nadir=1.0,
                            incidence_angle=2.0,
                            azimuth=3.0,
                            sun_azimuth=2.0,
                            sun_elevation=1.0)
github azavea / pystac / tests / test_catalog.py View on Github external
cat = Catalog(id='test', description='test catalog')
            image_item = Item(id='Imagery',
                              geometry=RANDOM_GEOM,
                              bbox=RANDOM_BBOX,
                              datetime=datetime.utcnow(),
                              properties={})
            for key in ['ortho', 'dsm']:
                image_item.add_asset(
                    key, Asset(href='some/{}.tif'.format(key), media_type=MediaType.GEOTIFF))

            label_item = Item(id='Labels',
                              geometry=RANDOM_GEOM,
                              bbox=RANDOM_BBOX,
                              datetime=datetime.utcnow(),
                              properties={},
                              stac_extensions=[Extensions.LABEL])
            label_ext = label_item.ext.label
            label_ext.apply(
                label_description='labels',
                label_type='vector',
                label_properties=['label'],
                label_classes=[LabelClasses.create(classes=['one', 'two'], name='label')],
                label_tasks=['classification'])
            label_ext.add_source(image_item, assets=['ortho'])

            cat.add_items([image_item, label_item])

            cat.normalize_hrefs(os.path.join(tmp_dir, 'catalog-full-copy-2-source'))
            cat.save(catalog_type=CatalogType.ABSOLUTE_PUBLISHED)
            cat2 = cat.full_copy()
            cat2.normalize_hrefs(os.path.join(tmp_dir, 'catalog-full-copy-2-dest'))
            cat2.save(catalog_type=CatalogType.ABSOLUTE_PUBLISHED)
github azavea / pystac / tests / extensions / test_projection.py View on Github external
def test_apply(self):
        item = next(TestCases.test_case_2().get_all_items())
        with self.assertRaises(ExtensionError):
            item.ext.proj

        item.ext.enable(Extensions.PROJECTION)
        item.ext.projection.apply(
            4326,
            wkt2=WKT2,
            projjson=PROJJSON,
            geometry=item.geometry,
            bbox=item.bbox,
            centroid={
                'lat': 0.0,
                'lon': 1.0
            },
            shape=[100, 100],
            transform=[30.0, 0.0, 224985.0, 0.0, -30.0, 6790215.0, 0.0, 0.0, 1.0])
github azavea / pystac / pystac / extensions / projection.py View on Github external
def __init__(self, item):
        if item.stac_extensions is None:
            item.stac_extensions = [Extensions.PROJECTION]
        elif Extensions.PROJECTION not in item.stac_extensions:
            item.stac_extensions.append(Extensions.PROJECTION)

        self.item = item
github azavea / pystac / pystac / extensions / eo.py View on Github external
def __init__(self, item):
        if item.stac_extensions is None:
            item.stac_extensions = [Extensions.EO]
        elif Extensions.EO not in item.stac_extensions:
            item.stac_extensions.append(Extensions.EO)

        self.item = item
github azavea / pystac / pystac / extensions / view.py View on Github external
def __init__(self, item):
        if item.stac_extensions is None:
            item.stac_extensions = [Extensions.VIEW]
        elif Extensions.VIEW not in item.stac_extensions:
            item.stac_extensions.append(Extensions.VIEW)

        self.item = item