Skip to content

Commit

Permalink
feat: make scale optional (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfouquet authored Feb 28, 2023
1 parent 8fe8211 commit 20218bd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
23 changes: 12 additions & 11 deletions scripts/files/file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,18 @@ def check_color_interpretation(self, gdalinfo: GdalInfo) -> None:
)

def check_tile_and_rename(self, gdalinfo: GdalInfo) -> None:
origin = Point(gdalinfo["cornerCoordinates"]["upperLeft"][0], gdalinfo["cornerCoordinates"]["upperLeft"][1])
try:
tile_name = get_tile_name(origin, self._scale)
if not tile_name == get_file_name_from_path(self._path_standardised):
new_path = os.path.join(os.path.dirname(self._path_standardised), tile_name + ".tiff")
os.rename(self._path_standardised, new_path)
get_log().info("renaming_file", path=new_path, old=self._path_standardised)
self._path_standardised = new_path

except TileIndexException as tie:
self.add_error(FileTiffErrorType.TILE_ALIGNMENT, error_message=f"{tie}")
if self._scale > 0:
origin = Point(gdalinfo["cornerCoordinates"]["upperLeft"][0], gdalinfo["cornerCoordinates"]["upperLeft"][1])
try:
tile_name = get_tile_name(origin, self._scale)
if not tile_name == get_file_name_from_path(self._path_standardised):
new_path = os.path.join(os.path.dirname(self._path_standardised), tile_name + ".tiff")
os.rename(self._path_standardised, new_path)
get_log().info("renaming_file", path=new_path, old=self._path_standardised)
self._path_standardised = new_path

except TileIndexException as tie:
self.add_error(FileTiffErrorType.TILE_ALIGNMENT, error_message=f"{tie}")

def validate(self) -> bool:
gdalinfo = self.get_gdalinfo()
Expand Down
6 changes: 5 additions & 1 deletion scripts/standardise_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ def main() -> None:

for file in tiff_files:
file.set_srs(srs)
file.set_scale(int(arguments.scale))
scale = arguments.scale
if scale == "None":
file.set_scale(0)
else:
file.set_scale(int(scale))

# Validate the file
if not file.validate():
Expand Down

0 comments on commit 20218bd

Please sign in to comment.