<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="color: rgb(0, 0, 0); font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; background: var(--white);">Hello all,</span><br>
</div>
<div dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I have been using <code>gdalwarp</code>​ to georeference sensor data with geolocation arrays.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
I have observed that GDAL assigns values to pixels that clearly fall outside the geolocation footprint, producing some funny artifacts at the image edges. For example,
<a href="https://pasteboard.co/K69DUni.png" title="https://pasteboard.co/K69DUni.png">
see the image here</a>.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
(Sensor data over Google satellite basemap; red dots are geolocation points.)</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Notice how the data values are 'extruded' from the edges.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
This occurs with various interpolation methods (all the ones I tried), including nearest neighbor, average & bilinear. Why does this happen? How can I go about fixing this?</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Ideally, any pixel in the output grid which lies more than 1 pixel width from any of the geolocation points (red dots) would be assigned to no-data.</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
My code is very straightforward, basically I open the raw sensor image & geolocation array (a.k.a. input geometry map or IGM) with GDAL & then assign geolocation metadata to the sensor image before warping:</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<blockquote itemscope="" itemtype="https://schemas.microsoft.com/QuotedText" style="border-left-width:3px; border-left-style:solid; border-color:rgb(200,200,200); padding-left:1ex; margin-left:0.8ex; color:rgb(102,102,102)">
<span style="font-family:Consolas,Courier,monospace; font-size:10pt"># Geolocation domain metadata</span>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">geoloc_metadata = {</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'SRS': WGS84_UTM16N.ExportToWkt(),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'X_BAND': '1',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'X_DATASET': str(igm_img_file),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'Y_BAND': '2',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'Y_DATASET': str(igm_img_file),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'PIXEL_OFFSET': '0',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'LINE_OFFSET': '0',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'PIXEL_STEP': '1',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">    'LINE_STEP': '1',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">}</span></div>
<div><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"># Set geolocation domain metadata on dataset to be warped</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">dn_img_ds.SetMetadata(geoloc_metadata, 'GEOLOCATION')</span></div>
<div><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">x_min, y_min = igm[:2].min(axis=(1,2))</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">x_max, y_max = igm[:2].max(axis=(1,2))</span></div>
<div><br>
</div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"># warp_options = gdal.WarpOptions(warpMemoryLimit=)</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">warped_ds = gdal.Warp(f'/warped.tif', dn_img_ds,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt"><span style="background-color:rgb(255,255,255); display:inline!important"> <span class="x_Apple-converted-space">                     </span></span>outputBounds=(x_min, y_min, x_max,
 y_max),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      xRes=1.0,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      yRes=1.0,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      resampleAlg='near',</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      dstSRS=WGS84_UTM16N,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      srcNodata=None,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      dstNodata=-9999,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      multithread=True,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      targetAlignedPixels=True,</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      outputType=get_gdal_dtype(np.int16),</span></div>
<div><span style="font-family:Consolas,Courier,monospace; font-size:10pt">                      geoloc=True)</span></div>
</blockquote>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
Any insight would be much appreciated. Cheers!</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
     — Brendan Heberlein</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div style="margin:0px; font-size:15px; color:rgb(32,31,30)"><span style="margin:0px; font-size:10pt">            Research Intern, BS</span></div>
<div style="margin:0px; font-size:15px; color:rgb(32,31,30)"><span style="margin:0px; font-size:10pt">            Townsend Lab</span></div>
<span style="margin:0px; font-size:10pt; color:rgb(32,31,30); background-color:white">            University of Wisconsin - Madison</span></div>
</div>
</body>
</html>