morecantile 3.2.5__py3-none-any.whl → 4.0.0a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
morecantile/defaults.py CHANGED
@@ -3,12 +3,12 @@
3
3
  import os
4
4
  import pathlib
5
5
  from copy import copy
6
- from typing import Dict, List, Sequence, Union
6
+ from typing import Dict, List, Union
7
7
 
8
8
  import attr
9
9
 
10
- from .errors import InvalidIdentifier
11
- from .models import TileMatrixSet
10
+ from morecantile.errors import InvalidIdentifier
11
+ from morecantile.models import TileMatrixSet
12
12
 
13
13
  morecantile_tms_dir = pathlib.Path(__file__).parent.joinpath("data")
14
14
  tms_paths = list(pathlib.Path(morecantile_tms_dir).glob("*.json"))
@@ -18,7 +18,7 @@ if user_tms_dir:
18
18
  tms_paths.extend(list(pathlib.Path(user_tms_dir).glob("*.json")))
19
19
 
20
20
  default_tms: Dict[str, Union[TileMatrixSet, pathlib.Path]] = {
21
- tms.stem: tms for tms in tms_paths
21
+ tms.stem: tms for tms in sorted(tms_paths)
22
22
  }
23
23
 
24
24
 
@@ -34,6 +34,8 @@ class TileMatrixSets:
34
34
  raise InvalidIdentifier(f"Invalid identifier: {identifier}")
35
35
 
36
36
  tms = self.tms[identifier]
37
+
38
+ # We lazyload the TMS document only when called
37
39
  if isinstance(tms, pathlib.Path):
38
40
  tms = TileMatrixSet.parse_file(tms)
39
41
  self.tms[identifier] = tms
@@ -46,19 +48,15 @@ class TileMatrixSets:
46
48
 
47
49
  def register(
48
50
  self,
49
- custom_tms: Union[TileMatrixSet, Sequence[TileMatrixSet]],
51
+ custom_tms: Dict[str, TileMatrixSet],
50
52
  overwrite: bool = False,
51
53
  ) -> "TileMatrixSets":
52
54
  """Register TileMatrixSet(s)."""
53
- if isinstance(custom_tms, TileMatrixSet):
54
- custom_tms = (custom_tms,)
55
-
56
- for tms in custom_tms:
57
- if tms.identifier in self.tms and not overwrite:
58
- raise Exception(f"{tms.identifier} is already a registered TMS.")
55
+ for identifier in custom_tms.keys():
56
+ if identifier in self.tms and not overwrite:
57
+ raise Exception(f"{identifier} is already a registered TMS.")
59
58
 
60
- new_tms = {tms.identifier: tms for tms in custom_tms}
61
- return TileMatrixSets({**self.tms, **new_tms})
59
+ return TileMatrixSets({**self.tms, **custom_tms})
62
60
 
63
61
 
64
62
  tms = TileMatrixSets(copy(default_tms)) # noqa
morecantile/errors.py CHANGED
@@ -31,3 +31,7 @@ class QuadKeyError(MorecantileError):
31
31
 
32
32
  class InvalidZoomError(MorecantileError):
33
33
  """Raised when input zoom is invalid."""
34
+
35
+
36
+ class DeprecationError(MorecantileError):
37
+ """Raised when TMS version is not 2.0"""