A python command line tool for importing SVG files into OpenOrienteering Mapper
OpenOrienteering Mapper (OOM) currently lacks specific tools for creating map marginalia such as logos, legends, scale bars and so on. It can therefore be easier to create such artwork in a separate graphics program, such as Inkscape or Adobe Illustrator, that can output SVG. svg2omap lets you convert an SVG file (see limitations below) to GeoJSON that can be imported by OOM. It transforms the SVG into map coordinates matching the coordinate system (typically UTM) of the target omap file and with the desired page dimensions.
Download the python file svg2omap.py or create a clone/fork.
The program requires Python 3 and the the following packages:
python3 ./src/svg2omap.py -m ./example/'Bluff Lake_210404.omap' -i ./example/NArrow1_arc.svg -ht 2.5
Executing the command generates the following output:
-
./src/svg2omap.py
is the python program file. -
./example/'Bluff Lake_210404.omap'
the target OOM map file. -
./example/NArrow1_arc.svg
the SVG file to import. -
-ht 2.5
specifies the desired height of the imported SVG graphics in the default unit of centimeters.
Next import the output geojson file into OOM using the following steps:
- Choose Import from the File menu and select the geojson file.
- Click OK in the symbol mapping menu.
This imports the file and places it in the map (it may be located outside of the current map view).
- Move the selected object to the desired location.
- Replace the default symbology as desired
python3 ./src/svg2omap.py -m ./example/'Bluff Lake_210404.omap' -i ./example/SBar2-10k.svg -wd 60.157 -u mm -o scalebar1.geojson -dpi 600
-
-u mm
specifies that the units for the width are given in millimeters. -
-o scalebar1.geojson
the name of the output file (default is <input_file>.geojson). -
-dpi 600
the resolution at which the graphics are converted (default is 300).
For this example, the given width of the scale bar must match the map scale including the text "Meters" to the right of the bar.
In order to fill the outlined text, we need to create a black fill symbol that is below the white "Forest" in the drawing order
that will be used for the interior rings of the "0":s.
python3 ./src/svg2omap.py -m ./example/'complete map.omap' -i ./example/open-orienteering_ill.svg -o oo.geojson -wd 3 -epsg 32632 -rotation 1.98
-epsg 32632
specifies EPSG code.-rotation 1.98
specifies the map rotation (declination/grivation).
In this example we are forcing an EPSG code and a rotation matching the georeferencing of the map. Normally, this information is automatically extracted from the omap file when available.
The intention of the program is to create a starting point for the most intricate layout elements by converting lines, curves and paths. It does not support all parts of the SVG format! The following are the most notable limitations:
- Text
Actual text strings and fonts are not supported. Instead, text must be vectorized (outlined) in the source SVG (see Creating Outlined Text below).
- Compound Paths
So called compound paths are not supported. In Illustrator, these can be removed by the Release command:
- Colors
No part of the graphic properties such as color and line width are preserved (only the skeleton). This means that the symbology must be reapplied in OOM (see Examples above).
- Compression
Compressed or minified SVG is not supported.
Follow these steps to create outlined text:
Inkscape
- Select the text elements
- Select Path> Object to Path
Illustrator
- Choose File> Save As> SVG with the following options:
The following arguments are available:
-i <file name>
SVG input file (required).-o <file name>
Output geojson file (default: input file name *.geojson).-m <file name>
Target OOM (*.omap) file identifying map scale, CRS and declination (default: SVG coords).-wd <number>
Width of graphic in target (default: SVG coords). Notice: normally you should specify either width or height.-ht <number>
Height of graphic in target (default: SVG coords). Notice: normally you should specify either width or height.-u <unit>
Units for height/width (default: cm). Choices are: 'mm', 'cm', 'in', 'pt'.-dpi <number>
Resolution for converting curve paths incl text outlines (default: 300). This is an approximate measure. Notice: a too high value may not yield a better result.-rotation <number>
Rotation of graphic relative to the map measured counterclockwise (default: map declination). Notice: Normally, this information is automatically extracted from the omap file when available.-epsg <code>
EPSG code (default: map coordinate system as specified in target omap file). Notice: Normally, this information is automatically extracted from the omap file when available.-skip_list <list of numbers>
List of id's to ignore. Ex '0,3,9' (default: None). This allows you to filter out certain input elements. Id numbers are part of the output properties (attributes). You can inspect them in OOM or a GIS.-debug <y/n>
Prints debug statements (default: No).")