<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Yes, you're right, I may need some extra pixels on the boundaries (depend on the resampling method).</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Does not GDAL manage this by itself ? I mean, if you ask for a warp, it doesn't read all necessary pixel to do the resampling ?</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Since GDAL 2.0, there is some API changes, and I'm looking for the most efficient way to do my operation : extract a region specified with geographic coordinates (in the same SRS as the data source) to a fixed size pixel
 buffer. Resampling should occur because the pixel count of the extracted region (source) and pixel count of the buffer (destination) will not fit.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>De :</b> gdal-dev <gdal-dev-bounces@lists.osgeo.org> de la part de Joaquim Manuel Freire Luís <jluis@ualg.pt><br>
<b>Envoyé :</b> jeudi 11 octobre 2018 16:47:27<br>
<b>À :</b> gdal-dev@lists.osgeo.org<br>
<b>Objet :</b> Re: [gdal-dev] Best method to extract regions from a raster into a memory buffer</font>
<div> </div>
</div>
<meta content="text/html; charset=iso-8859-1">
<meta name="x_Generator" content="Microsoft Word 15 (filtered medium)">
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
a:x_link, span.x_MsoHyperlink
        {color:#0563C1;
        text-decoration:underline}
a:x_visited, span.x_MsoHyperlinkFollowed
        {color:#954F72;
        text-decoration:underline}
p.x_msonormal0, li.x_msonormal0, div.x_msonormal0
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
span.x_EmailStyle19
        {font-family:"Calibri",sans-serif}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
-->
</style>
<div lang="PT" link="#0563C1" vlink="#954F72">
<div class="x_WordSection1">
<p class="x_MsoNormal"><span lang="EN-US" style="">Hi,</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style=""> </span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="">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.</span></p>
<p class="x_MsoNormal"><span lang="EN-US" style=""> </span></p>
<p class="x_MsoNormal"><span lang="EN-US" style="">Joaquim</span></p>
<p class="x_MsoNormal"><span style=""> </span></p>
<p class="x_MsoNormal"><span style=""> </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="x_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</span></p>
</div>
</div>
<p class="x_MsoNormal"> </p>
<div id="x_divtagdefaultwrapper">
<p><span style="font-size:12.0pt; color:black">Hi,</span></p>
<p><span style="font-size:12.0pt; color:black"> </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.</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 :</span></p>
<p><span style="font-size:12.0pt; color:black"> </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.</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.</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.</span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black">Which is the best/more performant way to do this ?</span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black">Knowing that :</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</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</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)</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</span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black">Should I :</span></p>
<p><span style="font-size:12.0pt; color:black"> </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/ ?</span></p>
<p><span style="font-size:12.0pt; color:black"> </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></span></p>
<p><span style="font-size:12.0pt; color:black"> </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"></span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black"> </span></p>
<p><span style="font-size:12.0pt; color:black; background:white">Thanks</span><span style="font-size:12.0pt; color:black"></span></p>
<p class="x_MsoNormal"><span style="font-size:12.0pt; color:black"> </span></p>
</div>
</div>
</div>
</div>
</body>
</html>