Main Content

Visualize Path Traversed in NASA Maps

This example shows how to visualize latitude and longitude data stored in a ThingSpeak™ channel feed on a raster map provided by NASA. You can retrieve a raster map from a Web Map Service (WMS) and plot the path traversed by the Mary Maersk ship.

Read Data

ThingSpeak channel 73734 stores the location data of the Mary Maersk ship. Read data for the last 10 days using the thingSpeakRead function.

data = thingSpeakRead(73734,'DateRange',...
    [datetime('now')-caldays(10),datetime('now')],'outputFormat','table');

Process Raw Data

Process the raw latitude and longitude data before plotting it on the map. Store the latitude and longitude information in separate variables lat and lon. Use the geoquadline function to find the limits of the tightest possible geographic quadrangle that bounds a line connecting vertices with geographic coordinates specified by lat and lon. To make the map more easily readable, expand latitude and longitude limits by 10 units.

lon = data.Longitude;
lat = data.Latitude;
[latlim,lonlim] = geoquadline(lat,lon);
buf = 10;
[latlim,lonlim] = bufgeoquad(latlim,lonlim,buf,buf);

Retrieve Raster Map from NASA

Use the NASA Web Map Service to produce maps of spatially referenced raster data. The wmsfind function searches the entries in the serverurl of the WMS database for the string 'nasa'.

nasa = wmsfind('nasa','SearchField','serverurl');

Refine the search for the required raster map layer from NASA database using the refine function.

layer = refine(nasa,'bluemarbleng','SearchField','layername', ...
    'MatchType','exact');

Call wmsread function to read the raster map.

[A,R] = wmsread(layer(1),'Latlim',latlim,'Lonlim',lonlim);

Generate the Map

Use the raster map returned by the worldmap function to generate a plot of the path travelled by the Mary Maersk over the last 10 days.

geoshow(A,R);
geoshow(lat,lon);
xlabel('Longitude');
ylabel('Latitude');
axis tight;

See Also

Functions

External Websites