Vishful thinking…

Setting up TileCache on IIS

Posted in Uncategorized by viswaug on February 3, 2008

This is a guide to setting up TileCache on IIS for non-Python people (like me 🙂 ). TileCache is an amazing piece of software that can cache the data from any WMS service, thereby speeding up access to the WMS service in the magnitude of 10 – 100 times or more. I am a big fan of the open source GIS tools coming out from Metacarta labs like FeatureServer and TileCache. If you haven’t checked out the other projects coming out of there, please try to make the time to check them out, it is definitely it. But the fact that they are all in Python had been a big obstacle for me (being a Microsoft guy and all) when I wanted to test them out. I finally got around to setting up TileCache on my IIS today, and if you are interested in doing the same, follow along.

  • Download the windows installer for the latest version (2.5.1) of Python from here. I had Python version 2.4 installed on my machine from an ESRI software setup(Python is an optional component). So the screenshots you see might not agree with the version numbers.
  • It is also a really good idea to install Win32all (Mark Hammond’s add-on for the regular Python installer (also including the Win32 API, COM support, and Pythonwin)) from here.
  • Run the Python installer for windows and install Python to its default location “C:\Python25\”.CropperCapture[5]
  • Setup the Python install directory in the system environment ‘PATH’ variable. Right-click on ‘My Computer’ and select ‘Properties’. Click on the ‘Advanced’ tab. Click on the ‘Environment Variables’ button. In the ‘Environment Variables’ dialog, select ‘PATH’ from the ‘System Variables’ group.
    • CropperCapture[6]
    • Click the ‘Edit button and add your Python path (C:\Python25\) to the end of the current PATH value.
    • CropperCapture[7]
  • Download TileCache from here (version 2.01). Unzip its contents to ‘C:\Inetpub\wwwroot\tilecache’. This is just my location of preference, it can obviously be setup as a virtual directory at any path desired.
    • CropperCapture[8]
  • Setup the unzipped ’tilecache’ directory as an application in IIS. Click ‘Start->Run’ and type in ‘inetmgr’ and click ok. This brings up the Internet Service Manager (ISM).
  • Now, we need to setup IIS to run Python scripts. Find ’tilecache’ under ‘Default Web Site’ and right-click to select properties.
    • CropperCapture[9]
    • In the ‘Directory’ tab, under the ‘Application Settings’ section, the ‘Application Name’ and its value should be disabled. Click the ‘Create’ button next to it. This should setup ’tilecache’ as the application name. Click OK to exit the dialog.
    • CropperCapture[10]
  • In the ISM, right-click on ‘Default Web Site’ and select ‘Properties’. Under the ‘Home Directory’ tab, select the ‘Configuration’ button.
    • CropperCapture[22]
    • This should bring up the ‘Application Configuration’ dialog, Click on the ‘Add’ button. This brings up the ‘Add/Edit Application Extension Mapping’ dialog. In the executable field, enter ‘C:\Pythin25\pythin.exe %s %s’. In the extension field, enter ‘.py’. Check both ‘Script engine’ and ‘Check that file exists’ options.
    • CropperCapture[13]
    • This should add a new entry for ‘.py’ in the ‘Application Configuration’ dialog.
    • CropperCapture[14]
  • Open up the command prompt and change directory to ‘C:\Inetpub\AdminScripts’. Execute the following
    • adsutil set w3svc/AllowPathInfoForScriptMappings True
    • adsutil set w3svc/1/AllowPathInfoForScriptMappings True
  • Rename ‘C:\Inetpub\wwwroot\tilecache\tilecache.cgi’ to ‘C:\Inetpub\wwwroot\tilecache\tilecache.py’.
  • Edit ‘C:\Inetpub\wwwroot\tilecache\tilecache.py’ and remove the first line in it that reads ‘#!/usr/bin/env python‘. Also, change the ‘Service.Load’ parameter to ‘C:\\Inetpub\\wwwroot\\tilecache\\tilecache.cfg’ like shown within quotes.
    • CropperCapture[19]
  • Create a directory called ‘Cache’ under ‘C:\Inetpub\wwwroot\tilecache\’. This is where to generated cache will be outputted. Give write permissions to the ‘Internet Guest account’ to this directory since the cache generated will be written to this location. I am using these settings just for a demonstration, please do take the time to setup the security properly as per your requirements.
  • Edit ‘C:\Inetpub\wwwroot\tilecache\tilecache.cfg’. Change the value for ‘base’ under the ‘[Cache]’ section to ‘C:\Inetpub\wwwroot\tilecache\Cache’, the directory where the cache will be outputted.
    • From CropperCapture[15]
    • To     CropperCapture[16]
  • Also, change the ‘url’ value under the ‘[basic]’ to the URL of the WMS service that you want cached. Here ‘[basic]’ is the name of the layer you want cached. Configure it accordingly for the WMS servoce you are using. I am leaving it at the defaults as shown below to generate a cache for the WMS service from Metacarta with the layer name ‘basic’.
    • CropperCapture[17]
  • Edit ‘C:\Inetpub\wwwroot\tilecache\index.html’. Under the ‘init’ function, change the parameters for the WMS layer from ’tilecache.cgi?’ to ’tilecache.py?’.
    • CropperCapture[18]
  • That is it. Congratulations! Your TileCache has been configured on IIS. Point your browser to ‘http://localhost/tilecache/index.html’ and start browsing around. You will generating the cache as you browse around.
    • CropperCapture[20]
    • Look in your ‘C:\Inetpub\wwwroot\tilecache\Cache’ directory as the cache is generated. The ‘basic’ folder is the name of the WMS layer being cached. You should be able to see a whole bunch directory and files being generated when browsing around.
    • CropperCapture[21]
  • Now, you generating cache as you browse around the map, but you don’t want to be browsing all around the map at all scales to fully generate the cache. In order to generate the cache for the desired region automatically, a python utility script has been provided with TileCache. To run the script, open up command prompt and execute the following.
    • python “C:\Inetpub\wwwroot\tilecache\tilecache_seed.py” “http://localhost/tilecache/tilecache.py?” basic 0 2
    • This generates the cache for the basic layer between scales 0 and 2. Please be aware that as you start increasing the scale range (0 to 6 etc), the time required to generate the cache will exponentially increase.
  • Now all that is left to do is to have OpenLayers start using your cache directly. In order to do so, edit the ‘C:\Inetpub\wwwroot\tilecache\index.html’ file again and point the WMS layer to your cache as shown below.
    • CropperCapture[25]
  • Sit back, browse you super fast web application and enjoy.

Please do let me know how the guide above works out for you or if you have any suggestions or improvements.