You were already in contact with cached layers in Chapter 5, Advanced Configurations. You had a quick tour of GeoWebCache (http://geowebcache.org/), which is a Java open source project. Like any caching system, it acts as a proxy between the clients and the map server. There is a standalone version that works with any map server being compliant with the WMS standard.
Indeed, GeoWebCache uses the WMS syntax to retrieve tiles from the map server. It exposes the tiles in several ways, with the GeoServer integrated version you can use:
You used the integrated version of GeoWebCache and it is a good choice as there are many advantages in using the internal one. You can use a single interface to administer both GeoServer and GeoWebCache, and you don't have to use a custom URL or a special endpoint. Also, all the layers you publish on GeoServer are automatically configured as cached. You just have to set the caching properties on layers and layer groups.
Of course, you can use REST operations to control GeoWebCache settings and behavior.
$ curl -u admin:geoserver -XGET -H 'Accept: text/xml' http://localhost:8080/geoserver/gwc/rest/layers -o gwc_layers.xml
>>> myUrl = 'http://localhost:8080/geoserver/gwc/rest/layers' >>> headers = {'Accept':'text/xml'} >>> resp = requests.get(myUrl, auth=('admin','geoserver'), headers=headers) >>> file = open('gwc_layers_py.xml','w') >>> file.write(resp.text) >>> file.close()
<layers> <layer> <name>NaturalEarth:Coastline</name> <atom:link xmlns:atom="http://www.w3.org/2005/Atom" rel="alternate" href="http://localhost:8080/geoserver/gwc/rest/layers/NaturalEarth%3ACoastline.xml" type="text/xml"/> </layer> … </layers>
$ curl -u admin:geoserver -XGET -H 'Accept: text/xml' http://localhost:8080/geoserver/gwc/rest/layers/NaturalEarth:Coastline.xml -o gwc_coastline.xml
>>> myUrl = 'http://localhost:8080/geoserver/gwc/rest/layers/NaturalEarth:Coastline.xml' >>> headers = {'Accept':'text/xml'} >>> resp = requests.get(myUrl, auth=('admin','geoserver'), headers=headers) >>> file = open('gwc_coastline_py.xml','w') >>> file.write(resp.text) >>> file.close()
<?xml version="1.0" encoding="UTF-8"?> <GeoServerLayer> <id>LayerInfoImpl--5b67a624:145e68c7cdc:-7ffc</id> <enabled>true</enabled> <name>NaturalEarth:Coastline</name> <mimeFormats> <string>image/jpeg</string> <string>image/png</string> </mimeFormats> <gridSubsets> <gridSubset> <gridSetName>EPSG:900913</gridSetName> <extent> <coords> <double>-2.003750834E7</double> <double>-2.003750834E7</double> <double>2.003750834E7</double> <double>1.8440002895114224E7</double> </coords> </extent> </gridSubset> <gridSubset> <gridSetName>EPSG:4326</gridSetName> <extent> <coords> <double>-180.0</double> <double>-85.60903777459774</double> <double>180.0</double> <double>83.64513</double> </coords> </extent> </gridSubset> </gridSubsets> <metaWidthHeight> <int>4</int> <int>4</int> </metaWidthHeight> <expireCache>0</expireCache> <expireClients>0</expireClients> <parameterFilters> <styleParameterFilter> <key>STYLES</key> <defaultValue></defaultValue> </styleParameterFilter> </parameterFilters> <gutter>0</gutter> </GeoServerLayer>
<gridSubset> <gridSetName>EPSG:900913</gridSetName> <extent> <coords> <double>-2.003750834E7</double> <double>-2.003750834E7</double> <double>2.003750834E7</double> <double>1.8440002895114224E7</double> </coords> </extent> </gridSubset>
$ curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' -d @gwc_coastline.xml http://localhost:8080/geoserver/gwc/rest/layers/NaturalEarth:Coastline.xml
>>> myUrl = 'http://localhost:8080/geoserver/gwc/rest/layers/NaturalEarth:Coastline.xml' >>> file = open('gwc_coastline.xml','r') >>> payload = file.read() >>> headers = {'Content-type': 'text/xml','Accept': 'text/xml'} >>> resp = requests.post(myUrl, auth=('admin','geoserver'), data=payload, headers=headers) >>> resp.status_code 200
Configuring cached layers is really similar to performing operations on GeoServer layers. In the web interface, the configuration is indeed perfectly integrated and only on the REST interface you have a different entry point for your operations.
Please note that, by default, when you add a new layer on GeoServer, it is also automatically added to the GeoWebCache configuration.
In the first request of this recipe, you retrieved the layers' list and it should contain all layers unless you changed the GeoServer's default behavior.
However, any action you perform on a layer from the GWC REST interface does work on the uncached layer. Let's see, for instance, what happens when we delete the coastline layer using the GWC REST interface.
As usual, we firstly used cURL to do it:
$ curl -u admin:geoserver -XDELETE -H 'Content-type: text/xml' http://localhost:8080/geoserver/gwc/rest/layers/NaturalEarth:Coastline.xml
Then switched to Python code:
>>> myUrl = 'http://localhost:8080/geoserver/gwc/rest/layers/NaturalEarth:Coastline.xml' >>> headers = {'Content-type': 'text/xml'} >>> resp = requests.delete(myUrl, auth=('admin','geoserver'), headers=headers) >>> resp.status_code 200
If you now open the layer configuration and go to the Tile Caching tab, you can see it's empty.
18.118.208.97