morecantile 3.2.4__tar.gz → 3.3.0__tar.gz

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.
Files changed (32) hide show
  1. {morecantile-3.2.4 → morecantile-3.3.0}/.bumpversion.cfg +1 -1
  2. morecantile-3.3.0/.pre-commit-config.yaml +34 -0
  3. {morecantile-3.2.4 → morecantile-3.3.0}/PKG-INFO +6 -4
  4. {morecantile-3.2.4 → morecantile-3.3.0}/README.md +5 -3
  5. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/__init__.py +1 -1
  6. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/defaults.py +10 -5
  7. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/models.py +52 -50
  8. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/scripts/cli.py +4 -4
  9. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/utils.py +5 -5
  10. {morecantile-3.2.4 → morecantile-3.3.0}/pyproject.toml +25 -4
  11. morecantile-3.2.4/.flake8 +0 -5
  12. morecantile-3.2.4/.pre-commit-config.yaml +0 -32
  13. morecantile-3.2.4/setup.py +0 -31
  14. {morecantile-3.2.4 → morecantile-3.3.0}/.gitignore +0 -0
  15. {morecantile-3.2.4 → morecantile-3.3.0}/LICENSE +0 -0
  16. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/commons.py +0 -0
  17. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/CanadianNAD83_LCC.json +0 -0
  18. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/EuropeanETRS89_LAEAQuad.json +0 -0
  19. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/LINZAntarticaMapTilegrid.json +0 -0
  20. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/NZTM2000.json +0 -0
  21. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/NZTM2000Quad.json +0 -0
  22. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/README.md +0 -0
  23. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/UPSAntarcticWGS84Quad.json +0 -0
  24. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/UPSArcticWGS84Quad.json +0 -0
  25. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/UTM31WGS84Quad.json +0 -0
  26. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/WGS1984Quad.json +0 -0
  27. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/WebMercatorQuad.json +0 -0
  28. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/WorldCRS84Quad.json +0 -0
  29. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/data/WorldMercatorWGS84Quad.json +0 -0
  30. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/errors.py +0 -0
  31. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/py.typed +0 -0
  32. {morecantile-3.2.4 → morecantile-3.3.0}/morecantile/scripts/__init__.py +0 -0
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 3.2.4
2
+ current_version = 3.3.0
3
3
  commit = True
4
4
  tag = True
5
5
  tag_name = {new_version}
@@ -0,0 +1,34 @@
1
+ repos:
2
+ - repo: https://github.com/abravalheri/validate-pyproject
3
+ rev: v0.12.1
4
+ hooks:
5
+ - id: validate-pyproject
6
+
7
+ - repo: https://github.com/psf/black
8
+ rev: 22.12.0
9
+ hooks:
10
+ - id: black
11
+ language_version: python
12
+
13
+ - repo: https://github.com/PyCQA/isort
14
+ rev: 5.12.0
15
+ hooks:
16
+ - id: isort
17
+ language_version: python
18
+
19
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
20
+ rev: v0.0.238
21
+ hooks:
22
+ - id: ruff
23
+ args: ["--fix"]
24
+
25
+ - repo: https://github.com/pre-commit/mirrors-mypy
26
+ rev: v0.991
27
+ hooks:
28
+ - id: mypy
29
+ language_version: python
30
+ # No reason to run if only tests have changed. They intentionally break typing.
31
+ exclude: tests/.*
32
+ additional_dependencies:
33
+ - types-attrs
34
+ - types-cachetools
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: morecantile
3
- Version: 3.2.4
3
+ Version: 3.3.0
4
4
  Summary: Construct and use map tile grids (a.k.a TileMatrixSet / TMS).
5
5
  Keywords: GIS,TMS,TileMatrixSet,Map Tile
6
6
  Author-email: Vincent Sarago <vincent@developmentseed.com>
@@ -90,12 +90,13 @@ Morecantile is like [mercantile](https://github.com/mapbox/mercantile) (the best
90
90
  ## Install
91
91
 
92
92
  ```bash
93
- $ pip install -U pip
94
- $ pip install morecantile
93
+ $ python -m pip install -U pip
94
+ $ python -m pip install morecantile
95
95
 
96
96
  # Or install from source:
97
97
 
98
- $ pip install git+https://github.com/developmentseed/morecantile.git
98
+ $ python -m pip install -U pip
99
+ $ python -m pip install git+https://github.com/developmentseed/morecantile.git
99
100
  ```
100
101
 
101
102
  ### Defaults Grids
@@ -119,6 +120,7 @@ ref: http://schemas.opengis.net/tms/1.0/json/examples/
119
120
 
120
121
  - [rio-tiler](https://github.com/cogeotiff/rio-tiler): Create tile from raster using Morecantile TMS.
121
122
  - [timvt](https://github.com/developmentseed/timvt): A lightweight PostGIS based dynamic vector tile server.
123
+ - [planetcantile](https://github.com/AndrewAnnex/planetcantile): Tile matrix sets for other planets.
122
124
 
123
125
  ## Changes
124
126
 
@@ -56,12 +56,13 @@ Morecantile is like [mercantile](https://github.com/mapbox/mercantile) (the best
56
56
  ## Install
57
57
 
58
58
  ```bash
59
- $ pip install -U pip
60
- $ pip install morecantile
59
+ $ python -m pip install -U pip
60
+ $ python -m pip install morecantile
61
61
 
62
62
  # Or install from source:
63
63
 
64
- $ pip install git+https://github.com/developmentseed/morecantile.git
64
+ $ python -m pip install -U pip
65
+ $ python -m pip install git+https://github.com/developmentseed/morecantile.git
65
66
  ```
66
67
 
67
68
  ### Defaults Grids
@@ -85,6 +86,7 @@ ref: http://schemas.opengis.net/tms/1.0/json/examples/
85
86
 
86
87
  - [rio-tiler](https://github.com/cogeotiff/rio-tiler): Create tile from raster using Morecantile TMS.
87
88
  - [timvt](https://github.com/developmentseed/timvt): A lightweight PostGIS based dynamic vector tile server.
89
+ - [planetcantile](https://github.com/AndrewAnnex/planetcantile): Tile matrix sets for other planets.
88
90
 
89
91
  ## Changes
90
92
 
@@ -8,7 +8,7 @@ Refs:
8
8
 
9
9
  """
10
10
 
11
- __version__ = "3.2.4"
11
+ __version__ = "3.3.0"
12
12
 
13
13
  from .commons import BoundingBox, Coords, Tile # noqa
14
14
  from .defaults import TileMatrixSets, tms # noqa
@@ -7,8 +7,8 @@ from typing import Dict, List, Sequence, 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"))
@@ -17,8 +17,8 @@ user_tms_dir = os.environ.get("TILEMATRIXSET_DIRECTORY", None)
17
17
  if user_tms_dir:
18
18
  tms_paths.extend(list(pathlib.Path(user_tms_dir).glob("*.json")))
19
19
 
20
- default_tms: Dict[str, TileMatrixSet] = {
21
- tms.stem: TileMatrixSet.parse_file(tms) for tms in tms_paths
20
+ default_tms: Dict[str, Union[TileMatrixSet, pathlib.Path]] = {
21
+ tms.stem: tms for tms in sorted(tms_paths)
22
22
  }
23
23
 
24
24
 
@@ -33,7 +33,12 @@ class TileMatrixSets:
33
33
  if identifier not in self.tms:
34
34
  raise InvalidIdentifier(f"Invalid identifier: {identifier}")
35
35
 
36
- return self.tms[identifier]
36
+ tms = self.tms[identifier]
37
+ if isinstance(tms, pathlib.Path):
38
+ tms = TileMatrixSet.parse_file(tms)
39
+ self.tms[identifier] = tms
40
+
41
+ return tms
37
42
 
38
43
  def list(self) -> List[str]:
39
44
  """List registered TMS."""
@@ -9,14 +9,15 @@ from pyproj import CRS, Transformer
9
9
  from pyproj.enums import WktVersion
10
10
  from pyproj.exceptions import ProjError
11
11
 
12
- from .commons import BoundingBox, Coords, Tile
13
- from .errors import (
12
+ from morecantile.commons import BoundingBox, Coords, Tile
13
+ from morecantile.errors import (
14
14
  InvalidZoomError,
15
+ MorecantileError,
15
16
  NoQuadkeySupport,
16
17
  PointOutsideTMSBounds,
17
18
  QuadKeyError,
18
19
  )
19
- from .utils import (
20
+ from morecantile.utils import (
20
21
  _parse_tile_arg,
21
22
  bbox_to_feature,
22
23
  check_quadkey_support,
@@ -229,7 +230,7 @@ class TileMatrixSet(BaseModel):
229
230
  crs: CRS,
230
231
  tile_width: int = 256,
231
232
  tile_height: int = 256,
232
- matrix_scale: List = [1, 1],
233
+ matrix_scale: Optional[List] = None,
233
234
  extent_crs: Optional[CRS] = None,
234
235
  minzoom: int = 0,
235
236
  maxzoom: int = 24,
@@ -273,6 +274,8 @@ class TileMatrixSet(BaseModel):
273
274
  TileMatrixSet
274
275
 
275
276
  """
277
+ matrix_scale = matrix_scale or [1, 1]
278
+
276
279
  tms: Dict[str, Any] = {
277
280
  "title": title,
278
281
  "identifier": identifier,
@@ -318,15 +321,15 @@ class TileMatrixSet(BaseModel):
318
321
  )
319
322
  tms["tileMatrix"].append(
320
323
  TileMatrix(
321
- **dict(
322
- identifier=str(zoom),
323
- scaleDenominator=res * mpu / 0.00028,
324
- topLeftCorner=[x_origin, y_origin],
325
- tileWidth=tile_width,
326
- tileHeight=tile_height,
327
- matrixWidth=matrix_scale[0] * 2**zoom,
328
- matrixHeight=matrix_scale[1] * 2**zoom,
329
- )
324
+ **{
325
+ "identifier": str(zoom),
326
+ "scaleDenominator": res * mpu / 0.00028,
327
+ "topLeftCorner": [x_origin, y_origin],
328
+ "tileWidth": tile_width,
329
+ "tileHeight": tile_height,
330
+ "matrixWidth": matrix_scale[0] * 2**zoom,
331
+ "matrixHeight": matrix_scale[1] * 2**zoom,
332
+ }
330
333
  )
331
334
  )
332
335
 
@@ -334,45 +337,44 @@ class TileMatrixSet(BaseModel):
334
337
 
335
338
  def matrix(self, zoom: int) -> TileMatrix:
336
339
  """Return the TileMatrix for a specific zoom."""
337
- try:
338
- tile_matrix = list(
339
- filter(lambda m: m.identifier == str(zoom), self.tileMatrix)
340
- )[0]
341
- except IndexError:
342
- matrix_scale = list(
343
- {
344
- round(
345
- self.tileMatrix[idx].scaleDenominator
346
- / self.tileMatrix[idx - 1].scaleDenominator,
347
- 2,
348
- )
349
- for idx in range(1, len(self.tileMatrix))
350
- }
351
- )
352
- if len(matrix_scale) > 1:
353
- raise Exception(
354
- f"TileMatrix not found for level: {zoom} - Unable to construct tileMatrix for TMS with variable scale"
340
+ for m in self.tileMatrix:
341
+ if m.identifier == str(zoom):
342
+ return m
343
+
344
+ matrix_scale = list(
345
+ {
346
+ round(
347
+ self.tileMatrix[idx].scaleDenominator
348
+ / self.tileMatrix[idx - 1].scaleDenominator,
349
+ 2,
355
350
  )
356
-
357
- warnings.warn(
358
- f"TileMatrix not found for level: {zoom} - Creating values from TMS Scale.",
359
- UserWarning,
351
+ for idx in range(1, len(self.tileMatrix))
352
+ }
353
+ )
354
+ if len(matrix_scale) > 1:
355
+ raise InvalidZoomError(
356
+ f"TileMatrix not found for level: {zoom} - Unable to construct tileMatrix for TMS with variable scale"
360
357
  )
361
358
 
362
- tile_matrix = self.tileMatrix[-1]
363
- factor = 1 / matrix_scale[0]
364
- while not str(zoom) == tile_matrix.identifier:
365
- tile_matrix = TileMatrix(
366
- **dict(
367
- identifier=str(int(tile_matrix.identifier) + 1),
368
- scaleDenominator=tile_matrix.scaleDenominator / factor,
369
- topLeftCorner=tile_matrix.topLeftCorner,
370
- tileWidth=tile_matrix.tileWidth,
371
- tileHeight=tile_matrix.tileHeight,
372
- matrixWidth=int(tile_matrix.matrixWidth * factor),
373
- matrixHeight=int(tile_matrix.matrixHeight * factor),
374
- )
375
- )
359
+ warnings.warn(
360
+ f"TileMatrix not found for level: {zoom} - Creating values from TMS Scale.",
361
+ UserWarning,
362
+ )
363
+
364
+ tile_matrix = self.tileMatrix[-1]
365
+ factor = 1 / matrix_scale[0]
366
+ while not str(zoom) == tile_matrix.identifier:
367
+ tile_matrix = TileMatrix(
368
+ **{
369
+ "identifier": str(int(tile_matrix.identifier) + 1),
370
+ "scaleDenominator": tile_matrix.scaleDenominator / factor,
371
+ "topLeftCorner": tile_matrix.topLeftCorner,
372
+ "tileWidth": tile_matrix.tileWidth,
373
+ "tileHeight": tile_matrix.tileHeight,
374
+ "matrixWidth": int(tile_matrix.matrixWidth * factor),
375
+ "matrixHeight": int(tile_matrix.matrixHeight * factor),
376
+ }
377
+ )
376
378
 
377
379
  return tile_matrix
378
380
 
@@ -789,7 +791,7 @@ class TileMatrixSet(BaseModel):
789
791
  self,
790
792
  tile: Tile,
791
793
  fid: Optional[str] = None,
792
- props: Dict = {},
794
+ props: Optional[Dict] = None,
793
795
  buffer: Optional[NumType] = None,
794
796
  precision: Optional[int] = None,
795
797
  projected: bool = False,
@@ -185,7 +185,7 @@ def cli(ctx, verbose, quiet):
185
185
  help="Shift shape x and y values by a constant number",
186
186
  )
187
187
  @click.pass_context
188
- def shapes(
188
+ def shapes( # noqa: C901
189
189
  ctx,
190
190
  input,
191
191
  identifier,
@@ -230,7 +230,7 @@ def shapes(
230
230
  col_xs = []
231
231
  col_ys = []
232
232
 
233
- for i, line in enumerate(iter_lines(src)):
233
+ for _i, line in enumerate(iter_lines(src)):
234
234
  obj = json.loads(line)
235
235
  if isinstance(obj, dict):
236
236
  x, y, z = obj["tile"][:3]
@@ -303,7 +303,7 @@ def shapes(
303
303
  help="Write a RS-delimited JSON sequence (default is LF).",
304
304
  )
305
305
  @click.pass_context
306
- def tiles(ctx, zoom, input, identifier, seq):
306
+ def tiles(ctx, zoom, input, identifier, seq): # noqa: C901
307
307
  """
308
308
  Lists TMS tiles at ZOOM level intersecting
309
309
  GeoJSON [west, south, east, north] bounding boxen, features, or
@@ -507,7 +507,7 @@ def custom(
507
507
  default=None,
508
508
  help="Shift shape x and y values by a constant number",
509
509
  )
510
- def tms_to_geojson(
510
+ def tms_to_geojson( # noqa: C901
511
511
  input,
512
512
  level,
513
513
  precision,
@@ -5,8 +5,8 @@ from typing import Dict, List
5
5
 
6
6
  from pyproj import CRS
7
7
 
8
- from .commons import BoundingBox, Coords, Tile
9
- from .errors import TileArgParsingError
8
+ from morecantile.commons import BoundingBox, Coords, Tile
9
+ from morecantile.errors import TileArgParsingError
10
10
 
11
11
 
12
12
  def _parse_tile_arg(*args) -> Tile:
@@ -59,10 +59,10 @@ def meters_per_unit(crs: CRS) -> float:
59
59
  unit_name = crs.axis_info[0].unit_name
60
60
  try:
61
61
  return unit_factors[unit_name]
62
- except KeyError:
62
+ except KeyError as e:
63
63
  raise Exception(
64
- f"CRS {crs} is not supported, please fill an issue in developmentseed/morecantile"
65
- )
64
+ f"CRS {crs} with Unit Name `{unit_name}` is not supported, please fill an issue in developmentseed/morecantile"
65
+ ) from e
66
66
 
67
67
 
68
68
  def bbox_to_feature(west: float, south: float, east: float, north: float) -> Dict:
@@ -66,6 +66,17 @@ exclude = [
66
66
  "CONTRIBUTING.md",
67
67
  ]
68
68
 
69
+ [tool.coverage.run]
70
+ branch = true
71
+ parallel = true
72
+
73
+ [tool.coverage.report]
74
+ exclude_lines = [
75
+ "no cov",
76
+ "if __name__ == .__main__.:",
77
+ "if TYPE_CHECKING:",
78
+ ]
79
+
69
80
  [tool.isort]
70
81
  profile = "black"
71
82
  known_first_party = ["morecantile"]
@@ -73,8 +84,18 @@ known_third_party = ["rasterio", "pydantic", "pyproj", "mercantile"]
73
84
  default_section = "THIRDPARTY"
74
85
 
75
86
  [tool.mypy]
76
- no_strict_optional = "True"
87
+ no_strict_optional = true
77
88
 
78
- [tool.pydocstyle]
79
- select = "D1"
80
- match = "(?!test).*.py"
89
+ [tool.ruff]
90
+ select = [
91
+ "D1", # pydocstyle errors
92
+ "E", # pycodestyle errors
93
+ "W", # pycodestyle warnings
94
+ "C", # flake8-comprehensions
95
+ "B", # flake8-bugbear
96
+ ]
97
+ ignore = [
98
+ "E501", # line too long, handled by black
99
+ "B008", # do not perform function calls in argument defaults
100
+ "B905", # ignore zip() without an explicit strict= parameter, only support with python >3.10
101
+ ]
morecantile-3.2.4/.flake8 DELETED
@@ -1,5 +0,0 @@
1
- [flake8]
2
- ignore = E501,W503,E203
3
- exclude = .git,__pycache__,docs/source/conf.py,old,build,dist
4
- max-complexity = 12
5
- max-line-length = 90
@@ -1,32 +0,0 @@
1
- repos:
2
- - repo: https://github.com/psf/black
3
- rev: 22.3.0
4
- hooks:
5
- - id: black
6
- language_version: python
7
-
8
- - repo: https://github.com/PyCQA/isort
9
- rev: 5.4.2
10
- hooks:
11
- - id: isort
12
- language_version: python
13
-
14
- - repo: https://github.com/PyCQA/flake8
15
- rev: 3.8.3
16
- hooks:
17
- - id: flake8
18
- language_version: python
19
-
20
- - repo: https://github.com/PyCQA/pydocstyle
21
- rev: 6.1.1
22
- hooks:
23
- - id: pydocstyle
24
- language_version: python
25
- additional_dependencies:
26
- - toml
27
-
28
- - repo: https://github.com/pre-commit/mirrors-mypy
29
- rev: v0.812
30
- hooks:
31
- - id: mypy
32
- language_version: python
@@ -1,31 +0,0 @@
1
- """Fake morecantile setup.py for github."""
2
- import sys
3
-
4
- from setuptools import setup
5
-
6
- sys.stderr.write(
7
- """
8
- ===============================
9
- Unsupported installation method
10
- ===============================
11
- morecantile no longer supports installation with `python setup.py install`.
12
- Please use `python -m pip install .` instead.
13
- """
14
- )
15
- sys.exit(1)
16
-
17
-
18
- # The below code will never execute, however GitHub is particularly
19
- # picky about where it finds Python packaging metadata.
20
- # See: https://github.com/github/feedback/discussions/6456
21
- #
22
- # To be removed once GitHub catches up.
23
-
24
- setup(
25
- name="morecantile",
26
- install_requires=[
27
- "attrs",
28
- "pyproj~=3.1",
29
- "pydantic",
30
- ],
31
- )
File without changes
File without changes