Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Nov 16, 2023
1 parent d56b7d8 commit e5eff80
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions rio_tiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from rasterio.dtypes import _gdal_typename
from rasterio.enums import ColorInterp, MaskFlags, Resampling
from rasterio.errors import NotGeoreferencedWarning
from rasterio.features import bounds as featureBounds
from rasterio.features import is_valid_geom
from rasterio.io import DatasetReader, DatasetWriter, MemoryFile
from rasterio.rio.helpers import coords
Expand Down Expand Up @@ -223,27 +222,17 @@ def get_overview_level(
return ovr_idx


def bbox_to_feature(west: float, south: float, east: float, north: float) -> Dict:
"""Create a GeoJSON feature from a bbox."""
return {
"type": "Polygon",
"coordinates": [
[[west, south], [west, north], [east, north], [east, south], [west, south]]
],
}


def _cheap_transform_calculation(src, dst_crs: CRS) -> Affine:
center = ((src.bounds[1] + src.bounds[3]) / 2, (src.bounds[0] + src.bounds[2]) / 2)
"""Get X,Y resolution by transforming the bbox of one pixel at the center of the dataset."""
center = ((src.bounds[0] + src.bounds[2]) / 2, (src.bounds[1] + src.bounds[3]) / 2)
xres, yres = src.res[0] / 2, src.res[1] / 2
geom = bbox_to_feature(
bbox = (
center[0] - xres,
center[1] - yres,
center[0] + xres,
center[1] + xres,
)
out = transform_geom(src.crs, dst_crs, geom)
bbox = featureBounds(out)
bbox = transform_bounds(src.crs, dst_crs, *bbox)
xres = bbox[2] - bbox[0]
yres = bbox[3] - bbox[1]
left, _, _, top = transform_bounds(src.crs, dst_crs, *src.bounds)
Expand Down Expand Up @@ -272,10 +261,13 @@ def get_vrt_transform(
"""
if src_dst.crs != dst_crs:
# dst_transform, _, _ = calculate_default_transform(
# src_dst.crs, dst_crs, src_dst.width, src_dst.height, *src_dst.bounds
# )
dst_transform, _, _ = calculate_default_transform(
src_dst.crs, dst_crs, src_dst.width, src_dst.height, *src_dst.bounds
)
print()
print(dst_transform.a, dst_transform.e)
dst_transform = _cheap_transform_calculation(src_dst, dst_crs)
print(dst_transform.a, dst_transform.e)

else:
dst_transform = src_dst.transform
Expand Down

0 comments on commit e5eff80

Please sign in to comment.