-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: add preliminary map tile creation #44
Merged
Merged
Changes from all commits
Commits
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Copyright 2024 Amazon.com, Inc. or its affiliates. | ||
|
||
from abc import ABC, abstractmethod | ||
from collections import namedtuple | ||
from dataclasses import dataclass | ||
|
||
from aws.osml.photogrammetry import GeodeticWorldCoordinate | ||
|
||
MapTileId = namedtuple("TildId", "tile_matrix tile_row tile_col") | ||
MapTileId.__doc__ = """ | ||
This type represents the unique id of a map tile within a map tile set. It is implemented as a named tuple to make | ||
use of that constructs immutability and hashing features. | ||
""" | ||
|
||
MapTileSize = namedtuple("MapTileSize", "width height") | ||
MapTileSize.__doc__ = """ | ||
This type represents the size of a map tile (width, height). These dimensions are typically the same (i.e. square | ||
tiles) but this is not required. | ||
""" | ||
|
||
MapTileBounds = namedtuple("MapTileBounds", "min_lon min_lat max_lon max_lat") | ||
MapTileBounds.__doc__ = """ | ||
This type represents the geodetic bounds of a map tile (min_lon, min_lat, max_lon, max_lat). | ||
""" | ||
|
||
|
||
@dataclass | ||
class MapTile: | ||
""" | ||
This dataclass provides a description of a map tile that is part of a well known tile set. | ||
""" | ||
|
||
id: MapTileId | ||
size: MapTileSize | ||
bounds: MapTileBounds | ||
|
||
|
||
class MapTileSet(ABC): | ||
""" | ||
This class provides an abstract interface to a well known set of map tiles. | ||
""" | ||
|
||
@property | ||
@abstractmethod | ||
def tile_matrix_set_id(self) -> str: | ||
""" | ||
Get the identifier for this map tile set. This is the tile matrix set ID in the OGC definitions. | ||
|
||
:return: the tile matrix set ID | ||
""" | ||
|
||
@abstractmethod | ||
def get_tile(self, tile_id: MapTileId) -> MapTile: | ||
""" | ||
Get a description of the tile identified by a specific map tile ID. | ||
|
||
:param tile_id: the tile ID | ||
:return: the tile description | ||
""" | ||
|
||
@abstractmethod | ||
def get_tile_for_location(self, world_coordinate: GeodeticWorldCoordinate, tile_matrix: int) -> MapTile: | ||
""" | ||
Get a description of the tile containing a specific world location. | ||
|
||
:param world_coordinate: the location in the world | ||
:param tile_matrix: the tile_matrix or zoom level of interest | ||
:return: the tile description | ||
""" | ||
|
||
def get_tile_matrix_limits_for_area( | ||
self, boundary_coordinates: list[GeodeticWorldCoordinate], tile_matrix: int | ||
) -> tuple[int, int, int, int]: | ||
""" | ||
Get a list of all tiles that intersect a specific area. | ||
|
||
:param boundary_coordinates: the boundary of the area | ||
:param tile_matrix: the tile_matrix or zoom level of interest | ||
:return: the (min_col, min_row, max_col, max_row) limits of tiles containing all points | ||
""" | ||
map_tiles_for_corners = [ | ||
self.get_tile_for_location(world_corner, tile_matrix=tile_matrix) for world_corner in boundary_coordinates | ||
] | ||
tile_rows = [tile_id.id.tile_row for tile_id in map_tiles_for_corners] | ||
tile_cols = [tile_id.id.tile_col for tile_id in map_tiles_for_corners] | ||
|
||
return min(tile_cols), min(tile_rows), max(tile_cols), max(tile_rows) |
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.
Should we go back and standardize all our inits to use this all pattern?
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.
The
__all__
list in an init.py defines the set of module names that are imported when someone imports *. The imagery toolkit modules are already making use of this as a way to explicitly define what is part of the public library API and what is not.In this PR if a consumer writes
from aws.osml.image_processing import *
then they will get the names listed here which deliberately excludes the WebMercatorQuadTileSet implementation of MapTileSet. The idea is that users should create these well known tile sets using the factory / enumerated IDs in WellKnownMapTileSet and never need to import or instantiate the concrete implementations directly.