At the moment I'm converting my OS Map theme from v3 to v4. I have been finding the process very mechanical and repetitive, so much so that once I I done around 2,500 lines out of 10,000 lines by hand I decided to quick put together a script to do most of the changes programatically.
Attached is a VBScipt that does most of the changes required to convert a v3 theme to v4.
I quickly discovered that v4 render engine is very intolerant to syntax errors and if any are present it will refuse to display anything. This means manually removing parts of the generated v4 theme until it works and locating the syntax error. The following are some examples of errors I found in several themes:
- stroke-width="1.2p"
- <rule case="off_pl"
- close="yes" (should be closed="yes")
I have converted the following themes using the script, in some cases requiring some additional custom mods:
- OS Map
- Outdoor (because it is small, simple and already has a v4 theme to compare with)
- Waymark2a
I would consider the output of the script as a starting point only and not a final theme. In some cases it is possible to tweak the theme using the script, see the Outdoor script for an example. In some cases there are differences that have to manually changed in the generated theme. Waymark2a is an example of this, seems the v4 rendering in LoMaps has a bug, the following puts green dashes on service roads as well as raceways:
<rule e="way" k="highway" v="service|raceway" zoom-min="14">
<line stroke="#ffffff" stroke-width="0.81" />
<rule e="way" k="highway" v="raceway" zoom-min="14">
<line stroke="#a5cba5" stroke-width="0.54" scale="all" stroke-dasharray="1,1" stroke-linecap="butt" />
</rule>
:
so I had to manually separate service and raceway rules to fix this:
<!-- service raceway -->
<rule e="way" k="highway" v="service" zoom-min="14">
<line stroke="#ffffff" stroke-width="0.81" />
:
<rule e="way" k="highway" v="raceway" zoom-min="14">
<line stroke="#ffffff" stroke-width="0.81" />
<line stroke="#a5cba5" stroke-width="0.54" scale="all" stroke-dasharray="1,1" stroke-linecap="butt" />
:
I'll add the converted Outdoor and Waymark example themes in the next few posts. I'm using the initial conversion of my OS Map theme as a starting point for a v4 OS Map theme. I'm about 50% complete so far, but am battling with lack of symbol and text scaling in v4...
Please note that this script is a quick hack, there are probably better ways using XML libraries to do this... It does no error checking and you'll probably need to modify it for best results. It is a visual basic script and should work on a Windows command line using the following command line syntax:
cscript v3_to_v4.vbs <v3 rendertheme>.xml <v4 rendertheme>.xml
Where:
v3_to_v4.vbs -- Name of this script
<v3 rendertheme>.xml -- Input file that is a v3 rendertheme file, e.g. VoluntaryV3.xml
<v4 rendertheme>.xml -- Output file to be created as a v4 rendertheme file, e.g. VoluntaryV4.xml
Just putting this out there in case it is useful to other theme writers. It isn't really suitable for most people to use, but anyone with a basic understanding of visual basic and renderthemes should be OK.
I would check the examples in the following posts for examples of how to use the custom coding section and supporting functions...
Karl.
Attached is a VBScipt that does most of the changes required to convert a v3 theme to v4.
I quickly discovered that v4 render engine is very intolerant to syntax errors and if any are present it will refuse to display anything. This means manually removing parts of the generated v4 theme until it works and locating the syntax error. The following are some examples of errors I found in several themes:
- stroke-width="1.2p"
- <rule case="off_pl"
- close="yes" (should be closed="yes")
I have converted the following themes using the script, in some cases requiring some additional custom mods:
- OS Map
- Outdoor (because it is small, simple and already has a v4 theme to compare with)
- Waymark2a
I would consider the output of the script as a starting point only and not a final theme. In some cases it is possible to tweak the theme using the script, see the Outdoor script for an example. In some cases there are differences that have to manually changed in the generated theme. Waymark2a is an example of this, seems the v4 rendering in LoMaps has a bug, the following puts green dashes on service roads as well as raceways:
<rule e="way" k="highway" v="service|raceway" zoom-min="14">
<line stroke="#ffffff" stroke-width="0.81" />
<rule e="way" k="highway" v="raceway" zoom-min="14">
<line stroke="#a5cba5" stroke-width="0.54" scale="all" stroke-dasharray="1,1" stroke-linecap="butt" />
</rule>
:
so I had to manually separate service and raceway rules to fix this:
<!-- service raceway -->
<rule e="way" k="highway" v="service" zoom-min="14">
<line stroke="#ffffff" stroke-width="0.81" />
:
<rule e="way" k="highway" v="raceway" zoom-min="14">
<line stroke="#ffffff" stroke-width="0.81" />
<line stroke="#a5cba5" stroke-width="0.54" scale="all" stroke-dasharray="1,1" stroke-linecap="butt" />
:
I'll add the converted Outdoor and Waymark example themes in the next few posts. I'm using the initial conversion of my OS Map theme as a starting point for a v4 OS Map theme. I'm about 50% complete so far, but am battling with lack of symbol and text scaling in v4...
Please note that this script is a quick hack, there are probably better ways using XML libraries to do this... It does no error checking and you'll probably need to modify it for best results. It is a visual basic script and should work on a Windows command line using the following command line syntax:
cscript v3_to_v4.vbs <v3 rendertheme>.xml <v4 rendertheme>.xml
Where:
v3_to_v4.vbs -- Name of this script
<v3 rendertheme>.xml -- Input file that is a v3 rendertheme file, e.g. VoluntaryV3.xml
<v4 rendertheme>.xml -- Output file to be created as a v4 rendertheme file, e.g. VoluntaryV4.xml
Just putting this out there in case it is useful to other theme writers. It isn't really suitable for most people to use, but anyone with a basic understanding of visual basic and renderthemes should be OK.
I would check the examples in the following posts for examples of how to use the custom coding section and supporting functions...
Karl.