-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraster_preparation.py
More file actions
59 lines (48 loc) · 2.36 KB
/
Copy pathraster_preparation.py
File metadata and controls
59 lines (48 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Build rasters from the CSV files
"""
from typing import Dict
import os.path
from logger import Logger
from sandbar_site import SandbarSite
from computation_extents import ComputationExtents
def raster_preparation(
sites: Dict[int, SandbarSite],
analysis_folder: str,
csv_cell_size: float,
raster_cell_size: float,
resample_method: str,
epsg: int,
reuse_rasters: bool,
gdal_warp: str,
comp_extent: ComputationExtents) -> None:
"""
Build rasters from the CSV files
:param sites: Dictionary of all SandbarSite objects to be processed.
:param analysis_folder: The path to the output folder
:param csv_cell_size: The cell size of the CSV files (m)
:param raster_cell_size: The cell size of the output rasters (m)
:param resample_method: The resampling method to use when resampling the CSV files to the raster cell size
:param epsg: The spatial reference code of the output rasters
:param reuse_rasters: If True, existing rasters will be used if they exist
:param gdal_warp: The path to the GDAL Warp executable
:param section_types: The list of section types to process
:param comp_extent_shp: The path to the computation extent shapefile
:return: None"""
log = Logger('Raster Prep')
for site in sites.values():
log.info(f'Site {site.site_code5}: Starting raster preparation...')
# Verify that ALL text files for all surveys at this site are correctly formatted
site.verify_txt_file_format()
# Skip the site if it failed to find computational extent
if site.ignore:
continue
# Make a subfolder in the output workspace for this survey
survey_folder = os.path.join(analysis_folder, site.site_code5)
if not os.path.exists(survey_folder):
os.makedirs(survey_folder)
assert os.path.exists(survey_folder), f'Failed to generate output folder for site {site.site_code5} at {survey_folder}'
# Convert the TXT files to GeoTIFFs
site.generate_dem_rasters(survey_folder, csv_cell_size, raster_cell_size, resample_method, epsg, reuse_rasters)
site.clip_dem_rasters_to_sections(gdal_warp, survey_folder, comp_extent, reuse_rasters)
log.info(f'Raster preparation is complete for all {len(sites)} sites.')