GeoServer GeoWebCache Configuration

This documentation is no longer maintained. Please see the new GeoServer documentation at http://docs.geoserver.org

GeoServer and GeoWebCache Configuration

This tutorial applies to GeoServer 1.7.2 and above.

This tutorial assumes that GeoServer is up and running on http://localhost:8080.
*Substitute localhost:8080 with your domain depending on your installation

Introduction

Step One:Learn the Directory Structure and Fill It In
Step Two:Learn How to Seed
Step Three:Visualize Some of the Tiles
Step Four:Control the Tiling Requests

Introduction

GeoWebCache can function as a stand-alone server, but documentation on its integration with GeoServer was confusing when I recently delved in to this technology. I was originally looking at TileCache, but the folks at GeoServer have been recommending GeoWebCache. Since GeoWebCache was included in the GeoServer 1.7.2, I thought the configuration would be a matter of simply going through the proxy, but there was a little more to it.

Configuration of GeoWebCache as a proxy tiling agent for GeoServer is the subject of this tutorial.

Step One: Learn the Directory Structure and Fill It In

A good place to begin is analyzing the GeoServer-GeoWebCache directory structure. When you have a new installation of Geoserver, the directories that GeoWebCache uses do not exist. With a typical GeoServer installation, the directory structure ends at: C:\Program Files\GeoServer 1.7.2\data_dir\gwc
At this point, enter the following in a browser: http://localhost:8080/geoserver/gwc/demo (Figure 1.)

This will pop up the demo page and simultaneously fill in the directory structure under \data_dir\gwc with folders that are named for the GeoServer namespace _ datastore combinations. (Figure 2.)
These are the directories that will store the cached tiles in their own folder structure. These tiles can be stored in other locations, and in different manners by modifying the web.xml and geowebcache-servlet.xml as discussed over at geowebcache.org.

Step Two: Learn How to Seed

To see how the seeding (creation of tile(s)) works, click on one of the Open Layers layer name links on the demo page to see one get seeded. Depending on which layer you chose, navigate back to the directory structure on your system C:\Program Files\GeoServer 1.7.2\data_dir\gwc\namespace_datastore\Tile Folders. The Tile Folders are named with the letters EPSG, then the projection code, then the zoom level e.g. EPSG_4326_11, so a full path might appear as: C:\Program Files\GeoServer 1.7.2\data_dir\gwc\sf_roads\EPSG_4326_11
You should see some image tiles under that directory. (Figure 3.)

To actually seed a layer, click the Seed this Layer link. It will take you to the main seeding interface.

The options are pretty straight forward. You can:

  • Choose to run multiple threads
  • Reseed: all the tiles, missing tiles or remove tiles
  • Modify your output projection
  • Change the image format
  • Declare your Zoom start and stop levels
  • Issue a different bounding box for the process. Note: Max extents will used if this is not declared.
    Kick this off with the Submit button and you can watch the tiles being generated through the interface or keep an eye on your directory structure.

Step Three: Visualize Some of the Tiles

After your tiles have been generated, the OpenLayers link on the demo page is ok for taking a look at your tiles, but the reference is only that layer. To have some real fun, try a Network Link in Google Earth. This is easily found in Google Earth under the Add menu. Drop a URL in there similar to the following: http://localhost:8080/geoserver/gwc/service/kml/sf:roads.png.kml
In this case, the sf represents the namespace in GeoServer, and roads is the datastore. Basically, you're taking your geocache folder that is separate by a _ and replacing it with a : Then, you have a .png.kml to output a png image in kml accessible by Google Earth.

Step Four: Control the Tiling Requests

GeoServer does not deploy an important file that configures GeoWebCache, geowebcache.xml. GeoWebCache will still work without it, but there's no control over tiling. The geowebcache.xml must be deployed to the caching directory to be picked up by GeoServer. If you haven't modified the tile location, then you would drop it under the \gwc\ directory, and restart GeoServer. This file is important in controlling the tiling requests being made of GeoWebCache for a datasource. You'll need to add and modify this file if you don't want to accept all the defaults for all tile levels within the full extent. The geowebcache.xml is fully documented over at geowebcache.org, but I want to hit some of the tag highlights here:

  • <backendTimeout> - This tag was helpful to me on getting some threads going on an older server. It can take more than 120 seconds for the initialization of some threads. Make this a larger number to get those threads going.
  • <name> - This is the same combination we have seen along, the namespace:datastore.
  • <coords> - The order here is Xmin,Ymin,Xmax,Ymax
  • <zoomStart> <zoomStop> - These are your zoom levels. This will help you control what levels you want users to be able to see and generate.
geowebcache.xml
<?xml version="1.0" encoding="utf-8"?>
<gwcConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                  xsi:noNamespaceSchemaLocation="http://geowebcache.org/schema/1.0.1/geowebcache.xsd" 
                  xmlns="http://geowebcache.org/schema/1.0.1">
<version>1.0.1</version>
<backendTimeout>120</backendTimeout>
<cacheBypassAllowed>true</cacheBypassAllowed>
<layers>
<wmsLayer> 
<name>sf:roads</name> 
<mimeFormats> 
	<string>image/png</string> 
	<string>image/jpeg</string> 
</mimeFormats>
	<!-- The following are the grid definitions. You need one entry for every SRS -->
	<grids>
		<entry>
			<!-- This is actually the dump of a hash table, so the SRS shows up in both the key and the value -->
			<srs>
				<number>4326</number>
			</srs>
			<grid>
				<srs>
					<number>4326</number>
				</srs>
				<!-- This defines the extent of your data and prevents GeoWebCache from 
             requesting blank tiles from the backend, thereby saving storage and
             responding faster. -->
				<dataBounds>
					<coords>
						<double>-103.87</double>
						<double>44.37</double>
						<double>-103.62</double>
						<double>44.50</double>
					</coords>
				</dataBounds>
				<!-- Grid bounds define the origin and extent of the grid, they ultimately
             determine what indexes GWC uses for each tile internally. If the SRS
             has a natural "maximum extent", like -180.0,-90.0,180.0,90.0 , then
             that's a good value to use. Otherwise use the max extent that your data
             could possibly grow to. If in doubt, just copy the coords from dataBounds. -->
				<gridBounds>
					<coords>
						<double>-103.87</double>
						<double>44.37</double>
						<double>-103.62</double>
						<double>44.50</double>
					</coords>
				</gridBounds>
				<zoomStart>0</zoomStart>
				<zoomStop>7</zoomStop>
			</grid>
		</entry>
	</grids>
<wmsUrl> 
<string>http://localhost:8080/geoserver/wms</string> <!-- /gwc/service/-->
</wmsUrl> 
<wmsLayers>sf:roads</wmsLayers>
 </wmsLayer> 

</layers>
</gwcConfiguration>

Added by Mark Rodrigo, last edited by Mark Rodrigo on Feb 05, 2009  (view change)
View Attachments (4) Info