Some WMS server implementations, such as GeoServer, can render their maps in a
non-image format, such as KML. KML is an XML dialect used by Google Earth™ and Google Maps™ browsers. The WebMapServer.getMap
method and the
wmsread
function do not allow you to use the KML format because
they import only standard graphics image formats. Work around this limitation by using
the WMSMapRequest.RequestURL
property.
Search the WMS Database for layers on any GeoServer. Refine to include only the layers from the MassGIS server. Refine that list to return a FEMA Flood Zone layer.
geoserver = wmsfind('geoserver', 'SearchField', 'any'); massgis = geoserver.refine('massgis*wms', 'SearchField', ... 'serverurl'); massgis = wmsupdate(massgis); floodzone = massgis.refine('FEMA Flood Zones', 'SearchField', ... 'LayerTitle'); floodzone = floodzone(1);
Set geographic limits for a region around Boston, Massachusetts.
latlim = [ 42.305 42.417]; lonlim = [-71.131 -70.99];
Create a WMSMapRequest
object and set the geographic
limits.
request = WMSMapRequest(floodzone); request.Latlim = latlim; request.Lonlim = lonlim;
Obtain the graphics image from the server.
[A, R] = wmsread(request.RequestURL);
Display the image in a figure window.
figure usamap(A, R) geoshow(A, R)
Request an image format that opens in Google Earth.
request.ImageFormat = 'application/vnd.google-earth.kml+xml';
Use the urlwrite
function to write out
a KML file.
filename = 'floodzone.kml';
websave(filename,request.RequestURL);
Open the file with Google Earth to view. On Windows® platforms, display the KML file with:
winopen(filename)
For UNIX® and Mac users, display the KML file with:
cmd = 'googleearth ';
fullfilename = fullfile(pwd, filename);
system([cmd fullfilename])