User:J. Johnson/OSM overlay how-to

How to create an OSM overlay file
Herein is described how to create an OSM overlay file using Xfig to create the overlay image, and Inkscape to convert the image to an SVG (Scalable Vector Graphic) file for upload to WikiCommons. The image can created in Inkscape if you are already familiar with it; for everyone else the freely available and easy-to-use Xfig package is recommended. LibreOffice Draw can also be used, but its user interface is torturous, and its output sometimes has problems. GIMP and Adobe Photoshop are not suitable for vector graphics. The ImageMagick 'display' program will display svg formatted graphcis, but the output of 'convert' is useless.

The principal requirements for this method are the Xfig and Inkscape packages. Some Xfig functions require a three-button mouse, or a way of emulating one.

1- If the OSM (OpenStreetMap) base map does not already exist: create it using the OSM Location map template.

2- From the template, note the base map's size (in pixels), zoom (scale), and coordinate values (latitude and longitude).

3- Save the base map image as a PNG file using your browser.

The following steps presume Xfig, but are generally applicable to Inkscape.

4- Start Xfig.

5- Import ("insert") the base map image using the "Picture" function. Be sure to check the "Use original size" box. Change the depth (layer) from the default "50" to a deeper level (higher number). For this exercise set it to "88".

6- Create the base map outline box:
 * a) Create a rectangle lying just outside the base map image.
 * b) Select the "Edit" function, select the rectangle, and change its depth to "18". Note the list of layers – "Depths" – on the right side, and that clicking on a layer's box toggles it between hidden and displayed.
 * c) Click on "Zoom" (lower-left corner) and increase it to "3".
 * d) In "Grid mode" select the smallest grid.
 * e) in "Point Posn" (position) also select the smallest grid. (This is so that moving two points within a small distance of each other will put them on exactly the same spot.)
 * f) Select "Move objects", then select the base map image and move it to a convenient location. The corners should "snap" to a grid intersection.
 * g) Select "Move points". Select the point at one corner of the outline box and move it to the corresponding corner point of the base map image. Repeat for the diagonally opposite point. (If by chance you grab the corner of the image and move it: there is an option at the top of the "Edit" pull-down menu to "Undo" the last edit.)
 * h) At this point you should have the base map image and outline box. This would be a good time to save your work to a file.
 * Note: the overlay image does not have to be the same size as the base map, but the center point of the image – as determined from the edges – must not be shifted relative to the graphics, or they will not align with the base map. The purpose of the outline box is to maintain the original geometry. It can be shrunk to make a smaller image (use the "Scale" function with the center mouse button), provided that none of the graphics extend beyond the outline box.

7- Importing source imagery. Skip this step if you will not be using another map or image to create the overlay graphics. Otherwise:
 * a) Import the source imagery using the "Picture" function.
 * b) Change the source image to higher layer, such as "78". Toggle that layer to hide it.
 * c) If there are particular points on the base map on which the overlay should be aligned, mark them. Either create a small circle or box around each point, or add a line that comes in from one direction to hit the alignment point and then turns approximately 90&deg; to run out. It will be convenient to have both ends lie outside of the outline box. Change the mark's layer (depth) to "17".
 * d) Set "Point Posn" to "any", then align the source image approximately with the base map.
 * e) Select "Scale". Grab one corner of the image with center button of your mouse, then move the corner in or out until the scale matches the base map.
 * f) If the vertical/horizontal proportion of the image does not match that of base map: select "Move points", grab a corner point of the image, and move to adjust the proportion.
 * g) Adjust the alignment, scale, and proportion until the source imagery is aligned with the base map.
 * h) Save your work.


 * If you will be drawing on multiple images, repeat step 7 for each one, incrementing the layer number for each.

8- Create your overlay graphics. Xfig has a large assortment of graphic elements, including several types of line and spline options, both open and closed. If you are tracing from more than one image: the tracings from each image should be in separate layers. Similarly if your graphics have different groups or elements that you might want to treat in different ways. You might want to increment your layers by two, so you can insert an extra layer with guidelines, comments, etc. And save your work frequently.


 * Recommendation: before investing a lot of time into this, do a simple overlay, then take it through the rest of steps and see if you can make a suitable svg file. Then come back to this step.

9- Export your overlay.
 * a) Hide all of your layers, then unhide the outline box (layer 18), and the layers you want to display.
 * b) Under the "File" menu go to "Export".
 * c) Select "EPS (Encapsulated Postscript" as Language. Other vector formats (not bitmaps) might also work. However, do not select "SVG beta", as it is produces only a very inefficient vectorized bitmap.
 * d) Check "Export only active" and "Boundary only active layers".
 * e) Set "Background" to "None". (This provides the necessary transparent background.)
 * f) Provide a suitable name, and hit "Export".
 * g) Check that your eps file (most pdf readers can read eps) is close to what you want.

10- Remove the outline box.
 * a) Make a backup copy of your eps file, then open it in a suitable editor. Note that some "simple" editors (such as pico, nano, and notepad), and many "word processors", will take liberties with the text. Use an editor intended for programming, such as vi or emacs.
 * b) Using the proper command, find the line that says "here starts figure with depth 18". Recall that that is the layer with the outline box. There should be nine lines, including one with four pairs of numbers, before the next "here starts figure ...."
 * c) Remove those nine lines, then save and close the file.
 * d) Check the eps file again, that it is like before, but without the outline box.

11- Convert eps to svg.
 * a) In Inkscape: use "File/Import" to import the eps file.
 * b) Select "File/Save As", provide a suitable name, check that an SVG format is selected, then hit "Save".
 * c) Check the svg file using an svg-capable graphics viewer (such as ImageMagick's 'display'). Your browser might also have an ability to read a local svg file.

Congratulation, you have just made an OSM overlay image. If this was a trial run, go back to step 8 and finish your graphics.

How to use an OSM overlay file
1- Upload the overlay file to |Wiki Commons. Please put some thought into selecting a useful name. A helpful convention is to include "overlay" in the name. Specify the overlay's geocode with "{&#123;Object location| | &#125;}", and add the file to "Category:OSM transparent overlays".

2- In your OSM Location map template specify your overlay file like any other marker that uses a file:
 * the file name on Wiki Commons
 * the lat/lon corresponding to the center of the overlay; should match that of the original base map
 * the height of the overlay image in pixels.
 * the "dimension" scaling: the height/width ratio.


 * Generally it is best to use the plain "mark" parameters for the overlay so that the numbered marks will appear on top of the overlay.
 * Example:

And that should work.

Did this work for you? Please comment on the Talk page.