Skip to content

Commit

Permalink
Asset expression indexes (#438)
Browse files Browse the repository at this point in the history
* change asset_expression type and add asset_indexes

* update changelog

* moar docs
  • Loading branch information
vincentsarago authored Oct 18, 2021
1 parent bcc996c commit e1cbc84
Show file tree
Hide file tree
Showing 6 changed files with 587 additions and 113 deletions.
77 changes: 75 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,84 @@ with COGReader(
* update morecantile requirement to version >=3.0 (https://github.com/cogeotiff/rio-tiler/pull/418)
* remove python 3.6 support (https://github.com/cogeotiff/rio-tiler/pull/418)
* remove `max_size` defaults for `COGReader.part` and `COGReader.feature`, which will now default to full resolution reading.
* deprecate `.metadata` methods (https://github.com/cogeotiff/rio-tiler/pull/425)

```python
# before
with COGReader("my.tif") as cog:
img = cog.part(*cog.dataset.bounds, dst_crs=cog.dataset.crs, bounds_crs=cog.dataset.crs)
# by default image should be max 1024x1024
assert max(img.width, 1024) # by default image should be max 1024x1024
assert max(img.height, 1024)

# now (there is no more max_size default)
with COGReader("my.tif") as cog:
img = cog.part(*cog.dataset.bounds, dst_crs=cog.dataset.crs, bounds_crs=cog.dataset.crs)
assert img.width == cog.dataset.width
assert img.height == cog.dataset.height
```

* deprecate `.metadata` and `.stats` methods (https://github.com/cogeotiff/rio-tiler/pull/425)
* add `.statistics` method in base classes (https://github.com/cogeotiff/rio-tiler/pull/427)

* remove `rio_tiler.io.base.SpatialMixin.spatial_info` and `rio_tiler.io.base.SpatialMixin.center` properties (https://github.com/cogeotiff/rio-tiler/pull/429)
* `rio_tiler.io.base.SpatialMixin.bounds` should now be in dataset's CRS (not in `WGS84`) (https://github.com/cogeotiff/rio-tiler/pull/429)

* Reader's `.bounds` property should now be in dataset's CRS, not in `WGS84` (https://github.com/cogeotiff/rio-tiler/pull/429)

```python
# before
with COGReader("my.tif") as cog:
print(cog.bounds)
>>> (-61.287001876638215, 15.537756794450583, -61.27877967704677, 15.542486503997608)

# now
with COGReader("my.tif") as cog:
print(cog.bounds)
>>> (683715.3266400001, 1718548.5702, 684593.2680000002, 1719064.90736)

print(cog.crs)
>>> EPSG:32620

print(cog.geographic_bounds)
>>> (-61.287001876638215, 15.537756794450583, -61.27877967704677, 15.542486503997608)
```

* Use `RIO_TILER_MAX_THREADS` environment variable instead of `MAX_THREADS` (author @rodrigoalmeida94, https://github.com/cogeotiff/rio-tiler/pull/432)
* remove `band_expression` in `rio_tiler.io.base.MultiBandReader` (https://github.com/cogeotiff/rio-tiler/pull/433)
* change `asset_expression` input type from `str` to `Dict[str, str]` in `rio_tiler.io.base.MultiBaseReader` (https://github.com/cogeotiff/rio-tiler/pull/434)

```python
# before
with STACReader("mystac.json") as stac:
img = stac.preview(
assets=("data1", "data2"),
asset_expression="b1*2", # expression was applied to each asset
)

# now
with STACReader("mystac.json") as stac:
img = stac.preview(
assets=("data1", "data2"),
asset_expression={"data1": "b1*2", "data2": "b2*100"}, # we can now pass per asset expression
)
```

* add `asset_indexes` in `rio_tiler.io.base.MultiBaseReader`, which replaces `indexes`. (https://github.com/cogeotiff/rio-tiler/pull/434)

```python
# before
with STACReader("mystac.json") as stac:
img = stac.preview(
assets=("data1", "data2"),
indexes=(1,), # indexes was applied to each asset
)

# now
with STACReader("mystac.json") as stac:
img = stac.preview(
assets=("data1", "data2"),
asset_indexes={"data1": 1, "data2": 2}, # we can now pass per asset indexes
)
```

# 2.1.3 (2021-09-14)

Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,21 @@ At the low level, `rio-tiler` is *just* a wrapper around the [rasterio.vrt.Warpe

with STACReader("item.json") as stac:
print(stac.assets) # available asset
img = stac.tile(x, y, z, assets="asset1", indexes=(1, 2, 3)) # read tile for asset1 and indexes 1,2,3
img = stac.tile(x, y, z, assets=("asset1", "asset2", "asset3",), indexes=(1,)) # create an image from assets 1,2,3 using their first band
img = stac.tile( # read tile for asset1 and indexes 1,2,3
x,
y,
z,
assets="asset1",
indexes=(1, 2, 3),
)

img = stac.tile( # create an image from assets 1,2,3 using their first band
x,
y,
z,
assets=("asset1", "asset2", "asset3",),
asset_indexes={"asset1": 1, "asset2": 1, "asset3": 1},
)
```

- [Mosaic](https://cogeotiff.github.io/rio-tiler/mosaic/) (merging or stacking)
Expand Down
Loading

0 comments on commit e1cbc84

Please sign in to comment.