 |
Converting ECW maps to the OSM Tile format
By David Bannon, dbannon at internode.on.net
These instructions are for Linux, TangoGPS is Linux only, I guess the remainder may be useful for other operating systems. Its also worth noting that I claim no knowledge of mapping or cartography, bound to be lots of things here I have wrong. Please feel free to have a laugh and then let me know how it can be don better.
I use TangoGPS to plot my position on a moving map. TangoGPS is one very nice little package by Marcus Bauer that generally use Open Street Map maps, it automatically downloads them when on line and caches them for use when off line. Does a couple of other source of maps too but I found them not so useful for various reasons. Here in Australia I can get 250000:1 survey maps from GeoScience Australia. What I really needed was a way to use the survey maps in TangGPS. So here is what I found -
- TangoGPS saves its maps in the OSM render tile format. Each tile is a 256x256 png bitmap and its name, a number, represents how far south we are. Its in a directory whose name is also a number that represents how far east we are. Thats in a directory, you guessed it, a number, this time its the zoom, between 2 and 17. So all we need to do is work out the names that match the bitmaps we have. OSM provide a couple of functions that do most of the hard work.
- The survey maps I use are in ECW format. While propriety, this is a pretty good format. ERDAS very kindly make C libraries that can address ECW files available for free after some painless registration. Note ECW is bundled with JPEG2000
- The ECW C libraries are supported by GDAL, a "Geospatial Data Abstraction Library". GDAL does not, out of the box, include ECW support, you need get them both as source and compile. Its easy but takes a while. Clear instructions here. You will need a compiler and a bit of time but its pretty easy. In practice all we need is a couple of the utilities included with GDAL but I did not look to see how to build just that. So I got heaps of libraries and header files I don't need. Not to worry...
- I wrote a little python script that extracts information from an ECW map, decides where the equivalent OSM tiles would live and then generates them from the ECW map. It works fine for me but has some problems, firstly, it only works for ecw maps that have its boundaries parallel to longitude and latitude. Secondly, it discards part tiles around the edge, OSM tiles cannot be expected to exactly line up with the edge of our ECW map. Thirdly, I've only tested it on maps from one source, Geoscience Australia, your mileage may vary. ..
Generating tiles for TangoGPS
You need a couple of things -
- A working install of TangoGPS (unless you are making OSM tiles for some other reason). Its probably in your Linux package repo.
- My python script (and python of course). You'll need to mark it as executable (chmod u+x ecw2osmtile.py) and may as well put in somewhere in our path.
- A working GDAL with ECW support as mentioned above. The python script is going to call the binaries gdalinfo and gdal_translate so if they are not on your path, be prepared to hard wire fqn into the script.
- You must know where TangoGPS caches its map files. In my case is ~/Maps, we'd expect to see at least a directory, "OSM" in there. Under OSM we'll find the tiles from OSM, we'll make another directory there called, for example, "Survey". ( mkdir ~/Maps/Survey )
- OK, lets assume we have an ECW file in ~MyMaps and its called AliceSprings.ecw, lets have a little test first ( ecw2osmtile -i ~/MyMaps/AliceSprings.ecw ).
- If that does not look too scary, try the real thing ( ecw2osmtile -d ~/Maps/Survey ~/MyMaps/AliceSprings.ecw ). This may run for five or ten minutes, it logs a bit of a progress report as it goes.
- Right, assuming thats all OK, start up TangoGPS. I use a little shell script that looks for the GPS and if its there, changes the port to my ownership, if not, pops up a zenity dialog and warns me before proceeding.
-
We have to lie to TangoGPS a bit, we make a config that has a dud web address and name it "Survey". TangoGPS is fine with that, it loads the new tiles and does not complain (to the GUI) when it cannot find the web site. See the sample image.
- Now TangoGPS will use the tiles whenever the zoom is set to the zoom they were made for and the next two zoom levels. Cool bit of code Marcus !
|