Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create BIGTIFF output during export if needed #1559

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading