Wednesday, June 15, 2011

Guide to Map Tiling
By Brent Fraser
July 26, 2010



    Tiling is the method of pre-rendering map image files in a particular file name structure to improve performance in delivering map image files to the web browser at the request of the Javascript in the web page.  Tiling can give a order of magnitude (or more?) over the traditional rendering-on-demand method used in MapServer (and other map servers). It is well suited to delivering geographic data that doesn't change very often.

    Tiles are typically 256x256 pixels in size by convention, with the data resampled from its original resolution all the way up to a "global" image, using a factor of two, to create an entire "pyramid" of image layers for different viewing scales.

    While there are several Tiling standards, the TMS method gives the most flexibility when using the OpenLayers JavaScript toolkit, and is easy to produce with MapTiler.

    The process described here is for pre-rendering the map tiles for use in a web mapping site. It is possible to render them "on-demand" (when the user browses to them), and save for later requests, but that is not covered here.


What are the Drawbacks?

  • It can take a lot of disk space on your server (about 1.5 times the volume of your original data)
  • It can take a long time to resample the tiles (hours, or days depending on your source data and server performance).
  • Browser code must be written to request and position tiles (or you can just use OpenLayers).
  • Users are limited to specific view scales, but there are lots of scales so that is usually not a problem.


What do I need?

1. Source raster data
2. The GDAL toolkit (http://download.osgeo.org/gdal/win32) for preparing the data
3. MapTiler (http://www.maptiler.org/) for tiling the data
4. OpenLayers (http://openlayers.org/) for displaying the tiles in the browser


Tiling Procedure
0. Prepare your data

    Your data must be one or more georeferenced rasters.  For performance reasons, it may be desirable to project them into your target projection, but it is not necessary.

1.  Build a VRT file

1.1 Create file list

    Use the Windows command line to create a list of files of your original map images:

dir /s /b *.tif > tifs.txt

1.2 Create VRT

    Use GDAL's gdalbuildvrt to create a "virtual raster" file from the above list:

gdalbuildvrt -input_file_list tifs.txt layer.vrt

1.3 Create the Tiles

Use MapTiler to create the tiles:





    Select a Minimum zoom of "0" if you wish your data to be visible when the user is viewing the entire world in one image.

    The Maximum zoom in the above window is calculated based on the pixel size of your original data. It tends to be a little pessimistic, so you may want increase the value by one (e.g. if it automatically calculates 15, you may want change it to 16). But be careful, by increasing it one level, you add 4 times the required disk space!

Some additional info to help you choose:

Zoom: 1:n Scale:    Pixel size:
---------------------------------------
0    443,744,256  156,543 m/pixel (1.40 degrees/pixel)
1    221,872,128   78,271
2    110,936,064   39,135
3     55,468,032   19,567
4     27,734,016    9,783
5      13867,008    4,891
6       6933,504    2,445
7       3466,752    1,222
8       1733,376      611.4
9        866,688      305.7
10       433,344      152.8
11       216,672       76.43
12       108,336       38.21
13        54,168       19.10
14        27,084        9.554
15        13,542        4.777
16         6,771        2.388
17         3,386        1.194
18         1,693        0.5971
19           846        0.2985 - Last OpenLayers Level -
20           423        0.1492
21           212        0.0746 - Last Google API Level -



Note: the Result directory must exist (MapTiler will not create it).





    MapTiler will produce Google Maps and OpenLayers compatible web pages in the target folder for viewing your map tiles.  You can have a look at the generated html to see how to use the tiles in a web page.

 
What is Map Tiling?

Tuesday, March 1, 2011

Notes on a Saskatchewan OpenStreetMap Canvec import

  I finally got around to doing my first OSM data import session.  I had some spare time and was frustrated with the lack of OSM progress in Saskatchewan, so I imported a Canvec sub-tile for Melfort, Sask.

    It was surprisingly easy, thanks to the great work of Daniel Bégin in supplying .osm formatted Canvec data, and Steve Singer's blog on  Importing Canvec.

  I used Josm to import the geometry and Potlatch to add the street names (the street naming was tedious, but somehow felt rewarding).  
 
Josm
  Josm looks like a powerful OSM editting tool and can be a little intimidating.  Fortunately you can do a lot with a couple of simple workflows.  Steve's blog covers the basics of opening the Canvec data and downloading the current OSM data for the area.
 
  Now to replace the existing low-res roads in the OSM data with the higher-res roads in the Canvec data, ensuring the new roads connect to low-res roads just outside the import area  
  1. Activate the OSM layer and add nodes to the existing OSM road data at the edge of your import area.  This will make the connecting of the new roads to the existing OSM road network easier.  When a node is added, select the node then click the "Split a way at the selected node" button.  This will let you select just the OSM roads with in the import area.
  2. Select the e
  3. Activate the Canvec layer.  Click "Open a list of all relations". Search. Copy. Edit->Merge Selection. Delete.
  4. Activate OSM layer.  Zoom to each of nodes you added.  Move the OSM node to Canvec node.  Select both nodes.  Tools-> Merge Nodes
  5. Upload

  Now to upload the other relations in the Canvec data.
  1. Since you've deleted the highways from the Canvec dataset in the previous workflow, activate the Canvec data and select everything.  Copy. Activate the OSM layer. Paste.
  2. Upload. A dialog will likely appear showing a list of errors and warnings.  If there are errors, cancel the upload.
  3.  The errors are likely related to duplicated ways of railways.  Delete the duplicates and upload.
  
Road Data
  For others planning to do some OSM work in Saskatchewan, here's a summary of free and license-friendly sources of street GIS data:

Canvec (.osm format)
    ftp://ftp2.cits.rncan.gc.ca/osm/pub
    - old geometry
    - no street names
    - no address ranges

GeoSask Road Network
    ftp://portaldata:freedata@ftp.isc.ca/PackagedData/Sask_Highways/SURN09.zip
    - geometry same as Canvec (old)
    - complete street names, but poor capitalization and spelling: "MACLOED AVENUE"
    - no address ranges

Geobase Road Network
    http://www.geobase.ca/geobase/en/search.do?produit=nrn&language=en
    - new geometry
    - complete street names, poor capitalization and spelling: "Macloed Avenue"
    - no address ranges

StatsCan
    http://geodepot.statcan.gc.ca/2006/040120011618150421032019/1814062006_05-eng.jsp
    - newer geometry but positional accuracy poor
    - incomplete street names (unless you combine NAME and TYPE attributes) "MacLeod AVE"
    - has address ranges