Table of contents
If you save the WMS layer you created via the GUI, you can save that to a separate *.kml
file. IF you save as a *.kmz
, that is simply a zipped *.kml
. You can now edit the *.kml
in an ASCII edit such as notepad, wordpad or textpad, to see what the syntax is for showing a WMS layer in Google Earth.
Once saved, you will see that kml uses a so-called GroundOverlay
element.
<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <GroundOverlay> <name>Untitled Image Overlay</name> <Icon> <href>http://data.ncof.co.uk/thredds/wms/METOFFICE-NWS-AF-BIO-DAILY?VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4326&WIDTH=512&HEIGHT=512&LAYERS=N3n&STYLES=boxfill/rainbow&TRANSPARENT=TRUE&FORMAT=image/gif&</href> <viewRefreshMode>onStop</viewRefreshMode> <viewBoundScale>0.75</viewBoundScale> </Icon> <LatLonBox> <north>65</north> <south>40</south> <east>15</east> <west>-20</west> </LatLonBox> </GroundOverlay> </kml> |
The GroundOverlay is an element that positions any image on the globe by describing its bounding boxes. For a WMS the LatLonBox
are in fact optional, as Google Earth will request an image for any locations, regardless of the valid range for the WMS. You can include a LatLonBox
to prevent fruitless events outside the valid extent of the data, it will not be used to span the data on the globe. For WMS, the href
image is actually generated on the fly, using a a very long url. We explain the construction of this url on a separate wms primer.
&
symbols in the url with the html encoding for that "& a m p ;
" (without spaces).href
element contains a full valid WMS url EXCEPT the bbox
keyword. Google Earth will automatically use the bbox
keyword depending on where you zoomed. This makes sure that you always see the WMS when you are in the correct region, and that the resolution will be better when you zoom in. Leaving out the bbox
will result in an INVALID url if you open it on a browser: http://data.ncof.co.uk/thredds/wms/METOFFICE-NWS-AF-BIO-DAILY?VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4326&WIDTH=512&HEIGHT=512&LAYERS=N3n&STYLES=boxfill/rainbow&TRANSPARENT=TRUE&FORMAT=image/gif&
LatLonBox
is only optional to bring the GroundOverlay into your view and prevent fruitless WMS calls or fruitless waiting.GroundOverlay
subelement <viewRefreshMode>
is essential for this, only when you stop zooming, Google Earth will update the image.With the previous manual editing of kml files, you can add any WMS to your Google Earth. However, often you will not see nice WMS images, but a 'request in progress' arrow.
You can prevent this by switching of the automatic updating of WMS, and simply download the WMS image and refer to a local file, or use WMS as a means to refer to images as if they were static images on the web. You can do this by making sure
href
element DOES contain a full valid WMS url INCLUDING the bbox=-20,40,15,65
keyword. Google Earth will now consider the WMS url as a regular weblink, and not update at all. It will wrap it into the globe using the corners specified in the LatLonBox
element. http://data.ncof.co.uk/thredds/wms/METOFFICE-NWS-AF-BIO-DAILY?VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4326&WIDTH=512&HEIGHT=512&LAYERS=N3n&STYLES=boxfill/rainbow&TRANSPARENT=TRUE&FORMAT=image/gif&bbox=-10.,50.,10,60.
.<LatLonBox><north>65</north><south>40</south><east>15</east><west>-20</west></LatLonBox>
is now ESSENTIAL to span the image correctly onto the globe, and it needs to be EXACTLY identical to the bbox=-20,40,15,65
in the href
element.GroundOverlay
subelement <viewRefreshMode>
need to be removed.<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:kml="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom"> <GroundOverlay> <name>Untitled Image Overlay</name> <Icon> <href>http://data.ncof.co.uk/thredds/wms/METOFFICE-NWS-AF-BIO-DAILY?VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG:4326&WIDTH=512&HEIGHT=512&LAYERS=N3n&STYLES=boxfill/rainbow&TRANSPARENT=TRUE&FORMAT=image/gif&bbox=-20,40,15,65&time=2011-04-07T12:00:00.000Z</href> </Icon> <LatLonBox> <north>65</north> <south>40</south> <east>15</east> <west>-20</west> </LatLonBox> </GroundOverlay> </kml> |
Note that the WMS image still needs to be request once, so initially you still see the 'request in progress' arrow. If you wan to reuse the image, you can also request the image yourselves in a web browser, save it, and point to it locally with the href
element.
In a WMS url there are some optional argument, like time
and elevation
. GIS clients like Google Earth by default use the default value for these dimensions. For temporal data, usually the last time step is shown only, for instance in this WMS of the Dutch KNMI rain radar. When you edit a kml, you can insert on-default values for these parameters. In addition, you can specify better values for non-standard extensions like COLORSCALERANGE
.