Main Content

Create WMS Maps when Internet Access is Intermittent

Reading data from WMS servers requires Internet access. However, once you read data from a server, you can save the data as a MAT or GeoTIFF file. Then, you can load the data without reading it again from the server. Saving WMS data to files is useful when you have intermittent Internet access, or when you want to share data with someone without Internet access.

This example shows how to create a WMS map for an area around Boston. The behavior of the example depends on whether you have Internet access, but the resulting map is the same.

Throughout the example, specify whether you have Internet access by using the logical scalar useInternet.

  • If useInternet is true, read data from the WMS server and update the saved files.

  • If useInternet is false, read data from the saved files.

useInternet = false;

If you use this example as a model to create your own WMS maps, you must create the saved files the first time you run the example by setting useInternet to true.

Search the WMS Database for basemap layers from the USGS National Map [1]. Refine the search to find a layer containing only orthoimagery. This step does not require Internet access, because the WMS Database is installed with Mapping Toolbox™.

bmapLayers = wmsfind("basemap.nationalmap","SearchFields","ServerURL");
usgsImageryLayer = refine(bmapLayers,"USGSImageryOnly","SearchFields","ServerURL");

Synchronize the layer with the server. The wmsupdate function adds an abstract, the attribute and style information, and the coordinate reference system information to the layer.

  • If useInternet is true, synchronize the layer with the server. Save the layer to a MAT file.

  • If useInternet is false, load the MAT file.

if useInternet
    usgsImageryLayer = wmsupdate(usgsImageryLayer);
    load usgsImageryLayer.mat

Specify the geographic limits and the image size. For this example, specify the limits for a region around Boston and a square image with a side length of 750 pixels.

latlim = [42.3453 42.3711];
lonlim = [-71.099 -71.0454];
s = 750;

Read the image from the server.

  • If useInternet is true, then read the map as an array and a GeographicCellsReference object. Save the array and reference object to a GeoTIFF file.

  • If useInternet is false, then read the GeoTIFF file.

if useInternet
    [A,R] = wmsread(usgsImageryLayer,"Latlim",latlim,"Lonlim",lonlim, ...
    [A,R] = readgeoraster("usgsImageryLayer.tif");

Create a map with appropriate latitude and longitude limits for the data. Display the map.


[1] Data available from U.S. Geological Survey, National Geospatial Program.

See Also



Related Topics