Add Custom Basemaps from WMS Data
This topic shows how to add custom basemaps from data stored in WMS servers by using the addCustomBasemap
function. You can use custom basemaps with map display objects that have a Basemap
property, including geographic axes objects and geographic globe objects. When you add a custom basemap by using the addCustomBasemap
function, the basemap remains available for use in future MATLAB® sessions.
Add Basemap from WMS Layer
Get a list of layers from the GEBCO WMS server. Refine the list to include the "GEBCO_LATEST_2_sub_ice_topo"
layer, which contains color-shaded elevation and under-ice topography for the globe.
info = wmsinfo("https://wms.gebco.net/mapserv?"); layers = info.Layer; iceTopoLayer = refine(layers,"GEBCO_LATEST_2_sub_ice_topo")
iceTopoLayer = WMSLayer Properties: Index: 1 ServerTitle: 'This is a WMS for the GEBCO global bathymetric grid' ServerURL: 'https://wms.gebco.net/mapserv?' LayerTitle: 'GEBCO Grid colour-shaded for elevation including under ice topography' LayerName: 'GEBCO_LATEST_2_sub_ice_topo' Latlim: [-90.0000 90.0000] Lonlim: [-180.0000 360.0000] Abstract: 'GEBCO_LATEST_2_sub_ice_topo' CoordRefSysCodes: {'EPSG:4326'} Details: [1x1 struct] Methods
Valid WMS layers have longitude limits in the range [–180, 180] or [0, 360]. Specify valid longitude limits for the layer by changing the Lonlim
property.
iceTopoLayer.Lonlim = [-180 180];
Add a custom basemap from the WMS layer by using the addCustomBasemap
function. Specify an attribution by using the Attribution
name-value argument and the title of the layer.
attribution = iceTopoLayer.LayerTitle;
addCustomBasemap("gebcoIceTopo",iceTopoLayer,Attribution=attribution)
Create a geographic globe that uses the custom basemap. Position the camera above Europe.
uif = uifigure;
g = geoglobe(uif,Basemap="gebcoIceTopo");
campos(g,33,8,4e6)
campitch(g,-70)
Add Basemap from WMS GetMap Request URL
Search the WMS Database for layers from the NASA Earth Observations (NEO) WMS server. Refine the list to include the "MOD_LSTD_M"
layer, which contains daytime land surface temperatures. Synchronize the layer with the WMS server.
layers = wmsfind("neo.gsfc.nasa.gov",SearchFields="ServerURL"); tempLayers = refine(layers,"land surface temperature"); tempDayLayer = refine(tempLayers,"MOD_LSTD_M"); tempDayLayer = wmsupdate(tempDayLayer);
Create a WMS map request from the layer. Request data from June 1, 2024 by updating the Time
property of the map request.
mapRequest = WMSMapRequest(tempDayLayer);
mapRequest.Time = "2024-06-01";
Get the WMS GetMap request URL from the map request. Then, add a custom basemap from the URL by using the addCustomBasemap
function. Specify an attribution by using the Attribution
name-value argument and the title of the server.
url2024 = mapRequest.RequestURL;
attribution = tempDayLayer.ServerTitle;
addCustomBasemap("landTempJune2024",url2024,Attribution=attribution)
Display the basemap in a geographic axes object by using the geobasemap
function. Add a title and subtitle using the title of the layer and the time stored in the map request, respectively.
figure
geobasemap landTempJune2024
t = tempDayLayer.LayerTitle;
title(t)
subtitle(mapRequest.Time)
Add a second basemap using temperatures from January 1, 2001. Update the Time
property of the map request, get the updated WMS GetMap request URL, and add the basemap using the updated URL.
mapRequest.Time = "2001-01-01"; url2000 = mapRequest.RequestURL; addCustomBasemap("temperatureJan2001",url2000,Attribution=attribution)
Display the second basemap in a new geographic axes object.
figure
geobasemap temperatureJan2001
title(t)
subtitle(mapRequest.Time)