Warp-gbos

From OpenStreetMap Wiki
Jump to navigation Jump to search

Warp-gbos is a group of programs to convert scanned map sheets into rectified KML files or slippy map tiles. An alternative is to use Metacarta and Geothing to display rectified/warped images. Warp-gbos supports higher resolution images than is allowed by web based services. Various transformations are available at high accuracy:

  • British national grid reference system to Rectified Mercator
  • British national grid reference system to Rectified British national grid reference system
  • Mercator to Rectified Mercator

If there is any demand, I can add the function of Mercator to Rectified British national grid reference system.

These tools were developed to rectify 7th Series OS maps into a usable form. They were originally created by TimSC. A large amount of computer memory is required to manipulate very large map scans. The tools operate on the command line and require some knowledge of common commands.

Compilation

The source code is here. Significant changes were made in v0.6 to remove the perl code and replace it with python. The old compilation instructions are therefore out of date - apologies. If you are interested, I will make the effort to document this (or you can do it!).

Converting Image to Rectified KML

1) Get the example source image

wget http://timsc.dev.openstreetmap.org/dev/warp-gbos/os7th075.jpg

2) Rectify source to KML using warpos. The calibration is specified in the file cal-os7th/os7sheet075.csv and the accuracy of fit is printed to the console. A cubic polynomial is used to transform the input image. To quickly check the accuracy of the warp, the option "--fitonly" calculates the transform and prints the accuracy without the slow image warping step.

./warpos --in os7th075.jpg --points cal-os7th/os7sheet075.csv --out os7th075 --fit 3

3) View the KML result (os7th075.kml) in an application of your choice. e.g. Google Earth

Calibration of Sheets

Inside the calibration file os7sheet075.csv is the following:

imagesize,8816,10929,,
os,NX930500,636,9730
os,NY330500,8095,9721
os,NX930950,633,1259
os,NY330950,8090,1247
os,NY130500,4363,9725
os,NY330720,8093,5593
os,NX930720,632,5598
os,NY130950,4361,1254
os,NY130720,4362,5596
os,NY040630,2682,7295
os,NY220630,6042,7292
os,NY040850,2684,3142
os,NY220850,6041,3140
os,NY290750,7346,5026
os,NY070590,3244,8047
os,NY250610,6601,7670
os,NY250660,6601,6725
os,NY260600,6787,7858

The first line specifies the image size that was used for the calibration.

The later lines specify the control points. The second column states the map reference. The third and fourth columns specify the horizontal and vertical pixel positions respectively. The origin is the top left of the image. Pixel positions may be read using an graphics tool such as GIMP.

More control points allow a more accurate calibration or a higher order polynomial transformation to be used.

Gentiles

Gentiles takes one or more KML tiles and produces tiles suitable for a slippy map (e.g. OpenLayers). The source code is included in the main warp-gbos archive and usually compiles along side warpos without difficulty. Command line help is available:

./gentiles --help

Usage is along the lines of:

./gentiles --minzoom 13 --maxzoom 14 ../path/to/files/*.kml

This creates a series of folders and files for the various tiles. The default output folder is simply called "out". Edges of map sheets should be specified in the bounds file (default name bounds.csv) which enables the joins between the various sheets to be correctly drawn. If a tile already exists in the output folder, it is not recreated. This allows tile generation to be stopped and easily restarted. This tool also requires the PERL5LIB environment variable, as described above.

The slowest part of the process is probably the loading and unloading of image files into memory, for slicing. If you are creating low-zoom tiles, or the image files are relatively small, you may find the limit of 3 files in memory slows things down. Edit GenTiles.cpp, changing maxTilesLoaded to a larger number. I've run it with all 120 images in my project area, with no problems - it does use a lot of memory of course. Once all the images are loaded in, it zips through the rest of the tiles. Ollie 20:36, 5 February 2010 (UTC)

Version 0.6 uses multithreading and batch processing to drastically improve tile loading and processing.--TimSC 18:11, 26 September 2010 (BST)

Cleartiles

Clear tiles deletes all tiles that are within the boundary of a specified KML file. (I think) the bounds must be set in bounds.csv to operate correctly. Let me know if further documentation or help is needed. cleartiles is not built by default but may be created by the command:

make cleartiles

Note: cleartiles assumes that the tiles are in the "out" subdirectory. The only parameter cleartiles needs is the path to (and name of) the KML file concerned. For example:

cleartiles ../path/to/file/005.kml

Copying Files to a Remote Server

There are many approaches to this, but one useful method is rsych:

rsync -r --verbose --progress /path/to/files/warp-gbos/out/14/ username@dev.openstreetmap.org:/home/ooc/os7-2010b/14