My question last week on how to use your own tiles in OSM didn't get an answer, so I had to figure out something myself. (http://www.openstreetmap.org/user/wallclimber21/diary/8019 )
This took a bit more effort than I expected:
Prologue: USGS topographical maps are a great source to map places that are otherwise difficult to map.
- They often contain features that are not available anywhere else (e.g. power lines)
- They are great for area's that are not visible on Yahoo Aerial tiles (e.g. too low resolution or because places where streets are covered by trees / forest).
- They often have feature names that can't be found anywhere else.
- They're in the public domain
(They're also very much outdated, so this won't work for areas with new construction etc.)
I've described here (http://www.openstreetmap.org/user/wallclimber21/diary/7750 ) how you can use those topo maps with Qgis.
Unfortunately, OSM support in Qgis is very basic. You really want to be able to use your tiles as a background in a real OSM tool.
The tiles generated by gdal2tiles.py follow the Tile Maps Service specification (TMS). But while they align perfectly with the tiles of Yahoo, Google, Virtual Earth etc, they don't follow the same standard in how to select a tile at a particular location. Google uses a zoom/y/x format, where (0,0) is at the top left of a flat world. Virtual Earth uses a recursive quadtree structure and TMS uses a structure similar to Google, but with (0,0) at the bottom left of the same flat world. Yahoo uses yet another slightly different convention...
The standard tiles of OSM are using the Google convention.
In addition, there are limitations to the way OSM tools can access custom background tiles: Potlatch only supports the Google convention (I believe), JOSM only supports the WMS standard, not the TMS. And Merkaartor supports both WMS and TMS, but with TMS only the Google convention.
I couldn't find an easy way to set up a WMS server, starting from existing TMS tiles. I'm sure it's possible with MapServer or TileCache or something, but I didn't have the patience to configure a whole setup.
So I decided to shoot for a Merkaartor based solution first.
Since this only supports the Google convention, one needs to hack gdal2tiles.py to modify the names of the directories and files that are created. You can find a patch for that here (http://gist.github.com/197749 ). Note that this patch only fixes the tile names. It doesn't make corresponding changes to the generated .html and .xml files, but since we don't need them, that's ok. A better patch would add a command line option to do all this. Feel free to contribute...
Now, go ahead an create some tiles from a topo map. You'll see that, after the patch, the y coordinate is different from before.
The next step is to get Merkaartor to use your tiles. Unfortunately, neither Potlatch, JOSM nor Merkaartor have support to use a local filesystem for this: they want to talk to a server to get the tiles.
No doubt, there are many HTTP servers that will just send you files, but I'm familiar with rails and didn't want to waste time, So I simply created a new rails project:
> rails topo_server
Then I created a symbolic link in ./topo_server/public directory to my tiles directory:
> cd topo_server/public && ln -s .../master_tiles master_tiles
Finally, I started the server itself:
Finally, you need to tell Merkaartor to use your new tiles.
- Tools -> TMS Servers Editor (this dialog box is completely non-intuitive in how the buttons work...)
- Select one of the existing ones (e.g. Cycle Map) and click "Add"
- Modify the fields:
Server address: localhost
Tile size: 256
Minimum Zoom: 9
Maximum Zoom: 15
(Check you master_tiles directory for the minimum and maximum to fill in)
- click apply on the right size, then ok.
Now you can enable your tiles as a background by right clicking on MAP layer. A USGS option should show up under TMS adapter.
If all goes well, you're good to go!
Except, that is, if you're on a Mac...
Merkaartor will start to crash left and right and become completely unusable. This is because of a race condition in Qt (even the very last official release 4.5.2) with the way it handles Mac sockets. When you are using tiles hosted on your own machine (localhost), this bug will hit all the time and Merkaartor will crash hard.
The only way I've found to fix this is to download the Qt source code, apply the following patch (http://qt.gitorious.com/qt/qt/commit/84abdaa41e6c3bde6ac653e02bd72300b6681572?diffmode=sidebyside ), compile, wait a few hours and install. If you already have other Qt libraries installed, make sure you point to the new version by setting:
(You don't want to know how long it took me to figure this all out...)
Unfortunately, my productivity in Merkaartor doesn't come close to Potlatch, which is nearly perfect in the way it is designed to minimize clicks and key strokes. Potlatch also has support for custom tiles. I assume it uses the same Google convention, but I haven't been able to get it to talk to my server on localhost. I'm still working on that. But, for now, the current solution will do.
PS: It would be nice to have some info on the "New Diary Entry" page on how to add markup to a post. It's not rocket science to 'svn co' the full source code the OSM site and grep for the definition of 'htmlize', but others may not have the same kind of determination. (Edit: nope, didn't work either...)