rio-tiler 7.6.1__py3-none-any.whl → 7.7.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.
rio_tiler/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """rio-tiler."""
2
2
 
3
- __version__ = "7.6.1"
3
+ __version__ = "7.7.1"
4
4
 
5
5
  from . import ( # noqa
6
6
  colormap,
rio_tiler/reader.py CHANGED
@@ -58,6 +58,12 @@ def _get_width_height(max_size, dataset_height, dataset_width) -> Tuple[int, int
58
58
  return height, width
59
59
 
60
60
 
61
+ def _missing_size(w: Optional[int] = None, h: Optional[int] = None):
62
+ """Check if one and only one size (width, height) is valid."""
63
+ iterator = iter([w, h])
64
+ return any(iterator) and not any(iterator)
65
+
66
+
61
67
  def _apply_buffer(
62
68
  buffer: float,
63
69
  bounds: BBox,
@@ -124,11 +130,12 @@ def read(
124
130
  """
125
131
  indexes = cast_to_sequence(indexes)
126
132
 
127
- if max_size and width and height:
133
+ if max_size and (width or height):
128
134
  warnings.warn(
129
- "'max_size' will be ignored with with 'height' and 'width' set.",
135
+ "'max_size' will be ignored with with 'height' or 'width' set.",
130
136
  UserWarning,
131
137
  )
138
+ max_size = None
132
139
 
133
140
  io_resampling = Resampling[resampling_method]
134
141
  warp_resampling = Resampling[reproject_method]
@@ -167,12 +174,11 @@ def read(
167
174
  else:
168
175
  dataset = src_dst
169
176
 
170
- if max_size and not (width and height):
171
- height, width = _get_width_height(max_size, dataset.height, dataset.width)
172
-
173
177
  if indexes is None:
174
178
  indexes = non_alpha_indexes(dataset)
175
179
 
180
+ max_height, max_width = dataset.height, dataset.width
181
+
176
182
  boundless = False
177
183
  if window:
178
184
  if isinstance(window, tuple):
@@ -188,6 +194,18 @@ def read(
188
194
  ):
189
195
  boundless = True
190
196
 
197
+ max_height, max_width = window.height, window.width
198
+
199
+ if max_size:
200
+ height, width = _get_width_height(max_size, max_height, max_width)
201
+
202
+ elif _missing_size(width, height):
203
+ ratio = max_height / max_width
204
+ if width:
205
+ height = math.ceil(width * ratio)
206
+ else:
207
+ width = math.ceil(height / ratio)
208
+
191
209
  if ColorInterp.alpha in dataset.colorinterp and nodata is None:
192
210
  # If dataset has an alpha band we need to get the mask using the alpha band index
193
211
  # and then split the data and mask values
@@ -345,11 +363,12 @@ def part(
345
363
  ImageData
346
364
 
347
365
  """
348
- if max_size and width and height:
366
+ if max_size and (width or height):
349
367
  warnings.warn(
350
- "'max_size' will be ignored with with 'height' and 'width' set.",
368
+ "'max_size' will be ignored with with 'height' or 'width' set.",
351
369
  UserWarning,
352
370
  )
371
+ max_size = None
353
372
 
354
373
  if buffer and buffer % 0.5:
355
374
  raise InvalidBufferSize(
@@ -389,9 +408,16 @@ def part(
389
408
  )
390
409
  bounds = array_bounds(vrt_height, vrt_width, vrt_transform)
391
410
 
392
- if max_size and not (width and height):
411
+ if max_size:
393
412
  height, width = _get_width_height(max_size, vrt_height, vrt_width)
394
413
 
414
+ elif _missing_size(width, height):
415
+ ratio = vrt_height / vrt_width
416
+ if width:
417
+ height = math.ceil(width * ratio)
418
+ else:
419
+ width = math.ceil(height / ratio)
420
+
395
421
  height = height or vrt_height
396
422
  width = width or vrt_width
397
423
 
@@ -449,11 +475,18 @@ def part(
449
475
  window = _round_window(window)
450
476
  bounds = windows.bounds(window, src_dst.transform)
451
477
 
452
- if max_size and not (width and height):
478
+ if max_size:
453
479
  height, width = _get_width_height(
454
480
  max_size, round(window.height), round(window.width)
455
481
  )
456
482
 
483
+ elif _missing_size(width, height):
484
+ ratio = window.height / window.width
485
+ if width:
486
+ height = math.ceil(width * ratio)
487
+ else:
488
+ width = math.ceil(height / ratio)
489
+
457
490
  height = height or max(1, round(window.height))
458
491
  width = width or max(1, round(window.width))
459
492
 
rio_tiler/types.py CHANGED
@@ -45,7 +45,7 @@ RIOResampling = Literal[
45
45
  ]
46
46
 
47
47
  # WarpKernel resampling method.
48
- # ref: https://gdal.org/api/gdalwarp_cpp.html#_CPPv4N14GDALWarpKernel9eResampleE
48
+ # ref: https://gdal.org/en/stable/api/gdalwarp_cpp.html#_CPPv415GDALResampleAlg
49
49
  WarpResampling = Literal[
50
50
  "nearest",
51
51
  "bilinear",
@@ -54,6 +54,11 @@ WarpResampling = Literal[
54
54
  "lanczos",
55
55
  "average",
56
56
  "mode",
57
+ "max",
58
+ "min",
59
+ "med",
60
+ "q1",
61
+ "q3",
57
62
  "sum",
58
63
  "rms",
59
64
  ]
rio_tiler/utils.py CHANGED
@@ -417,7 +417,17 @@ def get_vrt_transform(
417
417
  # NOTE: When we have desired output height/width, we can use them to
418
418
  # calculate the output size/transform. The VRT resolution will be aligned with the desired
419
419
  # output resolution (if not bigger)
420
- if height and width:
420
+ if height or width:
421
+ if not height or not width:
422
+ # get the size's ratio of the reprojected dataset
423
+ _w = max(1, round((e - w) / w_res))
424
+ _h = max(1, round((s - n) / h_res))
425
+ ratio = _h / _w
426
+ if width:
427
+ height = math.ceil(width * ratio)
428
+ else:
429
+ width = math.ceil(height / ratio)
430
+
421
431
  output_transform = from_bounds(w, s, e, n, width, height)
422
432
 
423
433
  # NOTE: Here we check if the Output Resolution is higher thant the dataset resolution (OverZoom)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rio-tiler
3
- Version: 7.6.1
3
+ Version: 7.7.1
4
4
  Summary: User friendly Rasterio plugin to read raster datasets.
5
5
  Project-URL: Homepage, https://cogeotiff.github.io/rio-tiler/
6
6
  Project-URL: Documentation, https://cogeotiff.github.io/rio-tiler/
@@ -1,4 +1,4 @@
1
- rio_tiler/__init__.py,sha256=NgOJMHNbvepJT4EulIhtQrgLUPQU3uS4Dz6TrWxuE24,192
1
+ rio_tiler/__init__.py,sha256=JiD_xTZTq-TugZlBpLQ1MOF5lKKzuuXUScj4Ot0TKq8,192
2
2
  rio_tiler/colormap.py,sha256=E2FYp6AysmnSAhj2901XUrgB2q-8OvO8zoe_hmM_UZU,11186
3
3
  rio_tiler/constants.py,sha256=55i-7JZDupTXZdLgxL03KsgM4lAzuGuIVP1zZKktzp0,426
4
4
  rio_tiler/errors.py,sha256=dnaAHPc5VL7SNKXm00gzlrU_4XIuw5rwzD-9Q2kFJsc,2018
@@ -7,10 +7,10 @@ rio_tiler/logger.py,sha256=RR8lnW3uVXkFkPa3nNJS_tTndmdiNNDVXpCDGDxGf0A,81
7
7
  rio_tiler/models.py,sha256=jmFmqrJghjLlPdxceccGvhhsQg9zqkIZUbST6BzAJbQ,27878
8
8
  rio_tiler/profiles.py,sha256=EAx2JdcaOcMw5PZjxbCqQBXXWMac9mjtpHoVFPJEDNQ,1562
9
9
  rio_tiler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- rio_tiler/reader.py,sha256=bUcl68xbnb431oo_nIAOvmPrJBGS3xPfmIdMt_mBvQQ,24156
10
+ rio_tiler/reader.py,sha256=C8IQY91PeBA-p14sDVFIoDYJKmIPZ1GcvJtJSuHmB4U,25119
11
11
  rio_tiler/tasks.py,sha256=tiQo24rZHBVxids40QkNInuMzDFEei08zYW3I_pkSVE,3157
12
- rio_tiler/types.py,sha256=wrGiiGBQ-WdzHf-lEypiH3cub7Knu_rXJw7EWZ2FAS8,1632
13
- rio_tiler/utils.py,sha256=uX8C0RxB_u1sJI3MCvQMdlolDJcWW5G4waU08VfYRF4,30249
12
+ rio_tiler/types.py,sha256=R9XOL-EEb_cwbD4SFNVmViXC84D2p4BEVNCXg0nlh7I,1684
13
+ rio_tiler/utils.py,sha256=iWBm0uoWAbZ1dna5sT1JtjmdvwwVpvB1_uLr0zYbL5M,30611
14
14
  rio_tiler/cmap_data/__init__.py,sha256=8FtVmfpTjXlvhxQ5QesN0UC1m_B3MuF3LbGbhMC5Rw4,1039
15
15
  rio_tiler/cmap_data/accent.npy,sha256=Qde1ldOoXghe4L05v1QbVvnMA1ldwNjKWPf5xCBbmI4,1152
16
16
  rio_tiler/cmap_data/accent_r.npy,sha256=ba-GWSMSPRAcm9CGzlXJeNG4ABbBHDCV602hAWV2idc,1152
@@ -235,8 +235,8 @@ rio_tiler/mosaic/reader.py,sha256=_YBwTJwHvXOzKwpNpOmmh0F4yicyxgWo9vHyof3w_Do,96
235
235
  rio_tiler/mosaic/methods/__init__.py,sha256=tgkXM9skaTLXIm5QFoheOEznQXM97KGflcAWHfkrt1g,612
236
236
  rio_tiler/mosaic/methods/base.py,sha256=9YZJWVRwH5Fk9KO9q5CW52Q8Mf60tAJ21oM4ixEDXBo,1424
237
237
  rio_tiler/mosaic/methods/defaults.py,sha256=z34lna2wGXnAPwculjk_6hDrloqS8wzer68FFoIo7pg,6744
238
- rio_tiler-7.6.1.dist-info/METADATA,sha256=Yl0OYYTGfxeu5aTKJ0WEE1wjk9EN08OMKYH1bRLEeF8,12233
239
- rio_tiler-7.6.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
240
- rio_tiler-7.6.1.dist-info/licenses/AUTHORS.txt,sha256=FCVd4Tjg-8syl0ZugCunpXER8X2-XonW2ZfllyTnRvE,158
241
- rio_tiler-7.6.1.dist-info/licenses/LICENSE,sha256=vq8Tt4KoYQT9JxAjQ4yXMmmhFYRTsBRgrOj-ao-bC5o,1517
242
- rio_tiler-7.6.1.dist-info/RECORD,,
238
+ rio_tiler-7.7.1.dist-info/METADATA,sha256=JLEAxqf-a9ope_eN3cZ1Spa21PV4pFyfzV2nCl2Qgg0,12233
239
+ rio_tiler-7.7.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
240
+ rio_tiler-7.7.1.dist-info/licenses/AUTHORS.txt,sha256=FCVd4Tjg-8syl0ZugCunpXER8X2-XonW2ZfllyTnRvE,158
241
+ rio_tiler-7.7.1.dist-info/licenses/LICENSE,sha256=vq8Tt4KoYQT9JxAjQ4yXMmmhFYRTsBRgrOj-ao-bC5o,1517
242
+ rio_tiler-7.7.1.dist-info/RECORD,,