Our new scripting project as of present is a script called duplicate.py which is specifically with the NZ Rail Maps project and it aims to achieve duplication and renaming of the sidecar files that are associated with raster layers.
Suppose that we have a base raster 4800x7200 pixels named in the following pattern:
- Timbuctoo-930W8-92NN9.jpg
- T1942-930W8x2-92NN9x2.jpg
- T1961-930W8x2-92NN9x2.jpg
- T1974-930W8x2-92NN9x2.jpg
- T1984-930W8x2-92NN9x2.jpg
The next steps are to find the sidecar files for the original base raster mentioned above (named Timbuctoo-) and copy these files and rename the copies so that there are four sets of them to match the four exported rasters from Gimp. You can see as the exports have had "x2" tagged onto the row and column names, this string has to be inserted at two places into the original filename.
In addition to this straightforward copy exercise, the world file (xx.jgw) has to have its pixel size entries changed. These are on the first and fourth lines and these have to be halved to reflect the fact that the original file is now doubled in each dimension, so that Qgis will draw it to occupy the same space on the canvas as the original.
There is a complication in that one of the sidecar files is the xx.jpg.aux.xml file as the issue is that the extension in this case is considered to be .xml rather than .jpg.aux.xml and therefore this has to be taken account of when determining where to add the "x2" string into the original file name.
A new aspect of this script that is possible because of the way it works is to run it within the directory that contains all of these files so we cd into that directory and then invoke the script passing its full path. And here we can make life easier for ourselves by using the ln -s command to create a symlink to the Scripts directory. So that to invoke the script we only have to type
- python ~/MapScripts/duplicate.py
A typical invocation could look like
- python ~/MapScripts/duplicate.py -s Timbuctoo- -d "T1942- T1961- T1974- T1984-" -m x2 -p 0.15
The script will search for source .jpg files whose names start with the source prefix and end with .jpg and then look for export files whose names start with each of the specified destination prefixes and end with .jpg. If such a file is found, the sidecar files for the source are copied/renamed/altered as mentioned above, to each destination file name.
By next posting I expect this relatively simple script will be completed.