Skip to content

Commit 4fcc3d3

Browse files
authored
Add functionality to reproject .tif file (#139)
1 parent 44a4035 commit 4fcc3d3

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

genet/utils/elevation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
def get_elevation_image(elevation_tif):
66
xarr_file = rioxarray.open_rasterio(elevation_tif)
7-
7+
if str(xarr_file.rio.crs) != 'EPSG:4326':
8+
xarr_file = xarr_file.rio.write_crs(4326, inplace=True)
89
return xarr_file[0, :, :]
910

1011

Binary file not shown.

tests/test_utils_elevation.py

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
elevation_test_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "test_data", "elevation"))
99
tif_path = os.path.join(elevation_test_folder, 'hk_elevation_example.tif')
10+
tif_path_crs_not_4326 = os.path.join(elevation_test_folder, 'hk_elevation_example_crs_2326.tif')
1011
array_path = os.path.join(elevation_test_folder, 'elevation_image.nc')
1112

1213
def test_output_type_get_elevation_image():
@@ -20,6 +21,12 @@ def test_get_elevation_image():
2021
assert output == image
2122

2223

24+
def test_get_elevation_image_with_crs_not_4326():
25+
output = elevation.get_elevation_image(tif_path_crs_not_4326)
26+
image = xr.open_dataset(array_path)
27+
assert output == image
28+
29+
2330
def test_get_elevation_data():
2431
# need to figure out how to load save and load in an xarray.DataArray - only managed xarray.Dataset
2532
image = elevation.get_elevation_image(tif_path)

0 commit comments

Comments
 (0)