mapper
mapper copied to clipboard
RFC: expose PDF export to command line
Would it be possible to expose some commands of the Mapper to a command line tool, so that for example one could tell a Github action to create a PDF (and store as build artifact) from a .xmap file?
(btw, I might be interested to contribute something in that direction but have absolutely no overview over the relevant parts of the code.)
Basically, it should be possible and not too difficult. Our tests might help to see how it could work. (In fact, it might be an option to do this as a separate executable.) Fragments:
- Argument processing would use Qt APIs.
- Loading a map from a file name:
https://github.com/OpenOrienteering/mapper/blob/a3cb8e4518f8d15a6938c9b1620c35703788c6ff/test/symbol_t.cpp#L258-L259 - Interactive PDF export is based on printing: https://github.com/OpenOrienteering/mapper/blob/a3cb8e4518f8d15a6938c9b1620c35703788c6ff/src/gui/print_widget.cpp#L1345-L1392
As part of my "map making workflow", I usually import contours e.g. as gpkg/some other georeferenced form, then simplify, and change to curve lines. Also I import bunch of other georeferenced materials (like orto-images, etc). Would be nice if these things could be done from the command line (and from a script).
@joneugster Do you want suggest concrete arguments?
For my usage, I think it would be enough to have something like mapper export ./my_map.xmap ./my_map.pdf (or mapper print [INPUT] [OUTPUT]?) which reads the <print> tag present in the .omap:
<print
scale="15000"
resolution="600"
templates_visible="true"
mode="raster">
<page_format paper_size="A4" orientation="portrait" h_overlap="5" v_overlap="5">
<dimensions width="210" height="297"/><page_rect left="0" top="0" width="210" height="297"/>
</page_format
<print_area left="7.353" top="-337.359" width="210" height="297" single_page="true"/>
</print>
It would be useful if this could also convert map format, for example from xmap to ocad. It would need an additional argument to specify the format.
I did have a go and managed to get this to work. I parsed the arguments if they existed before the window was created and ran a single shot function that did the conversion and quit. I wrote a simplified map load function will a null view. Ugly but it worked.
I guess the file extension of the input/output would directly specify this:
mapper export my_map.xmap my_map.ocad
mapper export my_map.omap my_map.pdf
mapper export my_map.omap my_map.xmap
...
Ideally yes, but the various OCAD versions use the same extension.
We already have is
mapper filename.omap [filname2.omap ...]
to open files in the editor. I would like to avoid any ambiguity about the ambiguity of a free parameter like myfile. Non-filename options shall begin with -. For practial reasons, it might be useful to follow the gdal interface as in https://gdal.org/en/latest/programs/gdal_vector_convert.html#gdal-vector-convert-subcommand. I would probably start the command line mode with --cli.
mapper --cli convert -i my_map.xmap -o my_map.ocd --of OCD12
mapper --cli export -i my_map.xmap -o my_map.pdf --creation-option <KEY>=<VALUE>
Note that map formats are map formats, (geospatial) vector formats and (geospatial) raster formats are treated a little bit different internally.
The --cli might be omitted from a pure command line executable (mapper-cli) which would also remove GUI library dependencies such as X on linux.
@joneugster Do you want suggest concrete arguments?
# export to some other format:
> mapper my_map.omap --cli export -o my_map.ocd --of OCD12
> mapper my_map.omap --cli export -o my_map.pdf -creation-option <KEY>=<VALUE>
# import (georeferenced) template
> mapper my_map.omap --cli import -f orto.tif
> mapper my_map.omap --cli import -f contours.gpkg
# simplify (no output file given -> modifications to my_map.omap)
> mapper my_map.omap --cli simplify -select 'SYMBOL 101' # advanced query language (as in CRT) supported to select objects
# convert to curves (optional output file given)
> mapper my_map.omap --cli to-curves -select 'SYMBOL 102' -o my_modified_map.omap
# change scale
> mapper my_map.omap --cli change-scale -target 1:7500 -o my_map7500.omap
In general some sort of "support for scripting" -type of feature would be nice.