コード例 #1
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_statistics(self) -> None:
        pc_item = pystac.Item.from_file(self.example_uri)

        # Get
        self.assertIn("pc:statistics", pc_item.properties)
        statistics = PointcloudExtension.ext(pc_item).statistics
        assert statistics is not None
        pc_statistics = [s.to_dict() for s in statistics]
        self.assertEqual(pc_statistics, pc_item.properties["pc:statistics"])

        # Set
        stats = [
            Statistic({
                "average": 1,
                "count": 1,
                "maximum": 1,
                "minimum": 1,
                "name": "Test",
                "position": 1,
                "stddev": 1,
                "variance": 1,
            })
        ]
        PointcloudExtension.ext(pc_item).statistics = stats
        self.assertEqual([s.to_dict() for s in stats],
                         pc_item.properties["pc:statistics"])

        # Validate
        pc_item.validate
コード例 #2
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_item_ext_add_to(self) -> None:
        plain_item_uri = TestCases.get_path("data-files/item/sample-item.json")
        item = pystac.Item.from_file(plain_item_uri)
        self.assertNotIn(PointcloudExtension.get_schema_uri(),
                         item.stac_extensions)

        _ = PointcloudExtension.ext(item, add_if_missing=True)

        self.assertIn(PointcloudExtension.get_schema_uri(),
                      item.stac_extensions)
コード例 #3
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
 def test_density(self) -> None:
     pc_item = pystac.Item.from_file(self.example_uri)
     # Get
     self.assertIn("pc:density", pc_item.properties)
     pc_density = PointcloudExtension.ext(pc_item).density
     self.assertEqual(pc_density, pc_item.properties["pc:density"])
     # Set
     density = 100
     PointcloudExtension.ext(pc_item).density = density
     self.assertEqual(density, pc_item.properties["pc:density"])
     # Validate
     pc_item.validate()
コード例 #4
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_type(self) -> None:
        pc_item = pystac.Item.from_file(self.example_uri)

        # Get
        self.assertIn("pc:type", pc_item.properties)
        pc_type = PointcloudExtension.ext(pc_item).type
        self.assertEqual(pc_type, pc_item.properties["pc:type"])

        # Set
        PointcloudExtension.ext(pc_item).type = "sonar"
        self.assertEqual("sonar", pc_item.properties["pc:type"])

        # Validate
        pc_item.validate()
コード例 #5
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_encoding(self) -> None:
        pc_item = pystac.Item.from_file(self.example_uri)

        # Get
        self.assertIn("pc:encoding", pc_item.properties)
        pc_encoding = PointcloudExtension.ext(pc_item).encoding
        self.assertEqual(pc_encoding, pc_item.properties["pc:encoding"])

        # Set
        PointcloudExtension.ext(pc_item).encoding = "binary"
        self.assertEqual("binary", pc_item.properties["pc:encoding"])

        # Validate
        pc_item.validate()
コード例 #6
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_statistics(self) -> None:
        collection = self.collection.clone()
        summaries_ext = PointcloudExtension.summaries(collection, True)
        statistics_list = [
            Statistic({
                "average": 637294.1783,
                "count": 10653336,
                "maximum": 639003.73,
                "minimum": 635577.79,
                "name": "X",
                "position": 0,
                "stddev": 967.9329805,
                "variance": 936894.2548,
            })
        ]

        summaries_ext.statistics = statistics_list

        self.assertEqual(
            summaries_ext.statistics,
            statistics_list,
        )

        summaries_dict = collection.to_dict()["summaries"]

        self.assertEqual(
            summaries_dict["pc:statistics"],
            [s.to_dict() for s in statistics_list],
        )
コード例 #7
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_extension_not_implemented(self) -> None:
        # Should raise exception if Item does not include extension URI
        plain_item_uri = TestCases.get_path("data-files/item/sample-item.json")
        item = pystac.Item.from_file(plain_item_uri)

        with self.assertRaises(pystac.ExtensionNotImplemented):
            _ = PointcloudExtension.ext(item)

        # Should raise exception if owning Item does not include extension URI
        asset = item.assets["thumbnail"]

        with self.assertRaises(pystac.ExtensionNotImplemented):
            _ = PointcloudExtension.ext(asset)

        # Should succeed if Asset has no owner
        ownerless_asset = pystac.Asset.from_dict(asset.to_dict())
        _ = PointcloudExtension.ext(ownerless_asset)
コード例 #8
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_schemas(self) -> None:
        pc_item = pystac.Item.from_file(self.example_uri)

        # Get
        self.assertIn("pc:schemas", pc_item.properties)
        pc_schemas = [
            s.to_dict() for s in PointcloudExtension.ext(pc_item).schemas
        ]
        self.assertEqual(pc_schemas, pc_item.properties["pc:schemas"])

        # Set
        schema = [Schema({"name": "X", "size": 8, "type": "floating"})]
        PointcloudExtension.ext(pc_item).schemas = schema
        self.assertEqual([s.to_dict() for s in schema],
                         pc_item.properties["pc:schemas"])

        # Validate
        pc_item.validate()
コード例 #9
0
ファイル: layer.py プロジェクト: hobu/usgs-lidar
    def add_stac(self, tile):

        if not tile.poly:
            return None

        item = pystac.Item(
            tile.name, mapping(tile.poly), list(tile.poly.bounds),
            datetime.datetime.now(),
            {'description': 'A USGS Lidar pointcloud in Entwine/EPT format'})

        #item.ext.enable(pystac.Extensions.POINTCLOUD)

        # icky
        s = tile.ept['schema']
        p = []
        for d in s:
            p.append(Schema(d))

        PointcloudExtension.add_to(item)
        PointcloudExtension.ext(item).apply(
            tile.num_points,
            PhenomenologyType.LIDAR,
            "ept",
            p,
        )

        ProjectionExtension.add_to(item)
        ProjectionExtension.ext(item).apply(3857, projjson=PROJJSON)

        #        item.ext.pointcloud.apply(tile.num_points, 'lidar', 'ept', p, epsg='EPSG:3857')

        asset = pystac.Asset(tile.url, 'entwine',
                             'The ept.json for accessing data')
        item.add_asset('ept.json', asset)

        item_link = pystac.Link('self',
                                f'{self.args.stac_base_url}{tile.name}.json')
        item_parent = pystac.Link('parent',
                                  f'{self.args.stac_base_url}catalog.json')
        item.add_links([item_link, item_parent])
        return item
コード例 #10
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_count(self) -> None:
        pc_item = pystac.Item.from_file(self.example_uri)

        # Get
        self.assertIn("pc:count", pc_item.properties)
        pc_count = PointcloudExtension.ext(pc_item).count
        self.assertEqual(pc_count, pc_item.properties["pc:count"])

        # Set
        PointcloudExtension.ext(pc_item).count = pc_count + 100
        self.assertEqual(pc_count + 100, pc_item.properties["pc:count"])

        # Validate
        pc_item.validate()

        # Cannot test validation errors until the pointcloud schema.json syntax is fixed
        # Ensure setting bad count fails validation

        with self.assertRaises(pystac.STACValidationError):
            PointcloudExtension.ext(
                pc_item).count = "not_an_int"  # type:ignore
            pc_item.validate()
コード例 #11
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_ext(self) -> None:
        pc_item = pystac.Item.from_file(self.example_uri_no_statistics)
        PointcloudExtension.ext(pc_item)
        asset = Asset(
            "https://github.com/PDAL/PDAL/blob"
            "/a6c986f68458e92414a66c664408bee4737bbb08/test/data/laz"
            "/autzen_trim.laz",
            "laz file",
            "The laz data",
            "application/octet-stream",
            ["data"],
            {"foo": "bar"},
        )
        PointcloudExtension.ext(asset)

        class RandomObject:
            pass

        self.assertRaisesRegex(
            ExtensionTypeError,
            r"^Pointcloud extension does not apply to type 'RandomObject'$",
            PointcloudExtension.ext,
            RandomObject(),
        )
コード例 #12
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_count(self) -> None:
        collection = self.collection.clone()
        summaries_ext = PointcloudExtension.summaries(collection, True)
        count_range = RangeSummary(1000, 10000)

        summaries_ext.count = count_range

        self.assertEqual(
            summaries_ext.count,
            count_range,
        )

        summaries_dict = collection.to_dict()["summaries"]

        self.assertEqual(
            summaries_dict["pc:count"],
            count_range.to_dict(),
        )
コード例 #13
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_density(self) -> None:
        collection = self.collection.clone()
        summaries_ext = PointcloudExtension.summaries(collection, True)
        density_range = RangeSummary(500.0, 1000.0)

        summaries_ext.density = density_range

        self.assertEqual(
            summaries_ext.density,
            density_range,
        )

        summaries_dict = collection.to_dict()["summaries"]

        self.assertEqual(
            summaries_dict["pc:density"],
            density_range.to_dict(),
        )
コード例 #14
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_encoding(self) -> None:
        collection = self.collection.clone()
        summaries_ext = PointcloudExtension.summaries(collection, True)
        encoding_list = ["LASzip"]

        summaries_ext.encoding = encoding_list

        self.assertEqual(
            summaries_ext.encoding,
            encoding_list,
        )

        summaries_dict = collection.to_dict()["summaries"]

        self.assertEqual(
            summaries_dict["pc:encoding"],
            encoding_list,
        )
コード例 #15
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_type(self) -> None:
        collection = self.collection.clone()
        summaries_ext = PointcloudExtension.summaries(collection, True)
        type_list = [PhenomenologyType.LIDAR, "something"]

        summaries_ext.type = type_list

        self.assertEqual(
            summaries_ext.type,
            type_list,
        )

        summaries_dict = collection.to_dict()["summaries"]

        self.assertEqual(
            summaries_dict["pc:type"],
            type_list,
        )
コード例 #16
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
    def test_apply(self) -> None:
        item = next(iter(TestCases.test_case_2().get_all_items()))

        self.assertFalse(PointcloudExtension.has_extension(item))

        PointcloudExtension.add_to(item)
        PointcloudExtension.ext(item).apply(
            1000,
            PhenomenologyType.LIDAR,
            "laszip",
            [Schema({
                "name": "X",
                "size": 8,
                "type": "floating"
            })],
        )
        self.assertTrue(PointcloudExtension.has_extension(item))
コード例 #17
0
ファイル: test_pointcloud.py プロジェクト: stac-utils/pystac
 def test_statistics_accessor_when_no_stats(self) -> None:
     pc_item = pystac.Item.from_file(self.example_uri_no_statistics)
     self.assertEqual(PointcloudExtension.ext(pc_item).statistics, None)