Skip to content
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

RasterDataset: calculate res after changing crs #2193

Merged
merged 4 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/datasets/test_geo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import math
import os
import pickle
import sys
Expand Down Expand Up @@ -277,6 +279,11 @@ def test_getitem_separate_files(self, sentinel: Sentinel2) -> None:
assert isinstance(x['image'], torch.Tensor)
assert len(sentinel.bands) == x['image'].shape[0]

def test_reprojection(self, naip: NAIP) -> None:
naip2 = NAIP(naip.paths, crs='EPSG:4326')
assert naip.crs != naip2.crs
assert not math.isclose(naip.res, naip2.res)

@pytest.mark.parametrize('dtype', ['uint16', 'uint32'])
def test_getitem_uint_dtype(self, dtype: str) -> None:
root = os.path.join('tests', 'data', 'raster', dtype)
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,11 @@ def __init__(

if crs is None:
crs = src.crs
if res is None:
res = src.res[0]

with WarpedVRT(src, crs=crs) as vrt:
minx, miny, maxx, maxy = vrt.bounds
if res is None:
res = vrt.res[0]
except rasterio.errors.RasterioIOError:
# Skip files that rasterio is unable to read
continue
Expand Down
Loading