{"id":231,"date":"2010-05-06T20:46:41","date_gmt":"2010-05-06T20:46:41","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/2010\/05\/06\/oilslick\/"},"modified":"2010-05-06T21:58:03","modified_gmt":"2010-05-06T21:58:03","slug":"oilslick","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2010\/05\/06\/oilslick\/","title":{"rendered":"Visualizing the Gulf of Mexico Oil Slick Using Web Map Service (WMS)"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>Today I'd like to introduce a guest blogger, Kelly Luetkemeyer, who is a Mapping Toolbox software developer at The MathWorks.\r\n         Kelly was the lead developer on the project to incorporate Web Map Service (WMS) into the Mapping Toolbox.\r\n      <\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Introduction<\/a><\/li>\r\n         <li><a href=\"#2\">Obtain Daily Planet Layer<\/a><\/li>\r\n         <li><a href=\"#3\">Update the Layer and Display the Abstract<\/a><\/li>\r\n         <li><a href=\"#4\">Define the Region-of-Interest<\/a><\/li>\r\n         <li><a href=\"#5\">Obtain the Image<\/a><\/li>\r\n         <li><a href=\"#6\">Display the Caption<\/a><\/li>\r\n         <li><a href=\"#7\">Display the Image<\/a><\/li>\r\n         <li><a href=\"#9\">View the Image at Full Resolution<\/a><\/li>\r\n         <li><a href=\"#10\">View the Image Using the WMS URL<\/a><\/li>\r\n         <li><a href=\"#11\">Obtain May 1, 2010 Image<\/a><\/li>\r\n         <li><a href=\"#12\">Enhance the Image<\/a><\/li>\r\n         <li><a href=\"#13\">Display Both Images<\/a><\/li>\r\n         <li><a href=\"#14\">Using Google&#8482; Earth with WMS<\/a><\/li>\r\n         <li><a href=\"#15\">Conclusion<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Introduction<a name=\"1\"><\/a><\/h3>\r\n   <p>Recently, the tragic accident in the Gulf of Mexico caused me to think if The MathWorks tools could be used to help visualize\r\n      the oil slick using imagery from Web Map Service (WMS) servers. I'll show you how to use WMS functionality in Mapping Toolbox\r\n      to obtain MODIS imagery of the region. The MODIS sensor is onboard NASA's Terra satellite. WMS is a standard developed by\r\n      the Open Geospatial Consortium (OGC) that allows clients to access web servers to obtain maps rendered as an image. We have\r\n      cataloged over 1000 WMS servers and their layers and stored that information into a database shipped with the Mapping Toolbox.\r\n      I will use that database to find a server that provides MODIS imagery.\r\n   <\/p>\r\n   <h3>Obtain Daily Planet Layer<a name=\"2\"><\/a><\/h3>\r\n   <p>The NASA WMS server located at the Jet Propulsion Laboratory (JPL) in Pasadena provides a continuously updating composite of\r\n      visual images from the MODIS sensor onboard the Terra satellite. I can obtain the stored layer's information with the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmsfind.html\"><tt>wmsfind<\/tt><\/a> function and narrow the search using the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmslayer.refine.html\"><tt>refine<\/tt><\/a> method of the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmslayerclass.html\"><tt>WMSLayer<\/tt><\/a> object.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">jpl = wmsfind(<span style=\"color: #A020F0\">'onearth.jpl'<\/span>, <span style=\"color: #A020F0\">'SearchField'<\/span>, <span style=\"color: #A020F0\">'serverurl'<\/span>);\r\ndaily_planet = jpl.refine(<span style=\"color: #A020F0\">'daily_planet'<\/span>);<\/pre><h3>Update the Layer and Display the Abstract<a name=\"3\"><\/a><\/h3>\r\n   <p>The information stored in the database is only a partial subset. I can update the layer with the latest information from the\r\n      server by using the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmsupdate.html\"><tt>wmsupdate<\/tt><\/a> function. Once the layer is updated, I can display the layer's abstract information.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">daily_planet = wmsupdate(daily_planet);\r\ndisp([<span style=\"color: #A020F0\">'&lt;html&gt;&lt;bf&gt;'<\/span> daily_planet.Abstract <span style=\"color: #A020F0\">'&lt;\/bf&gt;&lt;\/html&gt;'<\/span>])<\/pre><pre style=\"font-style:oblique\">A contiunously updating composite of visual images from TERRA MODIS scenes, see http:\/\/modis.gsfc.nasa.gov for details about MODIS.\r\n\tThis dataset is built local on the OnEarth server, it updates as soon as scenes are available, usually with a 6 to 24 hour delay from real time.\r\n        Images are produced from MODIS scenes using the HDFLook application.\r\n\tBase resolution is 8 arcseconds per pixel. The WMS \"time\" dimension can be used to retrieve past data, by using the YYYY-MM-DD notation.\r\n<\/pre><h3>Define the Region-of-Interest<a name=\"4\"><\/a><\/h3>\r\n   <p>I define the latitude and longitude bounds for a region surrounding the oil slick and request pixels at 8 arcseconds. The\r\n      <tt>time<\/tt> variable is used to request the image from April 29, 2010.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">latlim = [28 31];\r\nlonlim = [-90 -87];\r\ncellSize = 8\/3600;  <span style=\"color: #228B22\">% 8 arcseconds<\/span>\r\ntime  = <span style=\"color: #A020F0\">'2010-04-29'<\/span>;<\/pre><h3>Obtain the Image<a name=\"5\"><\/a><\/h3>\r\n   <p>The <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmsread.html\"><tt>wmsread<\/tt><\/a> function retrieves the image from the server. The output <tt>A<\/tt> is the image, <tt>R<\/tt> is the referencing matrix, and <tt>URL<\/tt> is a WMS URL that can be used in a browser to download the image. The image coordinates are in latitude and longitude. Please\r\n      note that sometimes this WMS server is busy and may issue an error message due to server overloading. If this happens, please\r\n      try again at a later time.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[A, R, URL] = wmsread(daily_planet, <span style=\"color: #A020F0\">'Time'<\/span>, time, <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'CellSize'<\/span>, cellSize, <span style=\"color: #A020F0\">'Latlim'<\/span>, latlim, <span style=\"color: #A020F0\">'Lonlim'<\/span>, lonlim);<\/pre><h3>Display the Caption<a name=\"6\"><\/a><\/h3>\r\n   <p>I initially found the MODIS image on a NASA website at <a href=\"http:\/\/www.nasa.gov\/topics\/earth\/features\/oil-creep.html\">http:\/\/www.nasa.gov\/topics\/earth\/features\/oil-creep.html<\/a>. I copied the caption from the website and placed it into a file.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">fid = fopen(<span style=\"color: #A020F0\">'caption.txt'<\/span>);\r\nc = fread(fid,<span style=\"color: #A020F0\">'char=&gt;char'<\/span>);\r\nfclose(fid);\r\ndisp([<span style=\"color: #A020F0\">'&lt;html&gt;&lt;bf&gt;'<\/span> c' <span style=\"color: #A020F0\">'&lt;\/bf&gt;&lt;\/html&gt;'<\/span>])<\/pre><pre style=\"font-style:oblique\"> On April 29, the MODIS image on the Terra satellite captured a wide-view natural-color image of the oil slick (outlined in white) just off the Louisiana coast. The oil slick appears as dull gray interlocking comma shapes, one opaque and the other nearly transparent. Sunglint -- the mirror-like reflection of the sun off the water -- enhances the oil slick&#8217;s visibility. The northwestern tip of the oil slick almost touches the Mississippi Delta. Credit: NASA\/Earth Observatory\/Jesse Allen, using data provided courtesy of the University of Wisconsin&#8217;s Space Science and Engineering Center MODIS Direct Broadcast system.\r\n<\/pre><h3>Display the Image<a name=\"7\"><\/a><\/h3>\r\n   <p>Since <tt>A<\/tt> is an RGB image, I can use the Image Processing Toolbox function <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/images\/imshow.html\"><tt>imshow<\/tt><\/a> to display it. The coordinates of the image are in longitude (rows) and latitude (columns).\r\n   <\/p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/231\/oilslick_01.png\"> <p>I can use the Mapping Toolbox function <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/geoshow.html\"><tt>geoshow<\/tt><\/a> to reproject the image into a Lambert projection. With the Mapping Toolbox functions, I can also overlay geographic data\r\n      onto the map, in this case, the boundaries of the states in the region-of-interest. The boundaries of the states are obtained\r\n      from the shapefile included with the Mapping Toolbox.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">S = shaperead(<span style=\"color: #A020F0\">'usastatehi.shp'<\/span>, <span style=\"color: #A020F0\">'UseGeoCoords'<\/span>, true);\r\nfigure(<span style=\"color: #A020F0\">'Renderer'<\/span>,<span style=\"color: #A020F0\">'zbuffer'<\/span>)\r\nusamap(A,R)\r\ngeoshow([S.Lat], [S.Lon]);\r\ngeoshow(A,R)\r\ntitle({<span style=\"color: #A020F0\">'MODIS Image of Gulf of Mexico Oil Slick'<\/span>, time, <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'Data Courtesy of NASA'<\/span>});<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/231\/oilslick_02.png\"> <h3>View the Image at Full Resolution<a name=\"9\"><\/a><\/h3>\r\n   <p>You can view the full image in your browser by clicking on the following link: <a href=\"https:\/\/blogs.mathworks.com\/images\/loren\/231\/gom.png\">https:\/\/blogs.mathworks.com\/images\/loren\/231\/gom.png<\/a><\/p>\r\n   <h3>View the Image Using the WMS URL<a name=\"10\"><\/a><\/h3>\r\n   <p>If you do not have the Mapping Toolbox, you can still use WMS if you know the WMS URL. The third output from <tt>wmsread<\/tt> provides this information. If you insert this URL into a browser, the browser will download the image from the WMS server.\r\n      You can also use the MATLAB function, <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/urlwrite.html\"><tt>urlwrite(URL, filename)<\/tt><\/a> to download the image.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">disp(URL(1:52)), disp(URL(53:95)), disp(URL(96:140))\r\ndisp(URL(141:170)), disp(URL(171:212)), <span style=\"color: #0000FF\">...<\/span>\r\ndisp(URL(213:262)), disp(URL(263:end))<\/pre><pre style=\"font-style:oblique\">http:\/\/onearth.jpl.nasa.gov\/wms.cgi?TIME=2010-04-29&amp;\r\nSERVICE=WMS&amp;LAYERS=daily_planet&amp;EXCEPTIONS=\r\napplication\/vnd.ogc.se_xml&amp;FORMAT=image\/jpeg&amp;\r\nTRANSPARENT=FALSE&amp;HEIGHT=1350&amp;\r\nBGCOLOR=0xFFFFFF&amp;REQUEST=GetMap&amp;WIDTH=1350\r\n&amp;BBOX=-90.0,28.0,-87.0,31.0&amp;STYLES=&amp;SRS=EPSG:4326&amp;\r\nVERSION=1.1.1\r\n<\/pre><h3>Obtain May 1, 2010 Image<a name=\"11\"><\/a><\/h3>\r\n   <p>The imagery from April 30 through May 6, excluding May 1, is either missing, because the area was not imaged at that time\r\n      by the sensor, or the region is cloudy. I'll download the May 1 imagery for comparison and see how the shape and size of the\r\n      oil slick has changed.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">time  = <span style=\"color: #A020F0\">'2010-05-01'<\/span>;\r\n[A2, R] = wmsread(daily_planet, <span style=\"color: #A020F0\">'Time'<\/span>, time, <span style=\"color: #A020F0\">'CellSize'<\/span>, cellSize, <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'Latlim'<\/span>, latlim, <span style=\"color: #A020F0\">'Lonlim'<\/span>, lonlim);\r\nfigure\r\nimshow(A2)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/231\/oilslick_03.png\"> <h3>Enhance the Image<a name=\"12\"><\/a><\/h3>\r\n   <p>The image can be enhanced by using the <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/images\/adapthisteq.html\"><tt>adapthisteq<\/tt><\/a> function from the Image Processing Toolbox.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">B = A2;\r\n<span style=\"color: #0000FF\">for<\/span> k=1:3\r\n B(:,:,k) = adapthisteq(A2(:,:,k));\r\n<span style=\"color: #0000FF\">end<\/span>\r\nfigure\r\nimshow(B)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/231\/oilslick_04.png\"> <h3>Display Both Images<a name=\"13\"><\/a><\/h3>\r\n   <p>For comparison, I'll place both the April 29 and the enhanced May 1 imagery in the same Figure window. You can see how the\r\n      shape and size of the oil slick has changed.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">figure(<span style=\"color: #A020F0\">'Renderer'<\/span>,<span style=\"color: #A020F0\">'zbuffer'<\/span>)\r\nsubplot(1,2,1)\r\nusamap(A,R)\r\ngeoshow(A,R)\r\ngeoshow([S.Lat], [S.Lon]);\r\ntitle({<span style=\"color: #A020F0\">'2010-04-29'<\/span>, <span style=\"color: #A020F0\">'Data Courtesy of NASA'<\/span>})\r\n\r\nsubplot(1,2,2)\r\nusamap(B,R)\r\ngeoshow(B,R)\r\ngeoshow([S.Lat], [S.Lon]);\r\ntitle({<span style=\"color: #A020F0\">'2010-05-01'<\/span>, <span style=\"color: #A020F0\">'Data Courtesy of NASA'<\/span>})<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/231\/oilslick_05.png\"> <h3>Using Google&#8482; Earth with WMS<a name=\"14\"><\/a><\/h3>\r\n   <p>Some WMS servers support non-image outputs. The <tt>daily_planet.Details.ImageFormats<\/tt> variable contains all the output types that the JPL server supports. One output type is <tt>'application\/vnd.google-earth.kml+xml'<\/tt>. I will modify the URL to specify KML as the output. You can use this file, <a href=\"https:\/\/blogs.mathworks.com\/images\/loren\/231\/gom.kml\"><tt>gom.kml<\/tt><\/a>, in Google&#8482; Earth to view the imagery.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">kmlURL = strrep(URL, <span style=\"color: #A020F0\">'image\/jpeg'<\/span>, <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'application\/vnd.google-earth.kml+xml'<\/span>);\r\nurlwrite(kmlURL, <span style=\"color: #A020F0\">'gom.kml'<\/span>);<\/pre><h3>Conclusion<a name=\"15\"><\/a><\/h3>\r\n   <p>I've shown how MATLAB, combined with functions from the Mapping Toolbox and Image Processing Toolbox, can be used to visualize\r\n      and enhance data for a current event. Do you have any ideas how you can use these tools to follow or analyze a current event?\r\n      Let me know <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=231#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_cc61f556c5bb412196aabf9259d3d4b3() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='cc61f556c5bb412196aabf9259d3d4b3 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' cc61f556c5bb412196aabf9259d3d4b3';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Loren Shure';\r\n        copyright = 'Copyright 2010 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_cc61f556c5bb412196aabf9259d3d4b3()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.10<br><\/p>\r\n<\/div>\r\n<!--\r\ncc61f556c5bb412196aabf9259d3d4b3 ##### SOURCE BEGIN #####\r\n%% Visualizing the Gulf of Mexico Oil Slick Using Web Map Service (WMS)\r\n% Today I'd like to introduce a guest blogger, Kelly Luetkemeyer, who is a\r\n% Mapping Toolbox software developer at The MathWorks. Kelly was the lead\r\n% developer on the project to incorporate Web Map Service (WMS) into the\r\n% Mapping Toolbox.\r\n\r\n\r\n\r\n%% Introduction\r\n% Recently, the tragic accident in the Gulf of Mexico caused me to think if\r\n% The MathWorks tools could be used to help visualize the oil slick using\r\n% imagery from Web Map Service (WMS) servers. I'll show you how to use WMS\r\n% functionality in Mapping Toolbox to obtain MODIS imagery of the region.\r\n% The MODIS sensor is onboard NASA's Terra satellite. WMS is a standard\r\n% developed by the Open Geospatial Consortium (OGC) that allows clients to\r\n% access web servers to obtain maps rendered as an image. We have cataloged\r\n% over 1000 WMS servers and their layers and stored that information into a\r\n% database shipped with the Mapping Toolbox. I will use that database to\r\n% find a server that provides MODIS imagery.\r\n\r\n%% Obtain Daily Planet Layer\r\n% The NASA WMS server located at the Jet Propulsion Laboratory (JPL) in\r\n% Pasadena provides a continuously updating composite of visual images from\r\n% the MODIS sensor onboard the Terra satellite. I can obtain the stored\r\n% layer's information with the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmsfind.html\r\n% |wmsfind|> function and narrow the search using the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmslayer.refine.html\r\n% |refine|> method of the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmslayerclass.html\r\n% |WMSLayer|> object.\r\njpl = wmsfind('onearth.jpl', 'SearchField', 'serverurl');\r\ndaily_planet = jpl.refine('daily_planet');\r\n\r\n%% Update the Layer and Display the Abstract\r\n% The information stored in the database is only a partial subset. I can\r\n% update the layer with the latest information from the server by using the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmsupdate.html\r\n% |wmsupdate|> function. Once the layer is updated, I can display the\r\n% layer's abstract information.\r\ndaily_planet = wmsupdate(daily_planet);\r\ndisp(['<html><bf>' daily_planet.Abstract '<\/bf><\/html>'])\r\n\r\n%% Define the Region-of-Interest\r\n% I define the latitude and longitude bounds for a region surrounding the\r\n% oil slick and request pixels at 8 arcseconds. The |time| variable is used\r\n% to request the image from April 29, 2010.\r\nlatlim = [28 31];\r\nlonlim = [-90 -87];\r\ncellSize = 8\/3600;  % 8 arcseconds\r\ntime  = '2010-04-29';\r\n\r\n%% Obtain the Image\r\n% The\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/wmsread.html\r\n% |wmsread|> function retrieves the image from the server. The output |A|\r\n% is the image, |R| is the referencing matrix, and |URL| is a WMS URL that\r\n% can be used in a browser to download the image. The image coordinates are\r\n% in latitude and longitude. Please note that sometimes this WMS server is\r\n% busy and may issue an error message due to server overloading. If this\r\n% happens, please try again at a later time.\r\n[A, R, URL] = wmsread(daily_planet, 'Time', time, ...\r\n    'CellSize', cellSize, 'Latlim', latlim, 'Lonlim', lonlim);\r\n\r\n%% Display the Caption\r\n% I initially found the MODIS image on a NASA website at\r\n% http:\/\/www.nasa.gov\/topics\/earth\/features\/oil-creep.html. I copied the\r\n% caption from the website and placed it into a file. \r\nfid = fopen('caption.txt');\r\nc = fread(fid,'char=>char');\r\nfclose(fid);\r\ndisp(['<html><bf>' c' '<\/bf><\/html>'])\r\n\r\n%% Display the Image\r\n% Since |A| is an RGB image, I can use the Image Processing Toolbox\r\n% function\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/images\/imshow.html\r\n% |imshow|> to display it. The coordinates of the image are in longitude\r\n% (rows) and latitude (columns).\r\nfigure\r\nimshow(A)\r\n\r\n%%\r\n% I can use the Mapping Toolbox function\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/map\/ref\/geoshow.html\r\n% |geoshow|> to reproject the image into a Lambert projection. With the\r\n% Mapping Toolbox functions, I can also overlay geographic data onto the\r\n% map, in this case, the boundaries of the states in the\r\n% region-of-interest. The boundaries of the states are obtained from the\r\n% shapefile included with the Mapping Toolbox.\r\nS = shaperead('usastatehi.shp', 'UseGeoCoords', true);\r\nfigure('Renderer','zbuffer')\r\nusamap(A,R)\r\ngeoshow([S.Lat], [S.Lon]);\r\ngeoshow(A,R)\r\ntitle({'MODIS Image of Gulf of Mexico Oil Slick', time, ...\r\n    'Data Courtesy of NASA'});\r\n\r\n%% View the Image at Full Resolution\r\n% You can view the full image in your browser by clicking on the following \r\n% link:\r\n% https:\/\/blogs.mathworks.com\/images\/loren\/231\/gom.png\r\n\r\n%% View the Image Using the WMS URL\r\n% If you do not have the Mapping Toolbox, you can still use WMS if you know\r\n% the WMS URL. The third output from |wmsread| provides this information.\r\n% If you insert this URL into a browser, the browser will download the\r\n% image from the WMS server. You can also use the MATLAB function,\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/urlwrite.html\r\n% |urlwrite(URL, filename)|> to download the image.\r\ndisp(URL(1:52)), disp(URL(53:95)), disp(URL(96:140))\r\ndisp(URL(141:170)), disp(URL(171:212)), ...\r\ndisp(URL(213:262)), disp(URL(263:end))\r\n\r\n%% Obtain May 1, 2010 Image\r\n% The imagery from April 30 through May 6, excluding May 1, is either\r\n% missing, because the area was not imaged at that time by the sensor, or\r\n% the region is cloudy. I'll download the May 1 imagery for comparison and\r\n% see how the shape and size of the oil slick has changed.\r\ntime  = '2010-05-01';\r\n[A2, R] = wmsread(daily_planet, 'Time', time, 'CellSize', cellSize, ...\r\n    'Latlim', latlim, 'Lonlim', lonlim);\r\nfigure\r\nimshow(A2)\r\n\r\n%% Enhance the Image\r\n% The image can be enhanced by using the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/toolbox\/images\/adapthisteq.html\r\n% |adapthisteq|> function from the Image Processing Toolbox.\r\nB = A2;\r\nfor k=1:3\r\n B(:,:,k) = adapthisteq(A2(:,:,k));\r\nend\r\nfigure\r\nimshow(B)\r\n\r\n%% Display Both Images\r\n% For comparison, I'll place both the April 29 and the enhanced May 1\r\n% imagery in the same Figure window. You can see how the shape and size of\r\n% the oil slick has changed.\r\nfigure('Renderer','zbuffer')\r\nsubplot(1,2,1)\r\nusamap(A,R)\r\ngeoshow(A,R)\r\ngeoshow([S.Lat], [S.Lon]);\r\ntitle({'2010-04-29', 'Data Courtesy of NASA'})\r\n\r\nsubplot(1,2,2)\r\nusamap(B,R)\r\ngeoshow(B,R)\r\ngeoshow([S.Lat], [S.Lon]);\r\ntitle({'2010-05-01', 'Data Courtesy of NASA'})\r\n\r\n%% Using Google(TM) Earth with WMS\r\n% Some WMS servers support non-image outputs. The\r\n% |daily_planet.Details.ImageFormats| variable contains all the output\r\n% types that the JPL server supports. One output type is\r\n% |'application\/vnd.google-earth.kml+xml'|. I will modify the URL to\r\n% specify KML as the output. You can use this file,\r\n% <https:\/\/blogs.mathworks.com\/images\/loren\/231\/gom.kml |gom.kml|>, in\r\n% Google(TM) Earth to view the imagery.\r\nkmlURL = strrep(URL, 'image\/jpeg', ...\r\n    'application\/vnd.google-earth.kml+xml');\r\nurlwrite(kmlURL, 'gom.kml');\r\n\r\n%% Conclusion\r\n% I've shown how MATLAB, combined with functions from the Mapping Toolbox\r\n% and Image Processing Toolbox, can be used to visualize and enhance data\r\n% for a current event. Do you have any ideas how you can use these tools to\r\n% follow or analyze a current event? Let me know \r\n% <https:\/\/blogs.mathworks.com\/loren\/?p=231#respond here>.\r\n\r\n##### SOURCE END ##### cc61f556c5bb412196aabf9259d3d4b3\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Today I'd like to introduce a guest blogger, Kelly Luetkemeyer, who is a Mapping Toolbox software developer at The MathWorks.\r\n         Kelly was the lead developer on the project to... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2010\/05\/06\/oilslick\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[27,41,40],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/231"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=231"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/231\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=231"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=231"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=231"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}