Tech:Map Imagery
From Cyclopath
Contents |
[edit] Quick Installation
It's now possible to install both TileCache and MapServer with a single script in the scripts/tiles/ directory. To do so, all one must do is navigate to that directory in their Cyclopath install and run:
$ ./setup.sh
This script downloads both TileCache and MapServer, installs both in $CPROOT/tilecache and $CPROOT/mapserver respectively, and also copies over the necessary configuration and layers files for both. After this script is run, you will be given an output of what needs to be added to your apache configuration, as well as a reminder to run fixperms on these two directories. Follow those instructions to get both running in no time. What follows below explains in more depth how MapServer and TileCache render and serve our raster tiles.
[edit] Tile Caching
[edit] Installing
The installation of TileCache is now done entirely through usage of the setup.sh script found in the scripts/tiles directory. Essentially all this script does is check out a copy of TileCache 2.10, copies our configuration file to it, and moves it to $CPROOT, then prints out directions for what needs to be added to the apache configuration to make it work.
[edit] Configuration Editing
The configuration file for TileCache is found in $CPROOT/tilecache if you followed the install approach above. Almost everything within it is well-commented and documented, and the only things that would need potential alterations are the location of the cache itself and the addition of the various WMS layers you'd like to be cached. A few issues cropped up during configuration when adding WMS layers that weren't easily fixable (Mainly involving resolutions and different errors being returned), so defined below is an example of one of the external WMS layers we are using, along with comments explaining each part in detail.
# Example LMIC Layer # This is the "name" field for a layer returned by the WMS GetCapabilities request: [msp2006] # For our purposes, always set this to WMS: type=WMS # When performing a WMS GetCapabilities request, this link will be found in the # GetMap section of the returned XML document: url=http://geoint.lmic.state.mn.us/cgi-bin/wms? # Currently LMIC only supports serving jpegs: extension=jpeg # The size of tiles to cache is currently 256x256: size=256,256 # This bounding box is based on the maximum extents of the old aerial imagery. # Use this for any layers added unless you know the bounding box you're setting # will create an exact number of 256x256 tiles in the exact placement that Cyclopath # will request them from, otherwise tilecache will complain later when you make WMS # requests. bbox=393216,4915200,524288,5046272 # Current spatial reference system being used: srs=EPSG:26915 # Every resolution (Read: meters/pixel at each zoom level) needs to be listed # explicitly because tilecache isn't smart. Not doing this makes tilecache # generate its own resolutions, most of which make no sense. resolutions=2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768
Once this is completed, tiles can be fetched from the cache using the following link structure:
http://localhost/tiles?LAYERS=msp2006&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:26915&BBOX=425984,4915200,458752,4947968&WIDTH=256&HEIGHT=256&FORMAT=image/jpeg
The above link is based on the assumption that the layer we're asking for is msp2006, and that the bounding box is the exact one defined above and that some 256x256 tile corresponds exactly to it. Tilecache doesn't seem to be very smart with parsing WMS requests in general, either, so no matter what you specify for height and width, the result returned will be a 256x256 tile. The arguments are necessary, however, for it to fetch the tile in the first place.
Also, an example of a MapServer layer:
[layer9] type=WMS layers=bmpolygons9,shadows9,byways9,byway_names9 url=http://localhost/wms? extension=png size=256,256 bbox=0,0,524288,5013504 srs=EPSG:26915 resolutions=128 extent_type=loose
[edit] Seeding the Cache
See the official TileCache documentation for the most up-to-date version of the tilecache_seed.py script and how to use it, included by default with your tilecache installation. Currently, seeding the cache is a simple (But time-consuming for higher zoom levels) process because most of the results will be cache misses the first time it is run. To seed your tilecache for the first time, navigate to the scripts/tiles install directory and run:
$ ./cache_initialize.sh
Default bounding box used for Twin Cities is: 393216,4915200,491520,5013504
[edit] Cleaning the Cache
See the TileCache documentation for a very simple explanation for this.
[edit] Web Map Service Requests
[edit] MapServer
[edit] Installation
Currently, the best solution found for WMS'ing raster tiles has been MapServer. This document assumes that MapServer has already been installed with the necessary configuration settings (PROJ.4 support, WMS_SERVER support need to be specified explicitly - the rest will be included by default) by the setup.sh script found in the scripts/tiles directory. For more information on compiling on Unix, seek the MapServer documentation or contact Systems staff.
1. To make sure your MapServer install has been compiled correctly, run the following command in the directory where you've compiled mapserv and make sure your output includes at least the output shown below:
user@machine ($CPROOT/mapserver/mapserv) % ./mapserv -v MapServer version 5.4.2 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=WBMP OUTPUT=SVG SUPPORTS=PROJ SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=ICONV SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=GEOS INPUT=EPPL7 INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE
2. For the layers that are fetched by MapServer, the setup.sh script does most of the work for this as well. If you'd like more information on how MapServer generates layers, please see the documentation. In our structure, each zoom layer has its own file which defines its drawing parameters and what geometry it needs to show.
3. The setup.sh script will also inform you of what directives need to be added to the Apache configuration for MapServer to work. Don't forget to also remove the old directives for the /tiles/ directory if you have not yet, and run fixperms on the mapserver directory!
[edit] Making Sure It Works
Visit this link on your machine to see if MapServer has been installed correctly. The result should be an output PNG tile.
For more information on using the Mapfile or other MapServer components, check the MapServer documentation.
[edit] Available WMS Streams
- LMIC (Currently what we use)
