Advertisements

GetMap from Geoserver using HTTP POST

Usually, I use CQL filter statements to dynamically filter features in a Geoserver WMS. These CQL filters can be added easily to the URL and Geoserver responds accordingly. There’s just one problem: There is a size limit for URLs and (very!) long filter statements won’t fit in. (And I’m not talking about the limit imposed by IE, but the more serious one in Apache.) This makes it necessary to switch from HTTP GET to POST. An easy way to send POST requests is using curl:

curl --data-binary @getMap.xml -H "Content-Type: text/xml" -o map.png "http://localhost:8080/geoserver/wms/GetMap"

I found that it’s important to use –data-binary to avoid that the text in getMap.xml is interpreted in any way. The “@” tells curl that a filename follows. Furthermore it’s necessary to specify the Content-Type. This results in the PNG map being stored in the current directory. My getMap.xml looks like follows:

<?xml version="1.0" encoding="UTF-8"?>
<ogc:GetMap
xmlns:ogc="http://www.opengis.net/ows"
xmlns:gml="http://www.opengis.net/gml"
version="1.1.1" service="WMS">

<StyledLayerDescriptor version="1.0.0">
<NamedLayer>
 <Name>myNs:roads</Name>
 <NamedStyle>
  <Name>simple_roads</Name>
 </NamedStyle>
</NamedLayer>
</StyledLayerDescriptor>

<BoundingBox srsName="http://www.opengis.net/gml/srs/epsg.xml#31287">
<gml:coord>
<gml:X>621005.1594799113</gml:X>
<gml:Y>471313.0306986364</gml:Y>
</gml:coord>
<gml:coord>
<gml:X>635174.7245025429</gml:X>
<gml:Y>484404.226939031</gml:Y>
</gml:coord>
</BoundingBox>

<Output>
 <Format>image/png</Format>
 <Size>
 <Width>600</Width>
 <Height>320</Height>
 </Size>
</Output>

<Exceptions>application/vnd.ogc.se+xml</Exceptions>

</ogc:GetMap>

It’s also pretty straightforward to add a filter to the NamedLayer element. Basically it can be copied from any SLD you have at hand.

Advertisements

Comments are closed.

%d bloggers like this: