This was initially just intended for Jared at Pierce County, but I thought it would be useful to share it with the wider list. It is possible to use a WMS feed as a data feed to gdal using the gdal_wms driver. See
http://www.gdal.org/frmt_wms.html for additional details, but essentially you create a short xml file that defines where the WMS is located, extents etc. Then you can point any gdal utility, or application that uses gdal to read data sources, directly at the xml file.
How is this useful? Well, if you have a proprietary image service that can be accessed via WMS, this allows you to create a new Web service that uses the image service as a data source.
The syntax of this file is somewhat obtuse, even with examples, so here is an example.
- Standard WMS request to a local MapServer WMS:
http://localhost/cgi-bin/mapserv?map=/var/www/mapfiles/hydro/hydro.map&SERVICE=WMS
&version=%221.1.1%22
&REQUEST=GetMap
&LAYERS=imagery
&STYLES=
&BBOX=-125,39,-108,54
&WIDTH=600
&HEIGHT=600
&FORMAT=AGGA <=== should match OUTPUTFORMAT NAME in mapfile
&SRS=epsg:4326
- Here's what the GDAL_WMS XML file looks like:
<GDAL_WMS>
<Service name="WMS">
<Version>%221.1.1%22</Version>
<ServerUrl>
http://localhost/cgi-bin/mapserv?map=/var/www/mapfiles/hydro/hydro.map&SERVICE=WMS</ServerUrl>
<SRS>EPSG:4326</SRS>
<ImageFormat>AGGA</ImageFormat>
<Layers>imagery</Layers>
<Styles></Styles>
</Service>
<DataWindow>
<UpperLeftX>-125</UpperLeftX>
<UpperLeftY>54</UpperLeftY>
<LowerRightX>-108</LowerRightX>
<LowerRightY>39</LowerRightY>
<SizeX>600</SizeX>
<SizeY>600</SizeY>
</DataWindow>
<Projection>EPSG:4326</Projection>
<BandsCount>4</BandsCount>
<ClampRequests>false</ClampRequests>
</GDAL_WMS>
- Finally, here's using gdal to read it:
$ gdal_translate hydro_wms.xml hydro_wms.tif
Input file size is 600, 600
0...10...20...30...40...50...60...70...80...90...100 - done.
Roger
--