{"id":367,"date":"2011-04-18T02:49:13","date_gmt":"2011-04-18T06:49:13","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2011\/04\/18\/exporting-geotiff-files-using-mapping-toolbox-in-r2011a\/"},"modified":"2019-10-29T16:34:12","modified_gmt":"2019-10-29T20:34:12","slug":"exporting-geotiff-files-using-mapping-toolbox-in-r2011a","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2011\/04\/18\/exporting-geotiff-files-using-mapping-toolbox-in-r2011a\/","title":{"rendered":"Exporting GeoTIFF files using Mapping Toolbox in R2011a"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>This is my first post using R2011a, which shipped last week. (MathWorks ships product-line updates <a href=\"https:\/\/www.mathworks.com\/products\/new_products\/release_model.html\">twice per year<\/a>, usually in March and September.) There's a lot of interesting material to write about for this new release.\r\n   <\/p>\r\n   <p>Because my blog readers have been asking for it for a long time, the first thing I want to mention is the new Mapping Toolbox\r\n      function <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/map\/ref\/geotiffwrite.html\"><tt>geotiffwrite<\/tt><\/a>.\r\n   <\/p>\r\n   <p>Here are a couple of examples from the documentation. The first example reads a layer from a NASA WMS (<a href=\"http:\/\/en.wikipedia.org\/wiki\/Web_Map_Service\">Web Map Service<\/a>) server and writes it out to a GeoTIFF file.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">nasa = wmsfind(<span style=\"color: #A020F0\">'nasa'<\/span>, <span style=\"color: #A020F0\">'SearchField'<\/span>, <span style=\"color: #A020F0\">'serverurl'<\/span>);\r\nlayerName = <span style=\"color: #A020F0\">'bluemarbleng'<\/span>;\r\nlayer = nasa.refine(layerName,  <span style=\"color: #A020F0\">'SearchField'<\/span>, <span style=\"color: #A020F0\">'layername'<\/span>, <span style=\"color: #0000FF\">...<\/span>\r\n  <span style=\"color: #A020F0\">'MatchType'<\/span>, <span style=\"color: #A020F0\">'exact'<\/span>);\r\n[A, R] = wmsread(layer(1));\r\nfilename = [layerName <span style=\"color: #A020F0\">'.tif'<\/span>];\r\ngeotiffwrite(filename, A, R)\r\nworldmap <span style=\"color: #A020F0\">world<\/span>\r\ngeoshow(filename)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/geotiffwrite_r2011a_01.jpg\"> <p>The next example reads an image from an existing GeoTIFF file, and then it writes out the first 1024 columns and last 1024\r\n      rows to a new GeoTIFF file.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[A, R] = geotiffread(<span style=\"color: #A020F0\">'boston.tif'<\/span>);\r\nrow = [size(A,1)-1024+1 size(A,1)];\r\ncol = [1 1024];\r\nsubImage = A(row(1):row(2), col(1):col(2), :);\r\nxi = col + [-.5 .5];\r\nyi = row + [-.5 .5];\r\n[xlim, ylim] = intrinsicToWorld(R, xi, yi);\r\nsubR = R;\r\nsubR.RasterSize = size(subImage);\r\nsubR.XLimWorld = sort(xlim);\r\nsubR.YLimWorld = sort(ylim);\r\ninfo = geotiffinfo(<span style=\"color: #A020F0\">'boston.tif'<\/span>);\r\nfilename = <span style=\"color: #A020F0\">'boston_subimage.tif'<\/span>;\r\ngeotiffwrite(filename, subImage, subR,  <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'GeoKeyDirectoryTag'<\/span>, info.GeoTIFFTags.GeoKeyDirectoryTag);\r\nmapshow(filename);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/geotiffwrite_r2011a_02.jpg\"> <p>If you'd like to know more about the capabilities of this new function, I encourage you to take a look at the extensive new\r\n      <a href=\"http:\/\/www.mathworks.com\/help\/map\/examples\/exporting-images-and-raster-grids-to-geotiff.html\">example<\/a> online.\r\n   <\/p>\r\n   <p>Stay tuned for more about R2011a...<\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_2b3f195d2abd4046994553e3891e58c9() {\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='2b3f195d2abd4046994553e3891e58c9 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 2b3f195d2abd4046994553e3891e58c9';\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 = 'Steve Eddins';\r\n        copyright = 'Copyright 2011 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_2b3f195d2abd4046994553e3891e58c9()\"><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.12<br><\/p>\r\n<\/div>\r\n<!--\r\n2b3f195d2abd4046994553e3891e58c9 ##### SOURCE BEGIN #####\r\n%%\r\n% This is my first post using R2011a, which shipped last week. (MathWorks\r\n% ships product-line updates\r\n% <https:\/\/www.mathworks.com\/products\/new_products\/release_model.html twice\r\n% per year>, usually in March and September.) There's a lot of interesting\r\n% material to write about for this new release.\r\n%\r\n% Because my blog readers have been asking for it for a long time, the\r\n% first thing I want to mention is the new Mapping Toolbox function\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2011a\/toolbox\/map\/ref\/geotiffwrite.html\r\n% |geotiffwrite|>.\r\n%\r\n% Here are a couple of examples from the documentation. The first example\r\n% reads a layer from a NASA WMS\r\n% (<http:\/\/en.wikipedia.org\/wiki\/Web_Map_Service Web Map Service>) server\r\n% and writes it out to a GeoTIFF file.\r\n\r\nnasa = wmsfind('nasa', 'SearchField', 'serverurl');\r\nlayerName = 'bluemarbleng';\r\nlayer = nasa.refine(layerName,  'SearchField', 'layername', ...\r\n  'MatchType', 'exact');\r\n[A, R] = wmsread(layer(1));\r\nfilename = [layerName '.tif'];\r\ngeotiffwrite(filename, A, R)\r\nworldmap world\r\ngeoshow(filename)\r\n\r\n%%\r\n% The next example reads an image from an existing GeoTIFF file, and then\r\n% it writes out the first 1024 columns and last 1024 rows to a new GeoTIFF\r\n% file.\r\n\r\n[A, R] = geotiffread('boston.tif');\r\nrow = [size(A,1)-1024+1 size(A,1)];\r\ncol = [1 1024];\r\nsubImage = A(row(1):row(2), col(1):col(2), :);\r\nxi = col + [-.5 .5];\r\nyi = row + [-.5 .5];\r\n[xlim, ylim] = intrinsicToWorld(R, xi, yi);\r\nsubR = R;\r\nsubR.RasterSize = size(subImage);\r\nsubR.XLimWorld = sort(xlim);\r\nsubR.YLimWorld = sort(ylim);\r\ninfo = geotiffinfo('boston.tif');\r\nfilename = 'boston_subimage.tif';\r\ngeotiffwrite(filename, subImage, subR,  ...\r\n    'GeoKeyDirectoryTag', info.GeoTIFFTags.GeoKeyDirectoryTag);\r\nmapshow(filename);\r\n\r\n%%\r\n% If you'd like to know more about the capabilities of this new function, I\r\n% encourage you to take a look at the extensive new\r\n% <https:\/\/www.mathworks.com\/products\/mapping\/demos.html?file=\/products\/demos\/shipping\/map\/mapexgeotiff.html\r\n% example> online.\r\n%\r\n% Stay tuned for more about R2011a...\r\n##### SOURCE END ##### 2b3f195d2abd4046994553e3891e58c9\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   This is my first post using R2011a, which shipped last week. (MathWorks ships product-line updates twice per year, usually in March and September.) There's a lot of interesting material to write... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2011\/04\/18\/exporting-geotiff-files-using-mapping-toolbox-in-r2011a\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[765,771,767,761,769,773,190,484,757,759,763],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/367"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=367"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":2375,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/367\/revisions\/2375"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}