User:NJR ZA/osm2svg

Introduction
I have been looking at converting Open Street Map data to Usable Wikivoyage maps. This is still early days, but it seems to be a viable solution to quickly and easily generate maps for Wikivoyage articles.

To start with, I took osmarender 6.0 from the OpenStreetMap project as base for a wikivoyage map generator

Status

 * Almost Usable, but with a lot of restrictions and work that still needs doing
 * It's only been tested on Ubuntu 7.10

Version 0.01 to 0.04

 * Initial messing about with the osmarender code to get to know what makes it tick, what it's short-commings are etc
 * Added some of the wikivoyage symbols to use in rendering
 * A number of issues were clear from the start
 * The generated svg files are far to big
 * The code can be made a lot simpler
 * OSM data is cc-by-sa, but there is no mechanism in osmarender to extract the user info for attribution
 * Once a map has been rendered there is no easy way to edit it

Version 0.05 to 0.09

 * added isWayVisible check to drop all ways that will not be visible on the rendered map from the generated svg. This makes the resulting svg a lot smaller and easier to work with
 * added rendering of the wikivoyage annotation box, symbol box and license box
 * added extract of individual OSM contributors for attribution
 * added generation of wikivoyage wikitext at completion of conversion
 * added initial support for themes (so this can be used for not only wikivoyage)
 * added automated scaling of the non map elements so they match the size of the map
 * added automated selection for the scale size
 * added yards/miles as additional scale units to the existing meter/kilometer
 * added a lot of useful progress output

Version 0.10

 * added  that will allow one to specify a central location in decimal degrees and the height and width in km to render at that location
 * cleaned up the documentation render area selection
 * fixed a bug introduced in 0.09 causing isAreaVisible to return false negatives
 * fixed small spelling mistake on output
 * removed external wikilinks to OSM users, Wikivoyage does not like multiple external links

Version 0.11

 * better scale size selection
 * code cleanup

Software overview

 * The current code consists of
 * osm2svg.xsl - The main translator, based on osmarender.xsl from Osmarender 6.0 Alpha 6
 * osm2svg.xml - Conversion rules used by osm2wtmap.xsl. Based on osm-map-features-z16.xml from Osmarender 6.0 Alpha 6
 * themes/themePostMessage.xsl - some code that can be executed at completion of the conversion. Used by the wikivoyage theme to generate wikitext that can be used for attribution and image description when uploading the map to the wiki
 * themes/wikivoyage/css.xml - stylesheet for wikivoyage
 * themes/wikivoyage/markers.xml - markers for wikivoyage
 * themes/wikivoyage/patterns.xml - patterns for wikivoyage
 * themes/wikivoyage/symbols.xml - symbols for wikivoyage

The latest version is available here

ToDo list

 * Look and feel changes
 * CSS needs to be updated to match recommendations given in Project:How to draw a map
 * all wikivoyage symbols need to be added
 * Mostly done now
 * rules need to be changed so they always refer to a standard set of symbol names that can be reused in all themes
 * A zoom factor needs to be added in order to selectively apply rules depending on map size
 * rules need to be changes to cater for this and rules from the other osmarender zoom levels need to be added to the current rule set
 * map element scaling (road width and spacing between roads etc) need to be calculated automatically based on map size, as has been done for the non map elements
 * extraction of OSM contributor names needs to be optimized as this takes far to long
 * code cleanup and spelling mistakes on the output
 * add support to read listing geodata directly from wikivoyage article and generate annotation listing on the fly
 * Can't do this. cc-by-sa-1 data from WT can't be redistributed on a map that has to be cc-by-sa-2 :(

Using osm2svg
If you want to play around with this, then get the latest release here.

Remember, it's not near perfect yet

Getting the OSM data
This is the simple part.

While viewing a map on the OSM website:
 * 1) Export
 * 2) Select OpenStreetMap XML Data as the Format to Export
 * 3) Select SVG under options
 * 4) Click the Export button

You will be prompted to save the data as a file called map.svg

Generating a Wikivoyage map
You should receive output similar to the following:
 * 1) Save the OSM data as map.osm in the same directory as the above mentioned source
 * 2) Open osm2svg.xml in a text editor and
 * 3) * Specify the area you want to render. This can be done in one of the following ways
 * 4) *# Specify a central location in decimal degrees and the height and width in km to render at that location,  
 * 5) *# Specify a bounding box here with minimum and maximum latitudes and longitudes in decimal degrees, 
 * 6) * Change title
 * 7) * Make sure the theme is set to wikivoyage
 * 8) Execute: ./xsltrans osm2wtmap.xml > map.svg

osm2svg version 0.09 Generating svg map from OSM data file map.osm

Map definition Title: Boston/Back Bay Theme: wikivoyage

Map extent Available in OSM data file Latitude: 42.273897 to 42.437487 Longitude: -71.232202 to -71.029286

Requested for this map Latitude: 42.345 to 42.355 Longitude: -71.0975 to -71.065 Area is 2.672 km (1.66 mile) wide, 1.112 km (0.691 mile) high and has a diagonal of 2.896 km (1.8) mile

Scaling Internal annotation scale: 0.134 Retreiving OSM users names for attribution (this might take a while) Adding svg metadata Adding svg defs sections stylesheets patterns markers symbols Pre-generate OSM ways as named paths Adding license and attribution information Drawing the map background OSM map data processing all rules for OSM layer -5 processing all rules for OSM layer -4 processing all rules for OSM layer -3 processing all rules for OSM layer -2 processing all rules for OSM layer -1 processing all rules for OSM layer 0 processing all rules for OSM layer 1 processing all rules for OSM layer 2 processing all rules for OSM layer 3 processing all rules for OSM layer 4 processing all rules for OSM layer 5 decorations border compass scale using 100meter/yard Adding an annotation box Adding a symbol box Done

The following wiki markup can be used when uploading this file to Wikivoyage:

Source
This is a derivative work based on copyright content from contributors to: OpenStreetMap http://www.openclipart.org Distributed under the Creative Commons Attribution-ShareAlike 2.0 License.

as well as Public Domain content from: http://www.openclipart.org 

Attribution

 * Creators of the source work include, but are not limited to

Áki G. Karlsson Finnish Road Commission Jean-Victor Balin Nick Roux Paul Louis United States DOT
 * Public Domain Work:


 * Wikivoyage users:

Import MassGIS Import crschmidt Matern Thomas Matern dforsi
 * OopenStreetMap users that are known to have contributed to this map:
 * some uri's removed here to satisfy wikivoyage's spam checker



The generated svg will look something like the one on the right, open it in Inkscape and change as required. An example of a generated svg file is available at Image:Osm2svg-example-boston_back_bay.svg