Skip to content

Commit

Permalink
Merge pull request #1559 from pierotofy/bigfix
Browse files Browse the repository at this point in the history
Create BIGTIFF output during export if needed
  • Loading branch information
pierotofy authored Sep 28, 2024
2 parents 31f9399 + b9868ba commit 208af69
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,19 @@ class ProfileInline(admin.StackedInline):
model = Profile
can_delete = False

# Hide "quota" profile field when adding (show during editing)
def get_fields(self, request, obj=None):
if obj is None:
fields = list(super().get_fields(request, obj))
fields.remove('quota')
return fields
else:
return super().get_fields(request, obj)

class UserAdmin(BaseUserAdmin):
inlines = [ProfileInline]


# Re-register UserAdmin
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
11 changes: 11 additions & 0 deletions app/classes/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,14 @@ def reset(self, text = ""):
f.write(text)
except IOError:
logger.warn("Cannot reset console file: %s" % self.file)

def delink(self):
try:
if os.path.isfile(self.file) and os.stat(self.file).st_nlink > 1:
with open(self.file, "r", encoding="utf-8") as f:
text = f.read()
os.unlink(self.file)
with open(self.file, "w", encoding="utf-8") as f:
f.write(text)
except OSError:
logger.warn("Cannot delink console file: %s" % self.file)
3 changes: 3 additions & 0 deletions app/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ def duplicate(self, set_new_name=True):
try:
# Try to use hard links first
shutil.copytree(self.task_path(), task.task_path(), copy_function=os.link)

# Make sure the console output is not linked to the original task
task.console.delink()
except Exception as e:
logger.warning("Cannot duplicate task using hard links, will use normal copy instead: {}".format(str(e)))
shutil.copytree(self.task_path(), task.task_path())
Expand Down
7 changes: 5 additions & 2 deletions app/raster_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ def export_raster(input, output, **opts):
elif export_format == "gtiff-rgb":
compress = "JPEG"
profile.update(jpeg_quality=90)
profile.update(BIGTIFF='IF_SAFER')
band_count = 4
rgb = True
else:
compress = "DEFLATE"
profile.update(BIGTIFF='IF_SAFER')
band_count = src.count

if compress is not None:
profile.update(compress=compress)
profile.update(predictor=2 if compress == "DEFLATE" else 1)
Expand Down Expand Up @@ -163,7 +165,8 @@ def write_band(arr, dst, band_num):
src_crs=src.crs,
dst_transform=transform,
dst_crs=dst_crs,
resampling=Resampling.nearest)
resampling=Resampling.nearest,
num_threads=4)

else:
# No reprojection needed
Expand Down

0 comments on commit 208af69

Please sign in to comment.