<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: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=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<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:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
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.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
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="PT" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">I think you need an extra point. If you will be doing resampling than you need extra row/columns for the boundary conditions (one for linear, two for spline/bicubic). Regarding 2) the
 options are:  round to closest node, or to the inner or to the outer node.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US" style="mso-fareast-language:EN-US">Joaquim<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> gdal-dev <gdal-dev-bounces@lists.osgeo.org>
<b>On Behalf Of </b>Aurélien Albert<br>
<b>Sent:</b> Thursday, October 11, 2018 11:28 AM<br>
<b>To:</b> gdal-dev@lists.osgeo.org<br>
<b>Subject:</b> [gdal-dev] Best method to extract regions from a raster into a memory buffer<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div id="divtagdefaultwrapper">
<p><span style="font-size:12.0pt;color:black">Hi,<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">I'm doing C++ applications and I'm familiar with GDAL 1.7 C/C++ API. For a new application, I'm switching to GDAL 2.2.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">In this application, I have the need to extract a region from a raster :<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Let's say I have 4000px x 4000px elevation raster, covering the whole earth, in EPSG 4326.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Now I want to extract the rectangle region between two points (lat_1/long_1) and (lat_2/long_2) in a 128px x 128px tile.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">I don't want to extract this region in a file, but in memory, to create a data buffer and then work on this buffer with my application.<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Which is the best/more performant way to do this ?<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Knowing that :<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> 1/ the region extraction may need some resampling, so I need to be able to configure the resampling method<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> 2/ the extracted region boundaries do no necessary fit on exact pixels of the original dataset<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> 3/ the SRS will not be modified, but I may need a vertical datum shift (EGM96 to WGS84 for example)<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> 4/ the extraction will be repeated a lot (a lot !) to extract several "tiles" with different bounds : the application can work on really big rasters, so I prefer to avoid complex objects initialization for each
 extraction<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">Should I :<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">- create a wrapped dataset (VRTDataSet) and make RasterIO on it ? This seems to solve 1/ and 3/ and 4/, but what about 2/ ?<o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black">- use a WarpOperation and then execute WarpRegionToBuffer method ? <span style="background:white">This seems to solve 1/ and 2/ and 3/, but what about 4/ ?</span><o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black;background:white">Any help will be appreciated.</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black"> <o:p></o:p></span></p>
<p><span style="font-size:12.0pt;color:black;background:white">Thanks</span><span style="font-size:12.0pt;color:black"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p> </o:p></span></p>
</div>
</div>
</div>
</body>
</html>