rio-tiler 7.7.3.post1__py3-none-any.whl → 7.8.0__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.7.3.post1"
3
+ __version__ = "7.8.0"
4
4
 
5
5
  from . import ( # noqa
6
6
  colormap,
rio_tiler/io/xarray.py CHANGED
@@ -108,7 +108,14 @@ class XarrayReader(BaseReader):
108
108
  self._dims = [
109
109
  d
110
110
  for d in self.input.dims
111
- if d not in [self.input.rio.x_dim, self.input.rio.y_dim]
111
+ if d
112
+ not in [
113
+ self.input.rio.x_dim,
114
+ self.input.rio.y_dim,
115
+ "spatial_ref",
116
+ "crs_wkt",
117
+ "grid_mapping",
118
+ ]
112
119
  ]
113
120
  assert len(self._dims) in [0, 1], "Can't handle >=4D DataArray"
114
121
 
@@ -130,9 +137,20 @@ class XarrayReader(BaseReader):
130
137
  `Bands` are all dimensions not defined as spatial dims by rioxarray.
131
138
  """
132
139
  if not self._dims:
133
- coords_name = list(self.input.coords)
134
- if len(coords_name) > 3 and (coord := coords_name[2]):
135
- return [str(self.input.coords[coord].data)]
140
+ coords_name = [
141
+ d
142
+ for d in self.input.coords
143
+ if d
144
+ not in [
145
+ self.input.rio.x_dim,
146
+ self.input.rio.y_dim,
147
+ "spatial_ref",
148
+ "crs_wkt",
149
+ "grid_mapping",
150
+ ]
151
+ ]
152
+ if coords_name:
153
+ return [str(self.input.coords[coords_name[0]].data)]
136
154
 
137
155
  return [self.input.name or "array"]
138
156
 
rio_tiler/models.py CHANGED
@@ -6,6 +6,7 @@ from typing import Any, Dict, List, Literal, Optional, Sequence, Tuple, Union
6
6
 
7
7
  import attr
8
8
  import numpy
9
+ import rasterio
9
10
  from affine import Affine
10
11
  from color_operations import parse_operations, scale_dtype, to_math_type
11
12
  from numpy.typing import NDArray
@@ -719,6 +720,42 @@ class ImageData:
719
720
 
720
721
  return render(array.data, img_format=img_format, colormap=colormap, **kwargs)
721
722
 
723
+ def to_raster(self, dst_path: str, *, driver: str = "GTIFF", **kwargs: Any) -> None:
724
+ """Save ImageData array to file."""
725
+ if driver.upper() == "GTIFF":
726
+ if "transform" not in kwargs:
727
+ kwargs.update({"transform": self.transform})
728
+ if "crs" not in kwargs and self.crs:
729
+ kwargs.update({"crs": self.crs})
730
+
731
+ write_nodata = "nodata" in kwargs
732
+ count, height, width = self.array.shape
733
+
734
+ output_profile = {
735
+ "dtype": self.array.dtype,
736
+ "count": count if write_nodata else count + 1,
737
+ "height": height,
738
+ "width": width,
739
+ }
740
+ output_profile.update(kwargs)
741
+
742
+ with warnings.catch_warnings():
743
+ warnings.filterwarnings(
744
+ "ignore",
745
+ category=NotGeoreferencedWarning,
746
+ module="rasterio",
747
+ )
748
+ with rasterio.open(dst_path, "w", driver=driver, **output_profile) as dst:
749
+ dst.write(self.data, indexes=list(range(1, count + 1)))
750
+
751
+ # Use Mask as an alpha band
752
+ if not write_nodata:
753
+ if ColorInterp.alpha not in dst.colorinterp:
754
+ dst.colorinterp = *dst.colorinterp[:-1], ColorInterp.alpha
755
+ dst.write(self.mask.astype(self.array.dtype), indexes=count + 1)
756
+
757
+ return
758
+
722
759
  def statistics(
723
760
  self,
724
761
  categorical: bool = False,
@@ -750,7 +787,7 @@ class ImageData:
750
787
  shape_crs: CRS = WGS84_CRS,
751
788
  cover_scale: int = 10,
752
789
  ) -> NDArray[numpy.floating]:
753
- """Post-process image data.
790
+ """Get Coverage array for a Geometry.
754
791
 
755
792
  Args:
756
793
  shape (Dict): GeoJSON geometry or Feature.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rio-tiler
3
- Version: 7.7.3.post1
3
+ Version: 7.8.0
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,10 +1,10 @@
1
- rio_tiler/__init__.py,sha256=RiZ2fKC2ocRa--hhqbeoXia1GsdgdoppjH8AgLcvOwY,198
1
+ rio_tiler/__init__.py,sha256=JBCQOMSAnUU1ySXF8RvZOBGCO0dOy-s0IH8nrhkN4vU,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
5
5
  rio_tiler/expression.py,sha256=EVHWgjMqIn4TTPfqT_HV1RWCQlxqOj3OtEr1iUDiFHE,2282
6
6
  rio_tiler/logger.py,sha256=RR8lnW3uVXkFkPa3nNJS_tTndmdiNNDVXpCDGDxGf0A,81
7
- rio_tiler/models.py,sha256=jmFmqrJghjLlPdxceccGvhhsQg9zqkIZUbST6BzAJbQ,27878
7
+ rio_tiler/models.py,sha256=_4JaeOrGInIKJqLSWhM_EZPoB8X8RRPSrR1FIel7Lmk,29293
8
8
  rio_tiler/profiles.py,sha256=EAx2JdcaOcMw5PZjxbCqQBXXWMac9mjtpHoVFPJEDNQ,1562
9
9
  rio_tiler/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  rio_tiler/reader.py,sha256=nWw1Eq7I06zvYrizXvSMkXjd2g3HpeW8XNMc1okwLR8,25153
@@ -229,14 +229,14 @@ rio_tiler/io/__init__.py,sha256=_L4iILm6vSiJ14GEDDOvkuUHRtbWC9oqx6Bu8PxHhvA,270
229
229
  rio_tiler/io/base.py,sha256=nyaAtfodM-5fXd1WsGG5Qh544PNv9Hy4FLQ_nPj8hw8,52154
230
230
  rio_tiler/io/rasterio.py,sha256=4j4ffxsBHD7wg2R1p6x6JE_7UZjMZQGx29qtO6JEs8U,29636
231
231
  rio_tiler/io/stac.py,sha256=kIEW4F71PouXF-Ubpz-VVXujnp8LqftptPKDo_J3BTw,12831
232
- rio_tiler/io/xarray.py,sha256=ia1bstgTg_lnpV5JMqeFnoem8F8CVYJpoxllWGVrhjk,22789
232
+ rio_tiler/io/xarray.py,sha256=O203gjfzkl61IK8amlR-BhIPS26JX-NZq7ZIby2DJG8,23211
233
233
  rio_tiler/mosaic/__init__.py,sha256=Yj6CKpnFl8PJhLSp-a55wo33hKZ8-6OOBJtWA1HZVy8,118
234
234
  rio_tiler/mosaic/reader.py,sha256=KSk6DaUJRN4Ye8lJ-V12sl5i2FN6y9o4wS1GzVSmtgU,10694
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=P-zSVVgvQ2oRiMchC3bMqIYLTX7H3743jsD_VmqStxM,7642
238
- rio_tiler-7.7.3.post1.dist-info/METADATA,sha256=4NXadjaAy_I9zq71dSp_Wcv0u4fd8wcNFhWOR-bn7-s,12239
239
- rio_tiler-7.7.3.post1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
240
- rio_tiler-7.7.3.post1.dist-info/licenses/AUTHORS.txt,sha256=FCVd4Tjg-8syl0ZugCunpXER8X2-XonW2ZfllyTnRvE,158
241
- rio_tiler-7.7.3.post1.dist-info/licenses/LICENSE,sha256=vq8Tt4KoYQT9JxAjQ4yXMmmhFYRTsBRgrOj-ao-bC5o,1517
242
- rio_tiler-7.7.3.post1.dist-info/RECORD,,
238
+ rio_tiler-7.8.0.dist-info/METADATA,sha256=u8DsPe_CzDjuwjitdk69RAujEHxNM6TcSXQxgriFXBs,12233
239
+ rio_tiler-7.8.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
240
+ rio_tiler-7.8.0.dist-info/licenses/AUTHORS.txt,sha256=FCVd4Tjg-8syl0ZugCunpXER8X2-XonW2ZfllyTnRvE,158
241
+ rio_tiler-7.8.0.dist-info/licenses/LICENSE,sha256=vq8Tt4KoYQT9JxAjQ4yXMmmhFYRTsBRgrOj-ao-bC5o,1517
242
+ rio_tiler-7.8.0.dist-info/RECORD,,