GeoWebCache 关于GeoWebCache的部署说明

来源:互联网 发布:小莫零食淘宝店 编辑:程序博客网 时间:2024/04/28 06:40

转:http://blog.csdn.net/wd4java/article/details/44677781

原文连接:http://www.cnblogs.com/znlgis/p/3487663.html

总结了网络的各种资料终于成功部署,并加载arcgis wms服务(当然tilecache部署失败了,有时间再试试)

主要修改2个地方(包用的1.5的,目前最新的1.7的部署失败)

1.将geowebcache-1.5.3-war 解压的tomcat webapp下

修改web.xml内容

[html] view plain copy
  1. <context-param>    
  2.   <param-name>GEOWEBCACHE_CACHE_DIR</param-name>    
  3.   <param-value>D:/geowebcache/data</param-value>    
  4. </context-param>   
在<web-app>根目录下添加上面代码

param-value:指定图片缓存位置

2.启动tomcat

在D:/geowebcache/data下会生成如下文件



2.修改geowebcache.xml添加自己的图层服务,进行切图

修改后的内容

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <gwcConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.   xmlns="http://geowebcache.org/schema/1.5.3"  
  4.   xsi:schemaLocation="http://geowebcache.org/schema/1.5.3 http://geowebcache.org/schema/1.5.3/geowebcache.xsd">  
  5.   <version>1.5.3</version>  
  6.   <backendTimeout>120</backendTimeout>  
  7.   <serviceInformation>  
  8.     <title>GeoWebCache</title>  
  9.     <description>GeoWebCache is an advanced tile cache for WMS servers.It supports a large variety of protocols and  
  10.       formats, including WMS-C, WMTS, KML, Google Maps and Virtual Earth.</description>  
  11.     <keywords>  
  12.       <string>WFS</string>  
  13.       <string>WMS</string>  
  14.       <string>WMTS</string>  
  15.       <string>GEOWEBCACHE</string>  
  16.     </keywords>  
  17.     <serviceProvider>  
  18.       <providerName>John Smith inc.</providerName>  
  19.       <providerSite>http://www.example.com/</providerSite>  
  20.       <serviceContact>  
  21.         <individualName>John Smith</individualName>  
  22.         <positionName>Geospatial Expert</positionName>  
  23.         <addressType>Work</addressType>  
  24.         <addressStreet>1 Bumpy St.</addressStreet>  
  25.         <addressCity>Hobart</addressCity>  
  26.         <addressAdministrativeArea>TAS</addressAdministrativeArea>  
  27.         <addressPostalCode>7005</addressPostalCode>  
  28.         <addressCountry>Australia</addressCountry>  
  29.         <phoneNumber>+61 3 0000 0000</phoneNumber>  
  30.         <faxNumber>+61 3 0000 0001</faxNumber>  
  31.         <addressEmail>john.smith@example.com</addressEmail>  
  32.       </serviceContact>  
  33.     </serviceProvider>  
  34.     <fees>NONE</fees>  
  35.     <accessConstraints>NONE</accessConstraints>  
  36.   </serviceInformation>  
  37.   
  38.   <gridSets>  
  39.     <!-- Grid Set Example, by default EPSG:900913 and EPSG:4326 are defined -->  
  40.     <gridSet>  
  41.       <!-- This does not have to be an EPSG code, you can also have multiple gridSet elements per SRS -->  
  42.       <name>EPSG:4326</name>  
  43.       <srs>  
  44.         <number>4326</number>  
  45.       </srs>  
  46.       <extent>  
  47.         <coords>  
  48.           <double>121.067963</double>  
  49.           <double>36.699255</double>  
  50.           <double>122.939758</double>  
  51.           <double>37.647947</double>  
  52.         </coords>  
  53.       </extent>  
  54.       <scaleDenominators>  
  55.         <double>18489297.737236</double>  
  56.         <double>9244648.868618</double>  
  57.         <double>4622324.434309</double>  
  58.         <double>2311162.217155</double>  
  59.         <double>1155581.108577</double>  
  60.       </scaleDenominators>  
  61.       <tileHeight>256</tileHeight>  
  62.       <tileWidth>256</tileWidth>  
  63.     </gridSet>  
  64.   </gridSets>  
  65.   
  66.   <layers>  
  67.     <wmsLayer>  
  68.       <name>GaoDeMapTile</name>  
  69.       <mimeFormats>  
  70.         <string>image/png</string>  
  71.       </mimeFormats>  
  72.       <gridSubsets>  
  73.         <gridSubset>  
  74.           <gridSetName>EPSG:4326</gridSetName>  
  75.         </gridSubset>  
  76.       </gridSubsets>  
  77.       <wmsUrl>  
  78.         <string>http://172.31.170.98:6080/arcgis/services/GaoDeMapTile/MapServer/WMSServer?</string>  
  79.       </wmsUrl>  
  80.       <wmsLayers>0</wmsLayers>   
  81.     </wmsLayer>  
  82.   </layers>  
  83.     
  84. </gwcConfiguration>  

当然具体的参数需要自己去查找与自己图层一致的参数(可以参考部署说明(2))

3.我是直接预览的


4.可以查看1中生成的文件夹内容,就是缓存的切片

5.附上openlayer调用显示代码

[html] view plain copy
  1. <pre name="code" class="html"><html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head>  
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  4. <title>openlayer EPSG:4326 image/png</title>  
  5. <link rel="stylesheet" type="text/css" href="openlayers/theme/default/style.css"/>  
  6. <style type="text/css">  
  7.     body { font-family: sans-serif; font-weight: bold; font-size: .8em; }  
  8.     body { border: 0px; margin: 0px; padding: 0px; }  
  9.     #map { width: 100%; height: 100%; border: 0px; padding: 0px; }  
  10. </style>  
  11. <script type="text/javascript" src="openlayers/OpenLayers.js"></script>    
  12. <script type="text/javascript">                 
  13.     var map, demolayer;                                                                          
  14.     OpenLayers.DOTS_PER_INCH = 90.71428571428572;  
  15.     OpenLayers.Util.onImageLoadErrorColor = 'transparent';  
  16.     function init(){  
  17.         var mapOptions = {   
  18.             resolutions: [0.703125, 0.3515625, 0.17578125, 0.087890625, 0.0439453125, 0.02197265625,   
  19.                 0.010986328125, 0.0054931640625, 0.00274658203125, 0.001373291015625, 6.866455078125E-4,   
  20.                 3.4332275390625E-4, 1.71661376953125E-4, 8.58306884765625E-5, 4.291534423828125E-5,   
  21.                 2.1457672119140625E-5, 1.0728836059570312E-5, 5.364418029785156E-6, 2.682209014892578E-6,   
  22.                 1.341104507446289E-6, 6.705522537231445E-7, 3.3527612686157227E-7  
  23.             ],  
  24.             projection: new OpenLayers.Projection('EPSG:4326'),  
  25.             maxExtent: new OpenLayers.Bounds(-180.0,-90.0,180.0,90.0),  
  26.             units: "degrees",  
  27.             controls: []  
  28.         };  
  29.         map = new OpenLayers.Map('map', mapOptions );  
  30.           
  31.         map.addControl(new OpenLayers.Control.PanZoomBar({  
  32.                 position: new OpenLayers.Pixel(0, 5)  
  33.         }));  
  34.         map.addControl(new OpenLayers.Control.Navigation());  
  35.         map.addControl(new OpenLayers.Control.Scale($('scale')));  
  36.         map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));  
  37.           
  38.         demolayer = new OpenLayers.Layer.WMS(  
  39.             "GaoDeMapTile","http://172.31.170.98:6080/arcgis/services/GaoDeMapTile/MapServer/WMSServer?",  
  40.             {layers: '0', format: 'image/png' },  
  41.             { tileSize: new OpenLayers.Size(256,256)}  
  42.         );  
  43.         map.addLayer(demolayer);  
  44.         map.zoomToExtent(new OpenLayers.Bounds(121.067963, 36.699255,   
  45.             122.939758, 37.647947)  
  46.         );  
  47.     }  
  48. </script>  
  49. </head>  
  50. <body onLoad="init()">  
  51.     <div id="map"></div>  
  52. </body>  
  53. </html>  


1、切片的缓存问题

当地图服务(这里默认指WMS)的数据更新时,GeoWebCache的切片如何随之更新,客户浏览器上的缓存如何更新成了一个绕不开的问题。GeoWebCache提供了相应的配置项供我们自定义服务端和客户端的切片保存时间。

[html] view plain copy
  1. <!-- 可选:一个瓦片在服务器保持可用的秒数。后续请求将取回的结果是一个新的瓦片。默认是永久cache。参数列表应该常常以minZoom="0"开头,然后单调递增。特殊值:-1表示从不缓存,-2表示从不过期 -->    
  2.       <expireCacheList>    
  3.         <expirationRule minZoom="0"  expiration="14400" />    
  4.         <expirationRule minZoom="10" expiration="7200" />    
  5.       </expireCacheList>    
  6.       <!-- 可选:客户端从GWC收到瓦片之后,需要缓存的时间(秒为单位)。默认值使用和WMS服务器提供的过期时间相同。如果值不可用,缓存2小时,参见expireCacheList -->    
  7.       <expireClientsList>    
  8.         <expirationRule minZoom="0" expiration="7200" />    
  9.         <expirationRule minZoom="10" expiration="600" />    
  10.       </expireClientsList>  
如果你不设置该配置项,服务端和客户端的默认缓存时间都是两个小时,你也可以根据需要单独设置任何一个缩放级别的缓存时间。

2、图片格式和图片压缩的问题

切片的一般是在浏览器上使用的,切片传到浏览器给客户展现出来需要考虑到使用的流量和需要的时间的问题,最好可以做到加载时间短,占用浏览少,试了很多办法,最有效的就是压缩切片。 GeoWebCache提供了相应的压缩切片的配置,我试了一下感觉效果最明显的还是对JPEG格式图片的压缩,大家可以试试,如果有问题可以跟我说。

[html] view plain copy
  1. <!-- 可选:格式修改器,这些也可以通过对各个图层单独定义 -->    
  2.   <formatModifiers>    
  3.     <!-- 能够有一个和多个这样的元素 -->    
  4.     <formatModifier>    
  5.       <!-- 必要:应用于JPEG -->    
  6.       <responseFormat>image/jpeg</responseFormat>    
  7.       <!-- 可选:从后端的PNG请求时,阻止双重压缩 -->    
  8.       <requestFormat>image/png</requestFormat>    
  9.       <!-- 可选:透明度支持 -->    
  10.       <transparent>false</transparent>    
  11.       <!-- 可选:背景颜色 -->    
  12.       <bgColor>0xFFFFFF</bgColor>    
  13.       <!-- 可选WMS服务器使用的调色板 -->    
  14.       <palette>somepalette</palette>    
  15.       <!-- 可选:调节压缩等级,1.0是最佳质量 -->    
  16.       <compressionQuality>0.9</compressionQuality>    
  17.     </formatModifier>    
  18.   </formatModifiers>  
这里需要注意的是,最好把bgColor调为白色,这样图片大小会小一些,而且效果也会好一些,而compressionQuality最好不要小于0.75(官网上说0.75以上图片质量基本无损),当然还是要根据使用中的具体情况来调整,我就是用的0.5,完全满足要求。

3、使用ArcGIS Server发布地图服务的问题

ArcGIS Server很强大,美中不足的是它提供的JavaScript api过于庞大,不适合手机上使用,于是就会想到用openlayers,但openlayers调用ArcGIS Server的切片服务的显示效果又很差(尤其是自定义坐标系),于是,我才会想到用GeoWebCache,还好GeoWebCache支持ArcGIS Server的WMS服务。

[html] view plain copy
  1. <wmsLayer>   
  2. <name>NEW-layer2</name>   
  3.      <mimeFormats>   
  4.      <string>image/jpeg</string>   
  5.      </mimeFormats>   
  6. <!-- Grid Subset Example -->   
  7. <gridSubsets>   
  8. <gridSubset>   
  9. <gridSetName>EPSG:2383</gridSetName>   
  10. <extent>   
  11. <coords>   
  12. <double>-26</double>   
  13.      <double>-402</double>   
  14.      <double>525</double>   
  15.      <double>20</double>   
  16. </coords>   
  17. </extent>   
  18. </gridSubset>   
  19. </gridSubsets>   
  20. <wmsUrl>   
  21. <string>http://test/arcgis/services/NEW-layer2/layer2/MapServer/WMSServer?</string>   
  22. </wmsUrl>   
  23. <wmsLayers>0</wmsLayers>   
  24. <transparent>false</transparent>   
  25. <bgColor>0xFFFFFF</bgColor>   
  26. </wmsLayer>  

这里需要注意的是引用ArcGIS Sever发布的WMS服务的时候别忘了最后的那个"?",不加可能会有问题。还有就是要根据具体的需求配置好wmsLayers项,这个配置项是指你要在切片中显示的图层,多配或者少配显示效果都不对。再就是要配置正确你的坐标系和坐标范围,这些信息都可以从ArcGIS Server找到,如果这个设置有问题很可能会出现坐标计算不正确或者图像超出范围等问题。


0 0
原创粉丝点击