morecantile 5.2.3__py3-none-any.whl → 5.3.1__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/__init__.py CHANGED
@@ -8,7 +8,7 @@ Refs:
8
8
 
9
9
  """
10
10
 
11
- __version__ = "5.2.3"
11
+ __version__ = "5.3.1"
12
12
 
13
13
  from .commons import BoundingBox, Coords, Tile # noqa
14
14
  from .defaults import TileMatrixSets, tms # noqa
morecantile/models.py CHANGED
@@ -31,6 +31,7 @@ from morecantile.utils import (
31
31
  _parse_tile_arg,
32
32
  bbox_to_feature,
33
33
  check_quadkey_support,
34
+ lons_contain_antimeridian,
34
35
  meters_per_unit,
35
36
  point_in_bbox,
36
37
  to_rasterio_crs,
@@ -660,6 +661,7 @@ class TileMatrixSet(BaseModel, arbitrary_types_allowed=True):
660
661
  ordered_axes: Optional[List[str]] = None,
661
662
  geographic_crs: pyproj.CRS = WGS84_CRS,
662
663
  screen_pixel_size: float = 0.28e-3,
664
+ decimation_base: int = 2,
663
665
  **kwargs: Any,
664
666
  ):
665
667
  """
@@ -692,8 +694,12 @@ class TileMatrixSet(BaseModel, arbitrary_types_allowed=True):
692
694
  Tile Matrix Set identifier
693
695
  geographic_crs: pyproj.CRS
694
696
  Geographic (lat,lon) coordinate reference system (default is EPSG:4326)
697
+ ordered_axes: list of str, optional
698
+ Override Axis order (e.g `["N", "S"]`) else default to CRS's metadata
695
699
  screen_pixel_size: float, optional
696
700
  Rendering pixel size. 0.28 mm was the actual pixel size of a common display from 2005 and considered as standard by OGC.
701
+ decimation_base: int, optional
702
+ How tiles are divided at each zoom level (default is 2). Must be greater than 1.
697
703
  kwargs: Any
698
704
  Attributes to forward to the TileMatrixSet
699
705
 
@@ -713,6 +719,11 @@ class TileMatrixSet(BaseModel, arbitrary_types_allowed=True):
713
719
  transform = pyproj.Transformer.from_crs(extent_crs, crs, always_xy=True)
714
720
  extent = transform.transform_bounds(*extent, densify_pts=21)
715
721
 
722
+ if decimation_base <= 1:
723
+ raise ValueError(
724
+ "Custom TileMatrixSet requires a decimation base that is greater than 1."
725
+ )
726
+
716
727
  bbox = BoundingBox(*extent)
717
728
  x_origin = bbox.left if not is_inverted else bbox.top
718
729
  y_origin = bbox.top if not is_inverted else bbox.left
@@ -723,8 +734,10 @@ class TileMatrixSet(BaseModel, arbitrary_types_allowed=True):
723
734
  tile_matrices: List[TileMatrix] = []
724
735
  for zoom in range(minzoom, maxzoom + 1):
725
736
  res = max(
726
- width / (tile_width * matrix_scale[0]) / 2.0**zoom,
727
- height / (tile_height * matrix_scale[1]) / 2.0**zoom,
737
+ width / (tile_width * matrix_scale[0]) / float(decimation_base) ** zoom,
738
+ height
739
+ / (tile_height * matrix_scale[1])
740
+ / float(decimation_base) ** zoom,
728
741
  )
729
742
  tile_matrices.append(
730
743
  TileMatrix(
@@ -735,8 +748,8 @@ class TileMatrixSet(BaseModel, arbitrary_types_allowed=True):
735
748
  "pointOfOrigin": [x_origin, y_origin],
736
749
  "tileWidth": tile_width,
737
750
  "tileHeight": tile_height,
738
- "matrixWidth": matrix_scale[0] * 2**zoom,
739
- "matrixHeight": matrix_scale[1] * 2**zoom,
751
+ "matrixWidth": matrix_scale[0] * decimation_base**zoom,
752
+ "matrixHeight": matrix_scale[1] * decimation_base**zoom,
740
753
  }
741
754
  )
742
755
  )
@@ -1240,9 +1253,11 @@ class TileMatrixSet(BaseModel, arbitrary_types_allowed=True):
1240
1253
 
1241
1254
  for w, s, e, n in bboxes:
1242
1255
  # Clamp bounding values.
1243
- w = max(self.bbox.left, w)
1256
+ ws_contain_180th = lons_contain_antimeridian(w, self.bbox.left)
1257
+ es_contain_180th = lons_contain_antimeridian(e, self.bbox.right)
1258
+ w = min(self.bbox.left, w) if ws_contain_180th else max(self.bbox.left, w)
1244
1259
  s = max(self.bbox.bottom, s)
1245
- e = min(self.bbox.right, e)
1260
+ e = max(self.bbox.right, e) if es_contain_180th else min(self.bbox.right, e)
1246
1261
  n = min(self.bbox.top, n)
1247
1262
 
1248
1263
  for z in zooms:
morecantile/utils.py CHANGED
@@ -40,6 +40,30 @@ def _parse_tile_arg(*args) -> Tile:
40
40
  )
41
41
 
42
42
 
43
+ def lons_contain_antimeridian(lon1: float, lon2: float) -> bool:
44
+ """
45
+ Check if the antimeridian (180th meridian) is between two longitude points
46
+
47
+ Parameters
48
+ ----------
49
+ lon1: float
50
+ The first longitude.
51
+ lon2: float
52
+ The second longitude
53
+
54
+ Returns
55
+ -------
56
+ A bool representing whether two longs contain the 180th meridian.
57
+ """
58
+ lon1_clipped = max(-180.0, min(lon1, 180))
59
+ lon2_clipped = max(-180.0, min(lon2, 180))
60
+ lon1_converted = (lon1_clipped + 360) % 360
61
+ lon2_converted = (lon2_clipped + 360) % 360
62
+ ws = [lon1_converted, lon2_converted]
63
+ sorted(ws)
64
+ return ws[0] < 180 < ws[1]
65
+
66
+
43
67
  def meters_per_unit(crs: CRS) -> float:
44
68
  """
45
69
  Coefficient to convert the coordinate reference system (CRS)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: morecantile
3
- Version: 5.2.3
3
+ Version: 5.3.1
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>
@@ -18,6 +18,7 @@ Requires-Dist: attrs
18
18
  Requires-Dist: pyproj~=3.1
19
19
  Requires-Dist: pydantic~=2.0
20
20
  Requires-Dist: pre-commit ; extra == "dev"
21
+ Requires-Dist: bump-my-version ; extra == "dev"
21
22
  Requires-Dist: mkdocs ; extra == "docs"
22
23
  Requires-Dist: mkdocs-material ; extra == "docs"
23
24
  Requires-Dist: pygments ; extra == "docs"
@@ -1,10 +1,10 @@
1
- morecantile/__init__.py,sha256=wcwgjah4uYI6ix_t1YBpqqfE2dkDhfI18E2cuy4qYMg,436
1
+ morecantile/__init__.py,sha256=xp0X6IQ8GGTQkJFJ9m2nrxtfkWW4njt-9MjFRNVKgUA,436
2
2
  morecantile/commons.py,sha256=nOj5f5K5EbDZiC0QTK2f14Mpkz6YIZyCaaUI0S9aWIw,1015
3
3
  morecantile/defaults.py,sha256=9lvHmZ9WM_J5uNCS9VWEy8O5_x2dA2Spvk4H5aHv6UQ,1804
4
4
  morecantile/errors.py,sha256=rhtdpNglfEz5nC8I-BJKUr_gkOwAPwVi1vhLFJ2StYw,907
5
- morecantile/models.py,sha256=LssuG3SB5sNSn5JkT_FlRo0hi6U3PCWuQ63jOxo9zms,50806
5
+ morecantile/models.py,sha256=mRCIDQ2VjMjNigF9mUiPy2oLehGmSSwD3VdVO_OH0Wc,51649
6
6
  morecantile/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- morecantile/utils.py,sha256=J37ixKq_lJC23bqJSAf01mfS-ZEHizvt2uqVE47dPRE,3364
7
+ morecantile/utils.py,sha256=-JUTcrwhT_TEWAPWV8YQBQJoYU2HfVkqQEJaggtnKJg,4020
8
8
  morecantile/data/CDB1GlobalGrid.json,sha256=VDc2ukAWtTQeCdOG8YMqsGO-D7eSzSCN1TEaBn2qLZI,36115
9
9
  morecantile/data/CanadianNAD83_LCC.json,sha256=RuR9z5MjxKzU4KE-CutrzjpWBz9c-XXykKAxcD83veU,7267
10
10
  morecantile/data/EuropeanETRS89_LAEAQuad.json,sha256=pR2Q7eAlLRG74SRdzYhXj19bf5qBvHrE6kzJ5cvko1Q,4679
@@ -21,8 +21,8 @@ morecantile/data/WorldCRS84Quad.json,sha256=l0Wf2faYwzRwO0mG-Tea1Vydpi7V1Oel5L9l
21
21
  morecantile/data/WorldMercatorWGS84Quad.json,sha256=JaqoBSu5qVJmL-J7oSVU1etP2OPWx_aVaTc68dGX0Ec,7001
22
22
  morecantile/scripts/__init__.py,sha256=-CJncfgWDnSZ8au-SJtgX-OFgCddlf7___d91qQcqQM,23
23
23
  morecantile/scripts/cli.py,sha256=zSE15udt2Mb8IR9XB01gm8k_L65ON4_WAkpcJmQazlI,16859
24
- morecantile-5.2.3.dist-info/entry_points.txt,sha256=keoXuYgnX-mdrGWwXIHqEkSZjQK_iAmtmdrtZ3sCT24,59
25
- morecantile-5.2.3.dist-info/LICENSE,sha256=18IxFIta7rF_RcVSIgLUUd_alyfQ9bGoZKQm5vOarGU,1073
26
- morecantile-5.2.3.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
27
- morecantile-5.2.3.dist-info/METADATA,sha256=XlcFVU9Hd8h14s_eho6zY5QrECpXHKgk9eQm3czGfK0,6890
28
- morecantile-5.2.3.dist-info/RECORD,,
24
+ morecantile-5.3.1.dist-info/entry_points.txt,sha256=keoXuYgnX-mdrGWwXIHqEkSZjQK_iAmtmdrtZ3sCT24,59
25
+ morecantile-5.3.1.dist-info/LICENSE,sha256=18IxFIta7rF_RcVSIgLUUd_alyfQ9bGoZKQm5vOarGU,1073
26
+ morecantile-5.3.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
27
+ morecantile-5.3.1.dist-info/METADATA,sha256=1HUu9x4xTg7y2cmoqGghUW127eupnemilcY7gK2UYlE,6938
28
+ morecantile-5.3.1.dist-info/RECORD,,