|
9 | 9 | from pystac.extensions.base import (
|
10 | 10 | ExtensionManagementMixin,
|
11 | 11 | PropertiesExtension,
|
| 12 | + SummariesExtension, |
12 | 13 | )
|
13 | 14 | from pystac.extensions.hooks import ExtensionHooks
|
| 15 | +from pystac.summaries import RangeSummary |
14 | 16 | from pystac.utils import map_opt, get_required
|
15 | 17 |
|
16 | 18 | T = TypeVar("T", pystac.Item, pystac.Asset)
|
@@ -320,9 +322,16 @@ def to_dict(self) -> Dict[str, Any]:
|
320 | 322 | """Returns a JSON-like dictionary representing this ``Statistic``."""
|
321 | 323 | return self.properties
|
322 | 324 |
|
| 325 | + def __eq__(self, o: object) -> bool: |
| 326 | + if not isinstance(o, Statistic): |
| 327 | + return NotImplemented |
| 328 | + return self.to_dict() == o.to_dict() |
| 329 | + |
323 | 330 |
|
324 | 331 | class PointcloudExtension(
|
325 |
| - Generic[T], PropertiesExtension, ExtensionManagementMixin[pystac.Item] |
| 332 | + Generic[T], |
| 333 | + PropertiesExtension, |
| 334 | + ExtensionManagementMixin[Union[pystac.Item, pystac.Collection]], |
326 | 335 | ):
|
327 | 336 | """An abstract class that can be used to extend the properties of an
|
328 | 337 | :class:`~pystac.Item` or :class:`~pystac.Asset` with properties from the
|
@@ -473,6 +482,16 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "PointcloudExtension[T]":
|
473 | 482 | f"Pointcloud extension does not apply to type '{type(obj).__name__}'"
|
474 | 483 | )
|
475 | 484 |
|
| 485 | + @classmethod |
| 486 | + def summaries( |
| 487 | + cls, obj: pystac.Collection, add_if_missing: bool = False |
| 488 | + ) -> "SummariesPointcloudExtension": |
| 489 | + if not add_if_missing: |
| 490 | + cls.validate_has_extension(obj) |
| 491 | + else: |
| 492 | + cls.add_to(obj) |
| 493 | + return SummariesPointcloudExtension(obj) |
| 494 | + |
476 | 495 |
|
477 | 496 | class ItemPointcloudExtension(PointcloudExtension[pystac.Item]):
|
478 | 497 | """A concrete implementation of :class:`PointcloudExtension` on an :class:`~pystac.Item`
|
@@ -513,6 +532,59 @@ def __repr__(self) -> str:
|
513 | 532 | return f"<AssetPointcloudExtension Asset {self.repr_id}>"
|
514 | 533 |
|
515 | 534 |
|
| 535 | +class SummariesPointcloudExtension(SummariesExtension): |
| 536 | + """A concrete implementation of :class:`~SummariesExtension` that extends |
| 537 | + the ``summaries`` field of a :class:`~pystac.Collection` to include properties |
| 538 | + defined in the :stac-ext:`Point Cloud Extension <pointcloud>`. |
| 539 | + """ |
| 540 | + |
| 541 | + @property |
| 542 | + def count(self) -> Optional[RangeSummary[int]]: |
| 543 | + return self.summaries.get_range(COUNT_PROP) |
| 544 | + |
| 545 | + @count.setter |
| 546 | + def count(self, v: Optional[RangeSummary[int]]) -> None: |
| 547 | + self._set_summary(COUNT_PROP, v) |
| 548 | + |
| 549 | + @property |
| 550 | + def type(self) -> Optional[List[Union[PhenomenologyType, str]]]: |
| 551 | + return self.summaries.get_list(TYPE_PROP) |
| 552 | + |
| 553 | + @type.setter |
| 554 | + def type(self, v: Optional[List[Union[PhenomenologyType, str]]]) -> None: |
| 555 | + self._set_summary(TYPE_PROP, v) |
| 556 | + |
| 557 | + @property |
| 558 | + def encoding(self) -> Optional[List[str]]: |
| 559 | + return self.summaries.get_list(ENCODING_PROP) |
| 560 | + |
| 561 | + @encoding.setter |
| 562 | + def encoding(self, v: Optional[List[str]]) -> None: |
| 563 | + self._set_summary(ENCODING_PROP, v) |
| 564 | + |
| 565 | + @property |
| 566 | + def density(self) -> Optional[RangeSummary[float]]: |
| 567 | + return self.summaries.get_range(DENSITY_PROP) |
| 568 | + |
| 569 | + @density.setter |
| 570 | + def density(self, v: Optional[RangeSummary[float]]) -> None: |
| 571 | + self._set_summary(DENSITY_PROP, v) |
| 572 | + |
| 573 | + @property |
| 574 | + def statistics(self) -> Optional[List[Statistic]]: |
| 575 | + return map_opt( |
| 576 | + lambda stats: [Statistic(d) for d in stats], |
| 577 | + self.summaries.get_list(STATISTICS_PROP), |
| 578 | + ) |
| 579 | + |
| 580 | + @statistics.setter |
| 581 | + def statistics(self, v: Optional[List[Statistic]]) -> None: |
| 582 | + self._set_summary( |
| 583 | + STATISTICS_PROP, |
| 584 | + map_opt(lambda stats: [s.to_dict() for s in stats], v), |
| 585 | + ) |
| 586 | + |
| 587 | + |
516 | 588 | class PointcloudExtensionHooks(ExtensionHooks):
|
517 | 589 | schema_uri: str = SCHEMA_URI
|
518 | 590 | prev_extension_ids = {"pointcloud"}
|
|
0 commit comments