Skip to content

Commit

Permalink
Add functionality to reproject .tif file (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ana-kop authored Aug 25, 2022
1 parent 44a4035 commit 4fcc3d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion genet/utils/elevation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

def get_elevation_image(elevation_tif):
xarr_file = rioxarray.open_rasterio(elevation_tif)

if str(xarr_file.rio.crs) != 'EPSG:4326':
xarr_file = xarr_file.rio.write_crs(4326, inplace=True)
return xarr_file[0, :, :]


Expand Down
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/test_utils_elevation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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

def test_output_type_get_elevation_image():
Expand All @@ -20,6 +21,12 @@ def test_get_elevation_image():
assert output == image


def test_get_elevation_image_with_crs_not_4326():
output = elevation.get_elevation_image(tif_path_crs_not_4326)
image = xr.open_dataset(array_path)
assert output == image


def test_get_elevation_data():
# need to figure out how to load save and load in an xarray.DataArray - only managed xarray.Dataset
image = elevation.get_elevation_image(tif_path)
Expand Down

0 comments on commit 4fcc3d3

Please sign in to comment.