File tree Expand file tree Collapse file tree 7 files changed +42
-11
lines changed Expand file tree Collapse file tree 7 files changed +42
-11
lines changed Original file line number Diff line number Diff line change 6
6
7
7
- Fix handling of optional properties when using apply on view extension ([ #259 ] ( https://github.com/stac-utils/pystac/pull/259 ) )
8
8
9
+ ### Changed
10
+
11
+ - Subclass relevant classes from ` enum.Enum ` . This allows iterating over the class' contents. The ` __str__ ` method is overwritten so this should not break backwards compatibility. ([ #261 ] ( https://github.com/stac-utils/pystac/pull/261 ) )
12
+
9
13
## [ v0.5.4]
10
14
11
15
### Added
Original file line number Diff line number Diff line change 1
1
import os
2
2
from copy import deepcopy
3
+ from enum import Enum
3
4
4
5
import pystac
5
6
from pystac import STACError
10
11
from pystac .utils import (is_absolute_href , make_absolute_href )
11
12
12
13
13
- class CatalogType :
14
+ class CatalogType (str , Enum ):
15
+ def __str__ (self ):
16
+ return str (self .value )
17
+
14
18
SELF_CONTAINED = 'SELF_CONTAINED'
15
19
"""A 'self-contained catalog' is one that is designed for portability.
16
20
Users may want to download a catalog from online and be able to use it on their
@@ -38,8 +42,8 @@ class CatalogType:
38
42
`The best practices documentation on published catalogs <https://github.com/radiantearth/stac-spec/blob/v0.8.1/best-practices.md#published-catalogs>`_
39
43
""" # noqa E501
40
44
41
- @staticmethod
42
- def determine_type (stac_json ):
45
+ @classmethod
46
+ def determine_type (cls , stac_json ):
43
47
"""Determines the catalog type based on a STAC JSON dict.
44
48
45
49
Only applies to Catalogs or Collections
@@ -61,12 +65,12 @@ def determine_type(stac_json):
61
65
62
66
if self_link :
63
67
if relative :
64
- return CatalogType .RELATIVE_PUBLISHED
68
+ return cls .RELATIVE_PUBLISHED
65
69
else :
66
- return CatalogType .ABSOLUTE_PUBLISHED
70
+ return cls .ABSOLUTE_PUBLISHED
67
71
else :
68
72
if relative :
69
- return CatalogType .SELF_CONTAINED
73
+ return cls .SELF_CONTAINED
70
74
else :
71
75
return None
72
76
Original file line number Diff line number Diff line change 1
1
# flake8: noqa
2
+ from enum import Enum
2
3
3
4
4
5
class ExtensionError (Exception ):
@@ -7,8 +8,11 @@ class ExtensionError(Exception):
7
8
pass
8
9
9
10
10
- class Extensions :
11
+ class Extensions ( str , Enum ) :
11
12
"""Enumerates the IDs of common extensions."""
13
+ def __str__ (self ):
14
+ return str (self .value )
15
+
12
16
CHECKSUM = 'checksum'
13
17
COLLECTION_ASSETS = 'collection-assets'
14
18
DATACUBE = 'datacube'
Original file line number Diff line number Diff line change 1
1
"""STAC Model classes for Label extension.
2
2
"""
3
+ from enum import Enum
4
+
3
5
from pystac import STACError
4
6
from pystac .extensions import Extensions
5
7
from pystac .extensions .base import (ItemExtension , ExtensionDefinition , ExtendedObject )
6
8
from pystac .item import (Item , Asset )
7
9
from pystac .link import Link
8
10
9
11
10
- class LabelType :
12
+ class LabelType ( str , Enum ) :
11
13
"""Enumerates valid label types (RASTER or VECTOR)."""
14
+ def __str__ (self ):
15
+ return str (self .value )
16
+
12
17
VECTOR = 'vector'
13
18
RASTER = 'raster'
14
19
Original file line number Diff line number Diff line change 1
1
from copy import (copy , deepcopy )
2
+ from enum import Enum
2
3
3
4
from pystac import STACError
4
5
from pystac .stac_io import STAC_IO
5
6
from pystac .utils import (make_absolute_href , make_relative_href , is_absolute_href )
6
7
7
8
8
- class LinkType :
9
+ class LinkType ( str , Enum ) :
9
10
"""Enumerates link types; used to determine if a link is absolute or relative."""
11
+ def __str__ (self ):
12
+ return str (self .value )
13
+
10
14
ABSOLUTE = 'ABSOLUTE'
11
15
RELATIVE = 'RELATIVE'
12
16
Original file line number Diff line number Diff line change 1
- class MediaType :
1
+ from enum import Enum
2
+
3
+
4
+ class MediaType (str , Enum ):
2
5
"""A list of common media types that can be used in STAC Asset and Link metadata.
3
6
"""
7
+ def __str__ (self ):
8
+ return str (self .value )
9
+
4
10
COG = 'image/tiff; application=geotiff; profile=cloud-optimized'
5
11
GEOJSON = 'application/geo+json'
6
12
GEOPACKAGE = 'application/geopackage+sqlite3'
Original file line number Diff line number Diff line change 1
1
from abc import (ABC , abstractmethod )
2
+ from enum import Enum
2
3
3
4
import pystac
4
5
from pystac import STACError
8
9
from pystac .extensions import ExtensionError
9
10
10
11
11
- class STACObjectType :
12
+ class STACObjectType (str , Enum ):
13
+ def __str__ (self ):
14
+ return str (self .value )
15
+
12
16
CATALOG = 'CATALOG'
13
17
COLLECTION = 'COLLECTION'
14
18
ITEM = 'ITEM'
You can’t perform that action at this time.
0 commit comments