<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
h4
{mso-style-priority:9;
mso-style-link:"Heading 4 Char";
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;
font-weight:bold;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
code
{mso-style-priority:99;
font-family:"Courier New";}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
span.Heading4Char
{mso-style-name:"Heading 4 Char";
mso-style-priority:9;
mso-style-link:"Heading 4";
font-family:"Times New Roman",serif;
mso-fareast-language:EN-CA;
font-weight:bold;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";
mso-fareast-language:EN-CA;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle23
{mso-style-type:personal;
font-family:"Arial",sans-serif;
color:windowtext;}
span.EmailStyle26
{mso-style-type:personal-reply;
font-family:"Arial",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-CA" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Hi Folks,<o:p></o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">The standard image footprint mechanism such as that produced by
<b>gdaltindex</b> draws a box around the raster but that often includes large nodata areas which we don't care about. Generating polygons of only the data carrying area is something I’ve often wished for but not devoted the time and attention to solving. This
summer I'm very happy to have finally arrived at repeatable solution to the challenge.<o:p></o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">I’ve posted the below in answer to “<a href="https://gis.stackexchange.com/questions/26893/creating-shapefile-showing-footprints-of-rasters/">Creating
shapefile showing footprints of Rasters?</a>” on GIS Stack Exchange. After some more refinement I’ll also post some of the scripts which I built as part of a larger processing chain. (No promises on how long that might be. I have to work it around my main
duties.)<o:p></o:p></span></p>
<div style="border:none;border-bottom:solid windowtext 1.0pt;padding:0cm 0cm 1.0pt 0cm">
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
</div>
<p><strong>Ensure images have defined nodata.</strong> If source images do not, fix with something like one of the below, where 0 or 255 is the supposed-to-be nodata value:<o:p></o:p></p>
<pre><code>gdal_translate ... -a_nodata 0 ... outimage.vrt<o:p></o:p></code></pre>
<pre><code>gdal_edit -a_nodata 255 somefile.tif<o:p></o:p></code></pre>
<p><strong>Create small preview images for faster processing</strong> (useful when dealing with multi GB satellite images). Skip this step if you want to match value pixels' boundary precisely. I find using the target resolution
<code><span style="font-size:10.0pt">-tr</span></code> parameter or choosing an outsize percentage that approximates 2048 rows/columns works well. Three approaches shown, just use one.<o:p></o:p></p>
<pre><code>gdal_translate -tr 185 185 vendor_image.tif myimage.tif<o:p></o:p></code></pre>
<pre><code>gdal_translate -outsize 5% 5% vendor_image.tif myimage.tif<o:p></o:p></code></pre>
<pre><code>gdal_translate -outsize 2048 0 vendor_image.tif myimage.tif<o:p></o:p></code></pre>
<p><strong>Force pixel values to range between 1 and 255, then rescale again so that data = 100 and all else are nodata</strong>. Use
<a href="https://gis.stackexchange.com/questions/tagged/vrt" title="show questions tagged 'vrt'">
vrt</a> to not conserve storage and be much faster also. The reason for scaling twice is to work around the problem of not knowing what range the values might be when we start. There's no meaning to 100 other than by default it draws as a midtone grey, in contrast
to the traditional 1 which is visually indistinguishable from black.<o:p></o:p></p>
<pre><code>gdal_translate -scale -ot byte myimage.tif myimage_8bit.vrt<o:p></o:p></code></pre>
<pre><code>gdal_translate -scale 1 255 100 100 myimage_8bit.vrt myimage_data_mask.vrt<o:p></o:p></code></pre>
<p><strong>Create a polygon of the data-only area image mask</strong> for all connected regions of pixels in the raster sharing a common pixel value, using 8-way connectedness.:<o:p></o:p></p>
<pre><code>gdal_polygonize -8 myimage_data_mask.vrt .\footprints\myimage_data.shp<o:p></o:p></code></pre>
<pre><code><o:p> </o:p></code></pre>
<p>Enjoy! Pink is the normal extents area as created by <code><span style="font-size:10.0pt">gdaltindex</span></code> and similar approaches. Black outline is our new data-only polygon.<o:p></o:p></p>
<p style="margin-left:36.0pt"><span style="color:#1F497D">Image: <a href="https://i.stack.imgur.com/Qv1im.png">
https://i.stack.imgur.com/Qv1im.png</a> </span><a href="https://i.stack.imgur.com/Qv1im.png"></a><o:p></o:p></p>
<h4>Windows CMD shell bulk processing example<o:p></o:p></h4>
<pre><code>cd .\previews<o:p></o:p></code></pre>
<pre><code>md .\byte<o:p></o:p></code></pre>
<pre><code>md .\data-only<o:p></o:p></code></pre>
<pre><code>for %a in (*.tif) do gdal_translate -scale -ot byte %a .\byte\%~na.vrt<o:p></o:p></code></pre>
<pre><code>for %a in (byte\*.vrt) do gdal_translate -scale 1 255 100 100 %a .\data-only\%~na.vrt<o:p></o:p></code></pre>
<pre><code>for %a in (data-only\*.vrt) do call gdal_polygonize -8 %a %~na.shp<o:p></o:p></code></pre>
<p>Assemble the footprints you've created by the hundred into a single overview index.
<em>{AUTO_NAME}</em> populates a field with the name of the source file for that polygon. See
<a href="https://gdal.org/programs/ogrmerge.html"><strong><span style="color:blue">ogrmerge</span></strong> doc page</a> for other options.<o:p></o:p></p>
<pre><code>ogrmerge -single ^<o:p></o:p></code></pre>
<pre><code> -src_layer_field_name Image_Name ^<o:p></o:p></code></pre>
<pre><code> -src_layer_field_content {AUTO_NAME} ^<o:p></o:p></code></pre>
<pre><code> -o ..\index_footprint_data.shp ^<o:p></o:p></code></pre>
<pre><code> .\data-only\*.shp<o:p></o:p></code></pre>
<p style="margin-left:36.0pt"><a href="https://i.stack.imgur.com/DbaQU.png"><span style="color:#1F497D;text-decoration:none">Image:</span></a><span style="color:#1F497D">
<a href="https://i.stack.imgur.com/DbaQU.png">https://i.stack.imgur.com/DbaQU.png</a></span><o:p></o:p></p>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="100%" align="center">
</div>
<p>Thank you <a href="https://gis.stackexchange.com/a/139045/108">https://gis.stackexchange.com/a/139045/108</a> for rescaling data-only to single pixel value tip. There are other ways of reaching the same end using
<code><span style="font-size:10.0pt">gdal_calc</span></code> but I find this scale approach is easier to wrap my head around.<o:p></o:p></p>
<div style="border:none;border-bottom:solid windowtext 1.0pt;padding:0cm 0cm 1.0pt 0cm">
<p>I think I learned about rescaling without knowing the input values ahead of time from Robert Simmon but have lost the reference. You can't go wrong by consulting his
<a href="https://medium.com/planet-stories/a-gentle-introduction-to-gdal-part-4-working-with-satellite-data-d3835b5e2971">
General Introduction to GDAL</a> series however.<o:p></o:p></p>
<p><o:p> </o:p></p>
</div>
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Hopefully this will be useful for others also,<o:p></o:p></span></p>
<p style="margin:0cm;margin-bottom:.0001pt"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">cheers.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal" style="margin-top:4.0pt;line-height:115%;text-autospace:none;vertical-align:middle">
<b><span lang="EN-US" style="font-size:9.0pt;line-height:115%;font-family:"Arial",sans-serif;mso-fareast-language:EN-CA">Matt Wilkie</span></b><span lang="EN-US" style="font-size:9.0pt;line-height:115%;font-family:"Arial",sans-serif;mso-fareast-language:EN-CA"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;mso-fareast-language:EN-CA">Geomatics Developer & Administrator<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;mso-fareast-language:EN-CA">Environment
<span style="color:#2E74B5">|</span> Technology, Innovation and Mapping<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;mso-fareast-language:EN-CA">T 867-667-8133
<span style="color:#2E74B5">|</span> </span><u><span style="font-size:9.0pt;font-family:"Arial",sans-serif;mso-fareast-language:EN-CA"><a href="http://yukon.ca/"><span lang="EN-US" style="color:windowtext">Yukon.ca</span></a><o:p></o:p></span></u></p>
<p class="MsoNormal"><i><span style="font-size:9.0pt;font-family:"Arial",sans-serif;mso-fareast-language:EN-CA">Hours: 08:30-16:30, Mon-Wed: Office, Thu: Remote, Fri: Away.<o:p></o:p></span></i></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>