From e5eff80bf3a4c8897acd0afac9780f6d54af751b Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 16 Nov 2023 15:37:01 +0100 Subject: [PATCH] simplify --- rio_tiler/utils.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/rio_tiler/utils.py b/rio_tiler/utils.py index 265cd6e9..31cb7f87 100644 --- a/rio_tiler/utils.py +++ b/rio_tiler/utils.py @@ -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 @@ -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) @@ -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