GeoWebCache的安装
SmartMap 科技
GeoWebCache配置地图缓存
GIS Pathfinder
2010-01-30
详细讲解了GeoWebCache配置地图缓存的配置过程
GeoWebCache配置地图缓存
1.下载geowebcache-1.2.1-WAR.zip,解压到“D:\Program Files\Eclipse\apache-tomcat-6.0.20\webapps\geowebcache”中:
下载地址:http://geowebcache.org/trac
2.在“D:\Program Files\Eclipse\apache-tomcat-6.0.20\webapps\geowebcache\”目录下新建一子目录“Cache”,用于存放生成的缓存地图切片。
3.编辑geowebcache-servlet.xml文件(“D:\Program Files\Eclipse\apache-tomcat-6.0.20\webapps\geowebcache\WEB-INF\geowebcache-servlet.xml”)。
由于我的Tomcat所用服务的端口为:8020,所以需要将相关的服务端口改为:8020
1)将
改为:
2)将
改为:
3)修改缓存图片的路径:
将
改为:
4)完整的geowebcache-servlet.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="gwcAppCtx" class="org.geowebcache.util.ApplicationContextProvider" />
<!-- The location of a static configuration file for GeoWebCache.
By default this lives in WEB-INF/classes/geowebcache.xml -->
<bean id="gwcXmlConfig" class="org.geowebcache.config.XMLConfiguration">
<constructor-arg ref="gwcAppCtx" />
<constructor-arg ref="gwcGridSetBroker"/>
<constructor-arg ref="gwcDefaultStorageFinder" />
<!-- Other examples: -->
<!--property name="relativePath"><value>../resources</value></property -->
<!--property name="relativePath"><value>/WEB-INF/classes</value></property-->
<!--property name="absolutePath"><value>/etc/geowebcache/conf</value></property-->
</bean>
<!-- If you like to automatically configure GWC from a WMS Getcapabilities document,
change the values below. The last constructor-arg lets you specify parameters
that are appended to every WMS request to the backed, for example:
"format_options=regionate_by:auto&bgcolor=0x112233" -->
<bean id="gwcWMSConfig" class="org.geowebcache.config.GetCapabilitiesConfiguration">
<constructor-arg ref="gwcGridSetBroker"/>
<!-- The URL to the WMS GetCapabilities document -->
<constructor-arg value="http://localhost:8020/geoserver/wms?service=WMS&request=GetCapabilities" />
<!-- constructor-arg value="http://dk.nunagis.gl/wms?servicename=nuk0600_wms_g5&version=1.1.0&service=WMS&request=getcapabilities"/ -->
<!-- constructor-arg value="http://www.nasa.network.com/elev?service=WMS&request=GetCapabilities" /-->
<!-- The formats to support for all layers read for the above document -->
<constructor-arg value="image/png,application/bil16,application/bil32"/>
<!-- Metatiling factors, 3x3 is usually a good compromise for vector data -->
<constructor-arg value="3x3"/>
<!-- Vendor parameters, these are appended to every request sent to the backend.
If you use MapServer you probably want to set this to "map=name" -->
<constructor-arg value=""/>
<!-- Whether to allow cached=false to specificed for certain requests -->
<constructor-arg value="false"/>
</bean>
<!-- For each configuration bean above, add them below to activate -->
<bean id="gwcTLDispatcher" class="org.geowebcache.layer.TileLayerDispatcher">
<constructor-arg ref="gwcGridSetBroker"/>
<constructor-arg>
<list>
<ref bean="gwcWMSConfig" />
<ref bean="gwcXmlConfig" />
</list>
</constructor-arg>
</bean>
<bean id="gwcDefaultStorageFinder" class="org.geowebcache.storage.DefaultStorageFinder">
<constructor-arg ref="gwcAppCtx" />
</bean>
<bean id="gwcMetaStore" class="org.geowebcache.storage.metastore.jdbc.JDBCMetaBackend" destroy-method="destroy">
<constructor-arg ref="gwcDefaultStorageFinder" />
</bean>
<!-- Static definition of where to put the metastore.
Note that the directory is AUTOMATICALLY CREATED if it does not exist. -->
<!-- bean id="gwcMetaStore" class="org.geowebcache.storage.metastore.jdbc.JDBCMetaBackend" destroy-method="destroy">
<constructor-arg value="org.h2.Driver" />
<constructor-arg value="jdbc:h2:file:/tmp/gwc_metastore/h2_metastore;TRACE_LEVEL_FILE=0" />
<constructor-arg value="username" />
<constructor-arg value="password" />
</bean -->
<bean id="gwcBlobStore" class="org.geowebcache.storage.blobstore.file.FileBlobStore" destroy-method="destroy">
<constructor-arg value="D:/Program Files/Eclipse/apache-tomcat-6.0.20/webapps/geowebcache/Cache" />
</bean>
<!-- Static definition of where to put the blobstore.
Note that the directory MUST EXIST when GWC is started. -->
<!-- bean id="gwcBlobStore" class="org.geowebcache.storage.blobstore.file.FileBlobStore" destroy-method="destroy">
<constructor-arg value="/tmp/gwc_blobstore" />
</bean -->
<bean id="gwcStorageBroker" class="org.geowebcache.storage.StorageBroker" destroy-method="destroy">
<constructor-arg ref="gwcMetaStore" />
<constructor-arg ref="gwcBlobStore" />
<property name="verifyFileSize" value="TRUE"/>
</bean>
<bean id="gwcGridSetBroker" class="org.geowebcache.grid.GridSetBroker">
<!-- Should we used EPSG:900913 instead of EPSG:3857 ? -->
<constructor-arg type="boolean" value="TRUE" />
<!--
Should the default grids be named EPSG:4326 and EPSG:90091,
or use the new names? If you say no here, you have to manually
rename the directories and entries in the H2 database.
-->
<constructor-arg type="boolean" value="TRUE" />
</bean>
<bean id="gwcRuntimeStats" class="org.geowebcache.stats.RuntimeStats" destroy-method="destroy">
<!-- The poll interval, the number of seconds until counters are aggregated -->
<constructor-arg type="int" value="3" />
<!-- The intervals (in seconds) for which aggregates are reported.
Each interval must be a multiple of the poll interval above and
listed in ascending order. For example, for a maximum interval
of 60 seconds and 3 second poll interval from above, the amount
of memory consumed is (60 / 3) * 8 = 160 bytes
-->
<constructor-arg>
<list>
<value>3</value>
<value>15</value>
<value>60</value>
</list>
</constructor-arg>
<!-- Descriptive texts for each of the intervals above -->
<constructor-arg>
<list>
<value>3 seconds</value>
<value>15 seconds</value>
<value>60 seconds</value>
</list>
</constructor-arg>
</bean>
<!-- controller for handling all incoming requests -->
<bean id="geowebcacheDispatcher" class="org.geowebcache.GeoWebCacheDispatcher" destroy-method="destroy">
<constructor-arg ref="gwcTLDispatcher"/>
<constructor-arg ref="gwcGridSetBroker"/>
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg ref="gwcXmlConfig"/>
<constructor-arg ref="gwcRuntimeStats"/>
<property name="defaultStorageFinder" ref="gwcDefaultStorageFinder"/>
</bean>
<!-- WMS based services -->
<bean id="gwcServiceWMS"
class="org.geowebcache.service.wms.WMSService">
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg ref="gwcTLDispatcher"/>
<property name="proxyRequests"><value>TRUE</value></property>
</bean>
<bean id="gwcServiceGMaps"
class="org.geowebcache.service.gmaps.GMapsConverter">
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg ref="gwcTLDispatcher"/>
<constructor-arg ref="gwcGridSetBroker"/>
</bean>
<bean id="gwcServiceMGMaps"
class="org.geowebcache.service.mgmaps.MGMapsConverter">
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg ref="gwcTLDispatcher"/>
<constructor-arg ref="gwcGridSetBroker"/>
</bean>
<bean id="gwcServiceVE"
class="org.geowebcache.service.ve.VEConverter">
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg ref="gwcTLDispatcher"/>
<constructor-arg ref="gwcGridSetBroker"/>
</bean>
<bean id="gwcServiceKML"
class="org.geowebcache.service.kml.KMLService">
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg ref="gwcTLDispatcher"/>
<constructor-arg ref="gwcGridSetBroker"/>
<constructor-arg ref="gwcRuntimeStats"/>
</bean>
<bean id="gwcServiceTMS"
class="org.geowebcache.service.tms.TMSConverter">
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg ref="gwcTLDispatcher"/>
</bean>
<bean id="gwcServiceWMTS"
class="org.geowebcache.service.wmts.WMTSService">
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg ref="gwcTLDispatcher"/>
<constructor-arg ref="gwcGridSetBroker"/>
</bean>
<!-- WFS based services -->
<bean id="gwcServiceWFS"
class="org.geowebcache.service.wfs.WFSService">
<constructor-arg ref="gwcStorageBroker"/>
<constructor-arg value="http://localhost:8020/geoserver/wfs" />
<constructor-arg value="" />
<constructor-arg value="600" />
</bean>
<!-- Thread pool for seeding -->
<bean id="gwcSeederThreadPoolExec"
class="org.geowebcache.rest.seed.SeederThreadPoolExecutor">
<constructor-arg value="16"/><!-- Size of core pool -->
<constructor-arg value="32"/><!-- Maximum size of pool -->
</bean>
<!-- Restlets -->
<bean id="gwcSeedRestlet" class="org.geowebcache.rest.seed.SeedRestlet">
<property name="tileLayerDispatcher" ref="gwcTLDispatcher"/>
<property name="threadPoolExecutor" ref="gwcSeederThreadPoolExec"/>
<property name="storageBroker" ref="gwcStorageBroker"/>
</bean>
<bean id="gwcSeedFormRestlet" class="org.geowebcache.rest.seed.SeedFormRestlet">
<property name="tileLayerDispatcher" ref="gwcTLDispatcher"/>
<property name="threadPoolExecutor" ref="gwcSeederThreadPoolExec"/>
<property name="storageBroker" ref="gwcStorageBroker"/>
<property name="seedRestlet" ref="gwcSeedRestlet"/>
</bean>
<bean id="gwcReloadRestlet" class="org.geowebcache.rest.reload.ReloadRestlet">
<property name="tileLayerDispatcher" ref="gwcTLDispatcher"/>
</bean>
<bean id="gwcTileLayerRestlet" class="org.geowebcache.rest.layers.TileLayerRestlet">
<property name="XMLConfiguration" ref="gwcXmlConfig"/>
<property name="tileLayerDispatcher" ref="gwcTLDispatcher"/>
</bean>
<bean id="gwcBoundsRestlet" class="org.geowebcache.rest.bounds.BoundsRestlet">
<property name="tileLayerDispatcher" ref="gwcTLDispatcher"/>
</bean>
<bean id="gwcFilterUpdateRestlet" class="org.geowebcache.rest.filter.FilterUpdateRestlet">
<constructor-arg ref="gwcTLDispatcher"/>
</bean>
<bean id="gwcByteStreamerRestlet" class="org.geowebcache.rest.webresources.ByteStreamerRestlet" />
<!-- REST Dispatcher -->
<bean id="gwcRestDispatcher" class="org.geowebcache.rest.RESTDispatcher">
<constructor-arg type="java.util.Map">
<map>
<entry>
<key><value>/seed/{layer}.{extension}</value></key>
<ref bean="gwcSeedRestlet" />
</entry>
<entry>
<key><value>/seed/{layer}</value></key>
<ref bean="gwcSeedFormRestlet" />
</entry>
<entry>
<key><value>/reload</value></key>
<ref bean="gwcReloadRestlet" />
</entry>
<entry>
<key><value>/layers/{layer}.{extension}</value></key>
<ref bean="gwcTileLayerRestlet" />
</entry>
<entry>
<key><value>/bounds/{layer}/{srs}/{type}</value></key>
<ref bean="gwcBoundsRestlet" />
</entry>
<entry>
<key><value>/filter/{filterName}/update/{updateType}</value></key>
<ref bean="gwcFilterUpdateRestlet" />
</entry>
<entry>
<key><value>/web/{filename}</value></key>
<ref bean="gwcByteStreamerRestlet" />
</entry>
</map>
</constructor-arg>
</bean>
<bean id="gwcProxyDispatcher"
class="org.geowebcache.proxy.ProxyDispatcher"/>
<bean id="gwcUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true"/>
<property name="mappings">
<props>
<prop key="/rest/**">gwcRestDispatcher</prop>
<prop key="/service/**">geowebcacheDispatcher</prop>
<prop key="/demo/**">geowebcacheDispatcher</prop>
<prop key="/proxy/**">gwcProxyDispatcher</prop>
<prop key="/home">geowebcacheDispatcher</prop>
</props>
</property>
</bean>
</beans>
4.编辑geowebcache.xml文件(“D:\Program Files\Eclipse\apache-tomcat-6.0.20\webapps\geowebcache\WEB-INF\classes\geowebcache.xml”)。
1) 添加gridSet
可参考:http://geowebcache.org/docs/current/concepts/gridset.html
在<gridSets></gridSets>节点添加如下的gridSet
<gridSet>
<name>EPSG:42304 Grid Set</name>
<srs><number>42304</number></srs>
<extent>
<coords>
<double>-2200000</double>
<double>-712631</double>
<double>3072800</double>
<double>3840000</double>
</coords>
</extent>
<alignTopLeft>false</alignTopLeft>
<resolutions>
<double>14062.5</double>
<double>7031.25</double>
<double>3515.625</double>
<double>1757.8125</double>
<double>878.90625</double>
<double>439.453125</double>
</resolutions>
<tileHeight>256</tileHeight>
<tileWidth>256</tileWidth>
</gridSet>
2) 添加MapServer的WMS服务
可参考:C:\Users\zhangyongxin\Desktop\OpenLayers\TileCache\geowebcache-1.2.1-DOC\geowebcache-1.2.1-docs\configuration\xml\exhaustive.html
在<layers></layers>节点添加如下的wmsLayer
<wmsLayer>
<name>gmap</name>
<mimeFormats><string>image/png</string></mimeFormats>
<!-- Grid Subset Example -->
<gridSubsets>
<gridSubset>
<gridSetName>EPSG:42304 Grid Set</gridSetName>
<extent>
<coords>
<double>-2200000</double>
<double>-712631</double>
<double>3072800</double>
<double>3840000</double>
</coords>
</extent>
</gridSubset>
</gridSubsets>
<wmsUrl>
<string>http://localhost:8040/cgi-bin/mapserv.exe?MAP=/ms4w/apps/gmap/htdocs/gmap75_wms.map&</string>
</wmsUrl>
<wmsLayers>bathymetry,land_fn</wmsLayers>
<transparent>false</transparent>
<bgColor>0x0066FF</bgColor>
<expireCacheList>
<expirationRule minZoom="0" expiration="60" />
</expireCacheList>
<expireClientsList>
<expirationRule minZoom="0" expiration="500" />
</expireClientsList>
</wmsLayer>
3)完整的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.2.1/geowebcache.xsd"
xmlns="http://geowebcache.org/schema/1.2.1">
<version>1.2.1</version>
<backendTimeout>120</backendTimeout>
<gridSets>
<!-- Grid Set Example, by default EPSG:900913 and EPSG:4326 are defined -->
<gridSet>
<name>EPSG:2163 Grid Set</name>
<srs><number>2163</number></srs>
<extent>
<coords>
<double>-2495667.977678598</double>
<double>-2223677.196231552</double>
<double>3291070.6104286816</double>
<double>959189.3312465074</double>
</coords>
</extent>
<scaleDenominators>
<double>25000000</double>
<double>1000000</double>
<double>100000</double>
<double>25000</double>
</scaleDenominators>
<tileHeight>200</tileHeight>
<tileWidth>200</tileWidth>
</gridSet>
<gridSet>
<name>EPSG:42304 Grid Set</name>
<srs><number>42304</number></srs>
<extent>
<coords>
<double>-2200000</double>
<double>-712631</double>
<double>3072800</double>
<double>3840000</double>
</coords>
</extent>
<alignTopLeft>false</alignTopLeft>
<resolutions>
<double>14062.5</double>
<double>7031.25</double>
<double>3515.625</double>
<double>1757.8125</double>
<double>878.90625</double>
<double>439.453125</double>
</resolutions>
<tileHeight>256</tileHeight>
<tileWidth>256</tileWidth>
</gridSet>
</gridSets>
<layers>
<wmsLayer>
<name>topp:states</name>
<gridSubsets>
<gridSubset>
<gridSetName>EPSG:2163 Grid Set</gridSetName>
</gridSubset>
</gridSubsets>
<wmsUrl><string>http://atlas.openplans.org:8080/geoserver/wms</string></wmsUrl>
</wmsLayer>
<wmsLayer>
<name>raster test layer</name>
<mimeFormats><string>image/jpeg</string></mimeFormats>
<wmsUrl><string>http://atlas.openplans.org:8080/geoserver/wms</string></wmsUrl>
<wmsLayers>nurc:Img_Sample</wmsLayers>
</wmsLayer>
<wmsLayer>
<name>img states</name>
<mimeFormats><string>image/gif</string></mimeFormats>
<!-- Grid Subset Example -->
<gridSubsets>
<gridSubset>
<gridSetName>EPSG:4326</gridSetName>
<extent>
<coords>
<double>-129.6</double>
<double>3.45</double>
<double>-62.1</double>
<double>70.9</double>
</coords>
</extent>
</gridSubset>
</gridSubsets>
<wmsUrl>
<string>http://atlas.openplans.org:8080/geoserver/wms</string>
</wmsUrl>
<wmsLayers>nurc:Img_Sample,topp:states</wmsLayers>
<transparent>false</transparent>
<bgColor>0x0066FF</bgColor>
<expireCacheList>
<expirationRule minZoom="0" expiration="60" />
</expireCacheList>
<expireClientsList>
<expirationRule minZoom="0" expiration="500" />
</expireClientsList>
</wmsLayer>
<wmsLayer>
<name>gmap</name>
<mimeFormats><string>image/png</string></mimeFormats>
<!-- Grid Subset Example -->
<gridSubsets>
<gridSubset>
<gridSetName>EPSG:42304 Grid Set</gridSetName>
<extent>
<coords>
<double>-2200000</double>
<double>-712631</double>
<double>3072800</double>
<double>3840000</double>
</coords>
</extent>
</gridSubset>
</gridSubsets>
<wmsUrl>
<string>http://localhost:8040/cgi-bin/mapserv.exe?MAP=/ms4w/apps/gmap/htdocs/gmap75_wms.map&</string>
</wmsUrl>
<wmsLayers>bathymetry,land_fn</wmsLayers>
<transparent>false</transparent>
<bgColor>0x0066FF</bgColor>
<expireCacheList>
<expirationRule minZoom="0" expiration="60" />
</expireCacheList>
<expireClientsList>
<expirationRule minZoom="0" expiration="500" />
</expireClientsList>
</wmsLayer>
</layers>
</gwcConfiguration>
5.启动Tomcat服务,预生成缓存图片。
在IE中打开网址为:http://localhost:8020/geowebcache/home的网页
点击“A list of all the layers and automatic demos”,进入如下的页面
点击“Seed this layer”
在弹出的输入用户名与密码的对话框中输入如下的信息后点“确定”按钮,进入如下的页面
用户名:geowebcache
密码:secured
将“Zoom stop:”下拉列表框选择最大的数,后点击“Submit”按钮
进入如下的页面
可以查看Tomcat中的输出信息
6.调用GeoWebCache地图切片缓存的ASPNET+OpenLayers客户端的代码为:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MapServer.aspx.cs" Inherits="ASPNETAJAXDemo.OpenLayersWebGIS.MapServer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>访问ArcIMS服务的Demo</title>
<link rel="stylesheet" href="theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="lib/OpenLayers.js"></script>
<script type="text/javascript">
var lon = 436400;
var lat = 1563684.5;
var zoom = 100;
var map, layer;
function init() {
var optionsMap = {
maxExtent: new OpenLayers.Bounds(-2200000, -712631, 3072800, 3840000),
maxResolution: 100,
units: 'm',
projection: "EPSG:42304",
};
map = new OpenLayers.Map("map", optionsMap);
// GeoWebCache
layer = new OpenLayers.Layer.WMS(
"gmap",
"http://localhost:8020/geowebcache/service/wms/",
//"",
{
layers: "gmap",
format: "image/png",
transparent: "off"
},
{
maxExtent: new OpenLayers.Bounds(-2200000, -712631, 3072800, 3840000),
maxResolution: 14062.5,
resolutions: [14062.5,7031.25,3515.625,1757.8125,878.90625,439.453125],
//numZoomLevels: 5,
projection: "EPSG:42304",
units: "m"
}
);
map.addLayer(layer);
map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
//去掉所有缺省的地图操作控件
var controlArray = new Array();
var count = map.controls.length;
for (var i = 0; i < count; i++) {
var control = map.controls[i];
controlArray.push(control.id);
}
//alert(controlArray);
for (var i = 0; i < count; i++) {
var control = map.getControl(controlArray[i]);
//map.removeControl(control);
}
//添加新地地图操作控件
//map.addControl(new OpenLayers.Control.OverviewMap());
//map.addControl(new OpenLayers.Control.PanZoomBar());
alert(map.getResolution());
}
</script>
</head>
<body onload="init()">
<form id="form1" runat="server">
<h1 id="title" align="center">访问ArcIMS服务的Demo</h1>
<div id="map" align="center" class="smallmap"></div>
<div id="docs" align="center">
SmartMap Technology(By GIS Pathfinder)
</div>
</form>
</body>
</html>