Skip to content

Commit

Permalink
ers to tif
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardScottOZ committed Feb 25, 2024
1 parent ea92c2c commit be330ec
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/richardutils/richardutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ def create_vrt_for_geotiffs(directory):

def tif_to_ers(strpath, masked=True, chunks=None, dsmatch=None):
"""
Walks a directory of geotiffs and returns each as an ers grid and writes to fiel
Walks a directory of geotiffs and returns each as an ers grid and writes to file
Args:
strpath: directory name
chunks: tuple of integers
Expand Down Expand Up @@ -1170,6 +1170,47 @@ def tif_to_ers(strpath, masked=True, chunks=None, dsmatch=None):


return check_dict

def ers_to_tif(strpath, masked=True, chunks=None, dsmatch=None):
"""
Walks a directory of ers and returns each as an ers geotiff
Args:
strpath: directory name
chunks: tuple of integers
dsmatch: data array to match the directory of rasters to
masked: whether to mask by nodata, default is yes, pass masked=False if not desired
Returns:
a dictionary of rioxarrays
Examples:
tif_dict(r'D:\BananaSplits')
tif_dict(r'D:\BananaSplits', chunk=s(1,1024,1024))
"""

check_dict = {}
for root, dirs, files in os.walk(strpath):
for file in files:
if '.ers' in file and '.xml' not in file:
if dsmatch is None:
if chunks is None:
check_dict[file] = rioxarray.open_rasterio(os.path.join(root,file),masked=masked)
else:
check_dict[file] = rioxarray.open_rasterio(os.path.join(root,file), masked=masked, chunks=chunks)
else:
if chunks is None:
check_dict[file] = rioxarray.open_rasterio(os.path.join(root,file), masked=masked).rio.reproject_match(dsmatch)
else:
check_dict[file] = rioxarray.open_rasterio(os.path.join(root,file), masked=masked, chunks=chunks).rio.reproject_match(dsmatch)

for file in check_dict:
ersfile = file.replace('.ers','.tif')
print(file.replace('.ers','.etif'))
check_dict[file].rio.to_raster(ersfile, driver='GTiff')


return check_dict



def tif_to_img(strpath, masked=True, chunks=None, dsmatch=None):
Expand Down

0 comments on commit be330ec

Please sign in to comment.