<div dir="ltr">makes sense, although I did <u>want</u> to use the buf_xsize, buf_ysize :)<div><br></div><div>Thanks<br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><font color="#999999"><br></font></div><div><font color="#999999">---</font></div><div><font color="#999999">Gregory Bataille</font><br></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 12, 2018 at 6:26 PM Even Rouault <<a href="mailto:even.rouault@spatialys.com">even.rouault@spatialys.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On mardi 12 juin 2018 16:47:08 CEST Grégory Bataille wrote:<br>
> Hey Even,<br>
> <br>
> Yes I guess ;)<br>
> <br>
> However, what you say is exactly what I did and what I had hoped but I<br>
> found that it was reading only the first 512x512 pixels of my big raster<br>
> and dumping at full res rather than downsampling it as I expected!<br>
<br>
You probably misused the (xsize, ysize) parameters instead of the (buf_xsize, buf_ysize).<br>
<br>
(xoff, yoff, xsize, ysize) are in full resolution image coordinates<br>
buf_xisze, buf_ysize is the dimension of the output buffer<br>
<br>
> I expected so much the behavior you mention so much that it took me time to<br>
> understand what was actually happening!<br>
> <br>
> Maybe I did something wrong then. I’ll retry again<br>
<br>
Little demo. Let's generate a 1024x1024 raster, with 512x512 overview<br>
<br>
$ gdal_translate byte.tif test.tif -outsize 1024 1024<br>
$ gdaladdo test.tif 2<br>
<br>
1) Reading whole raster at full resolution:<br>
<br>
$ CPL_DEBUG=ON python -c "from osgeo import gdal; ds = gdal.Open('test.tif'); ds.ReadAsArray()"<br>
[...]<br>
GDAL: GDALOpen(test.tif, this=0x1685430) succeeds as GTiff.<br>
[...]<br>
<br>
2) Reading whole raster at overview resolution:<br>
<br>
$ CPL_DEBUG=ON python -c "from osgeo import gdal; ds = gdal.Open('test.tif'); ds.ReadAsArray(buf_xsize=512, buf_ysize=512)"<br>
[...]<br>
GDAL: GDALOpen(test.tif, this=0xdae480) succeeds as GTiff.<br>
[...]<br>
GTiff: ScanDirectories()<br>
GTiff: Opened 512x512 overview.<br>
[...]<br>
<br>
> <br>
> Thanks for the quick answer as always<br>
> Greg<br>
> <br>
> On Tue, 12 Jun 2018 at 16:42, Even Rouault <<a href="mailto:even.rouault@spatialys.com" target="_blank">even.rouault@spatialys.com</a>><br>
> <br>
> wrote:<br>
> > On mardi 12 juin 2018 16:20:47 CEST Grégory Bataille wrote:<br>
> > > Hello everyone,<br>
> > > <br>
> > > I’m trying to migrate my code to COG more and more rather than<br>
> > > pre-computing some views/data.<br>
> > > <br>
> > > I have had some great success with extracting partial full res raster<br>
> > > values and it’s great.<br>
> > > <br>
> > > One thing I have not been able to do so far though is « reading from the<br>
> > > overview »<br>
> > > Say for example I want to render a 512x512 tiles of data but really<br>
> > <br>
> > zoomed<br>
> > <br>
> > > out. Let’s say for example that this tile contains my entire<br>
> > <br>
> > 10’000x10’000<br>
> > <br>
> > > pixels geotiff. It’s obviously super inefficient to read from the raw<br>
> > > raster rather than reading from one of the pre-computed overviews.<br>
> > > Is there an API (python) to ask for raster data (between 2 points) (like<br>
> > > ReadAsArray which is the one I currently use) but passing it the output<br>
> > > size so that gdal can figure out which overview it’s better to read<br>
> > > from?<br>
> > <br>
> > Grégory,<br>
> > <br>
> > This is a GDAL question in fact :-)<br>
> > <br>
> > Yes, the full signature of Dataset.ReadAsArray() is<br>
> > <br>
> >     def ReadAsArray(self, xoff=0, yoff=0, xsize=None, ysize=None,<br>
> >     <br>
> >                     buf_obj=None,<br>
> >                     buf_xsize=None, buf_ysize=None, buf_type=None,<br>
> >                     resample_alg=gdalconst.GRIORA_NearestNeighbour,<br>
> >                     callback=None,<br>
> >                     callback_data=None,<br>
> > <br>
> >                     interleave='band'):<br>
> > So specify buf_xsize and buf_ysize (or pass a buf_obj of the appropriate<br>
> > output size)<br>
> > <br>
> > Even<br>
> > <br>
> > --<br>
> > Spatialys - Geospatial professional services<br>
> > <a href="http://www.spatialys.com" rel="noreferrer" target="_blank">http://www.spatialys.com</a><br>
> > <br>
> > --<br>
> <br>
> Greg<br>
<br>
<br>
-- <br>
Spatialys - Geospatial professional services<br>
<a href="http://www.spatialys.com" rel="noreferrer" target="_blank">http://www.spatialys.com</a><br>
</blockquote></div>