-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/add point endpoint #150
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
60ec292
add /{lon},{lat}/values endpoints
hrodmn 526a7e3
Merge branch 'main' of https://github.com/stac-utils/titiler-pgstac i…
vincentsarago e56b81b
Merge branch 'main' of https://github.com/stac-utils/titiler-pgstac i…
vincentsarago 19f7ee9
update and lint
vincentsarago 556693c
use custom multi_values method
vincentsarago File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
"""TiTiler.PgSTAC custom Mosaic Backend and Custom STACReader.""" | ||
|
||
import json | ||
from typing import Any, Dict, List, Optional, Tuple, Type | ||
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type | ||
|
||
import attr | ||
import rasterio | ||
|
@@ -17,13 +17,13 @@ | |
from psycopg_pool import ConnectionPool | ||
from rasterio.crs import CRS | ||
from rasterio.warp import transform, transform_bounds, transform_geom | ||
from rio_tiler.constants import WEB_MERCATOR_TMS, WGS84_CRS | ||
from rio_tiler.constants import MAX_THREADS, WEB_MERCATOR_TMS, WGS84_CRS | ||
from rio_tiler.errors import InvalidAssetName, PointOutsideBounds | ||
from rio_tiler.io import Reader | ||
from rio_tiler.io.base import BaseReader, MultiBaseReader | ||
from rio_tiler.models import ImageData | ||
from rio_tiler.models import ImageData, PointData | ||
from rio_tiler.mosaic import mosaic_reader | ||
from rio_tiler.tasks import multi_values | ||
from rio_tiler.tasks import create_tasks, filter_tasks | ||
from rio_tiler.types import AssetInfo, BBox | ||
|
||
from titiler.pgstac.settings import CacheSettings, RetrySettings | ||
|
@@ -33,6 +33,30 @@ | |
retry_config = RetrySettings() | ||
|
||
|
||
def multi_points_pgstac( | ||
asset_list: Sequence[Dict[str, Any]], | ||
reader: Callable[..., PointData], | ||
*args: Any, | ||
threads: int = MAX_THREADS, | ||
allowed_exceptions: Optional[Tuple] = None, | ||
**kwargs: Any, | ||
) -> Dict: | ||
"""Merge values returned from tasks. | ||
|
||
Custom version of `rio_tiler.task.multi_values` which | ||
use constructed `item_id` as dict key. | ||
|
||
""" | ||
tasks = create_tasks(reader, asset_list, threads, *args, **kwargs) | ||
|
||
out: Dict[str, Any] = {} | ||
for val, asset in filter_tasks(tasks, allowed_exceptions=allowed_exceptions): | ||
item_id = f"{asset['collection']}/{asset['id']}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. collection and id are mandatory |
||
out[item_id] = val | ||
|
||
return out | ||
|
||
|
||
@attr.s | ||
class CustomSTACReader(MultiBaseReader): | ||
"""Simplified STAC Reader. | ||
|
@@ -355,16 +379,18 @@ def _reader( | |
item: Dict[str, Any], | ||
lon: float, | ||
lat: float, | ||
coord_crs=coord_crs, | ||
coord_crs: CRS = coord_crs, | ||
**kwargs: Any, | ||
) -> Dict: | ||
) -> PointData: | ||
with self.reader(item, **self.reader_options) as src_dst: | ||
return src_dst.point(lon, lat, coord_crs=coord_crs, **kwargs) | ||
|
||
if "allowed_exceptions" not in kwargs: | ||
kwargs.update({"allowed_exceptions": (PointOutsideBounds,)}) | ||
|
||
return list(multi_values(mosaic_assets, _reader, lon, lat, **kwargs).items()) | ||
return list( | ||
multi_points_pgstac(mosaic_assets, _reader, lon, lat, **kwargs).items() | ||
) | ||
|
||
def part( | ||
self, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now equivalent to https://github.com/developmentseed/titiler/blob/main/src/titiler/mosaic/titiler/mosaic/factory.py#L672-L677 and remove the need of custom model