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

Add left-padding to Atlas output filenames for better ordering #31309

Open
kannes opened this issue Aug 20, 2019 · 3 comments · May be fixed by #59978
Open

Add left-padding to Atlas output filenames for better ordering #31309

kannes opened this issue Aug 20, 2019 · 3 comments · May be fixed by #59978
Labels
Feature Request Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks

Comments

@kannes
Copy link
Contributor

kannes commented Aug 20, 2019

Feature description.
I propose to change the default output filename expression used by Atlas from

'output_'||@atlas_featurenumber

to

'output_' || lpad(@atlas_featurenumber, length(to_string(@atlas_totalfeatures)), 0)

This will result in output filenames that are left-padded with leading zeros. They all have the same length as the required maximum length is determined by length(to_string(@atlas_totalfeatures)).

The motivation for this is safer and more deterministic ordering of the output files. Different OSs, file managers or video editing tools might order numbered files differently if there are no leading zeros.

The secondary benefit is a fixed length of the filenames.

For example when turning Atlas output into a video with ffmpeg, the common approach is to use a fixed size placeholder in the input string like -i output_%03d.png. This won't work if the filenames have different lengths. The alternative approach of using globbing -pattern_type glob -i 'output_*.jpg' depends on the shell's ordering (see the ls example above I guess).

For example ls (at least on my system) will order an example output alphabetically like this:

output_10.png
output_11.png
output_12.png
output_13.png
output_14.png
output_15.png
output_16.png
output_17.png
output_18.png
output_19.png
output_1.png
output_20.png
output_21.png
output_2.png
output_3.png
output_4.png
output_5.png
output_6.png
output_7.png
output_8.png
output_9.png

while in my file manager (Thunar) it looks like this as it considers the numbers separately:

image

If we pad with leading zeros, both of these exemplary tools would display the same order.

Of course people can probably configure their tools to a different order but that seems like an unnecessarily complicated thing to ask for if we could simple pad the output nicely.

Additional context
I meant to add this change in a Pull Request but the complexity of doing a proper code submission is scaring me off (not the fault of QGIS but C++ and tests and proper software development processes in general ;) ). I think I have identified all occurances in the code and edited them correctly in https://github.com/kannes/QGIS/commits/padded_atlas_output but I have no idea if tests are needed, I would need to set up an environment to compile etc. Sorry but this Feature Request is all I can do. I hope it is detailed enough that the work load is as small as possible.

@kannes
Copy link
Contributor Author

kannes commented Apr 20, 2023

On it, will make a PR shortly.

kannes pushed a commit to kannes/QGIS that referenced this issue Apr 20, 2023
This will result in output filenames that are left-padded with leading
zeros. They all have the same length as the required maximum length is
determined by `length(to_string(@atlas_totalfeatures))`.

E. g. "output_1.png" -> "output_01.png".

The motivation for this is safer and more deterministic ordering of the
output files. Different OSs, file managers or video editing tools might
order numbered files differently if there are no leading zeros.

The secondary benefit is a fixed length of the filenames.

For example when turning Atlas output into a video with ffmpeg, the
common approach is to use a fixed size placeholder in the input string
like `-i output_%03d.png`. This won't work if the filenames have
different lengths. The alternative approach of using globbing
`-pattern_type glob -i 'output_*.jpg'` depends on the shell's ordering.
kannes added a commit to kannes/QGIS that referenced this issue Apr 20, 2023
This will result in output filenames that are left-padded with leading
zeros. They all have the same length as the required maximum length is
determined by `length(to_string(@atlas_totalfeatures))`.

E. g. "output_1.png" -> "output_01.png".

The motivation for this is safer and more deterministic ordering of the
output files. Different OSs, file managers or video editing tools might
order numbered files differently if there are no leading zeros.

The secondary benefit is a fixed length of the filenames.

For example when turning Atlas output into a video with ffmpeg, the
common approach is to use a fixed size placeholder in the input string
like `-i output_%03d.png`. This won't work if the filenames have
different lengths. The alternative approach of using globbing
`-pattern_type glob -i 'output_*.jpg'` depends on the shell's ordering.
@alexbruy alexbruy added the Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks label Dec 7, 2023
@YoannQDQ
Copy link
Contributor

@kannes are you still working on that?

@kannes
Copy link
Contributor Author

kannes commented Dec 19, 2024

Huh, not sure what happened there in 2023. Looks like I wrote the code but stopped when tests were involved?

I won't be able to work on this soon, please feel invites to take anything from my branch, with our without attribution, and make a PR.

@YoannQDQ YoannQDQ linked a pull request Dec 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants