<div dir="ltr"><ul><li>When debugging <b>gdal_translate </b>I noticed that both gdal_translate and GDALRasterIO chose tilematrix=22 (<i>WMTS: Using tilematrix=22 (zoom level 22)</i><br></li><li>The difference is in the next log line:</li><ul><li>gdal_translate uses XML as argument for GdalOpen:<br><i>HTTP: Fetch(<a href="https://basemap.nationalmap.gov/arcgis/rest/services/USGSHydroCached/MapServer/WMTS/1.0.0/WMTSCapabilities.xml" target="_blank">https://basemap.nationalmap.gov/arcgis/rest/services/USGSHydroCached/MapServer/WMTS/1.0.0/WMTSCapabilities.xml</a>)<br></i><i>WMTS: Using tilematrix=22 (zoom level 22)<br></i><i>WMS: Using C:\Users\Michal\.cache\gdalwmscache\4112649712971ece915a619d7334b09c for cache<br></i><i><b>GDAL: GDALOpen(<GDAL_WMS><Service name="TMS"> <ServerUrl><a href="https://basemap.nationalmap.gov/arcgis/rest/services/USGSHydroCached/MapServer/WMTS/tile/1.0.0/USGSHydroCached/default/default028mm/22/$%7By%7D/$%7Bx%7D.png" target="_blank">https://basemap.nationalmap.gov/arcgis/rest/services/USGSHydroCached/MapServer/WMTS/tile/1.0.0/USGSHydroCached/default/default028mm/22/${y}/${x}.png</a></ServerUrl></Service><DataWindow> <UpperLeftX>-20037508.342787</UpperLeftX> <UpperLeftY>20037508.342787</UpperLeftY> <LowerRightX>49090487.0664309</LowerRightX> <LowerRightY>-36387522.4405195</LowerRightY> <TileLevel>0</TileLevel> <TileX>0</TileX> <TileY>0</TileY> <SizeX>1852166912</SizeX> <SizeY>1511812608</SizeY> <YOrigin>top</YOrigin></DataWindow><BlockSizeX>256</BlockSizeX><BlockSizeY>256</BlockSizeY><BandsCount>4</BandsCount><DataType>Byte</DataType><Cache /><UnsafeSSL>true</UnsafeSSL><ZeroBlockHttpCodes>204,404</ZeroBlockHttpCodes><ZeroBlockOnServerException>true</ZeroBlockOnServerException></GDAL_WMS></b>, this=0000025616415250) succeeds as WMS.<br></i><i>WMS: Using C:\Users\Michal\.cache\gdalwmscache\9c7d5f9a99f1b710170c225a59a5ee4c for cache</i></li><li>log from my code shows different approach...But this approach works fine for the other subdataset from this server "tilematrixset=GoogleMapsCompatible"<br><i>[Fri Aug 30 11:12:41 2024].3130, 14.4900: HTTP: Fetch(<a href="https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/WMTS/1.0.0/WMTSCapabilities.xml" target="_blank">https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/WMTS/1.0.0/WMTSCapabilities.xml</a>)</i><br><i>[Fri Aug 30 11:12:41 2024].9710, 15.1480: WMTS: Using tilematrix=22 (zoom level 22)</i><br><i>[</i><b style="font-style:italic">Fri Aug 30 11:12:41 2024].9730, 15.1500: GDAL: GDALOpen(WMTS:<a href="https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/WMTS/1.0.0/WMTSCapabilities.xml,layer=USGSImageryOnly,tilematrixset=default028mm" target="_blank">https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/WMTS/1.0.0/WMTSCapabilities.xml,layer=USGSImageryOnly,tilematrixset=default028mm</a>, this=0000028EE0F1AA30) succeeds as WMTS.<br>[</b><i>Fri Aug 30 11:12:41 2024].9970, 15.1740: CPLError: WMTSCapabilities.xml,layer=USGSImageryOnly,tilematrixset=default028mm: Access window out of range in RasterIO(). Requested (0,0) of size 1073741760x764544 on raster of 1073741756x1347126255.</i><br><i>ERROR 5: WMTSCapabilities.xml,layer=USGSImageryOnly,tilematrixset=default028mm: Access window out of range in RasterIO(). Requested (0,0) of size 1073741760x764544 on raster of 1073741756x1347126255.</i><br></li></ul><li>gdal_translate also works for -ovr NONE<br></li><li>when I hardcode to use <b>nxSize=1073741756</b> instead of <b>1073741760</b>, similar problem occurs later:<br>GDAL CPL Error 5: WMTSCapabilities.xml,layer=USGSImageryOnly,tilematrixset=default028mm: Access window out of range in RasterIO(). Requested (0,1344795604) of size 1073741756x2330668 on raster of 1073741756x1347126255.<br></li><li>answering to you last question - I fill windows bitmap using Delphi where I need to copy byte values line-by-line (using scanline approach).</li></ul><div>I guess we're still stuck :-(</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">pt., 30 sie 2024 o 09:50 Rahkonen Jukka <<a href="mailto:jukka.rahkonen@maanmittauslaitos.fi" target="_blank">jukka.rahkonen@maanmittauslaitos.fi</a>> napisał(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>
<div lang="FI">
<div>
<p class="MsoNormal"><span>Hi,<u></u><u></u></span></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">I do not know either, I am not a programmer. I have used sometimes a local proxy server for capturing the http traffic. With gdal_translate the http requests are printed when the command
is run with -- debug on. It would probably be good to run gdal_translate with -ovr NONE
<a href="https://gdal.org/en/latest/programs/gdal_translate.html#cmdoption-gdal_translate-ovr" target="_blank">
https://gdal.org/en/latest/programs/gdal_translate.html#cmdoption-gdal_translate-ovr</a> and force it to use the full resolution image, because I quess that your code is also hitting the full resolution. Maybe gdal_translate is already hitting the same resolution,
but by using -ovr it is you who makes the decision.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">By reading the values it seems that you request 1073741760 pixels but for some reason GDAL believes that there are only 1073741756 pixels available. If I were a programmer, I think I
would have a try with nXSize=1073741756.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">May I ask why do you want to compress quite a large area of a raster into a single line of pixels? You have probably some interesting use case.<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<p class="MsoNormal"><span lang="EN-US">-Jukka Rahkonen-<u></u><u></u></span></p>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">Lähettäjä:</span></b><span lang="EN-US"> Michał Kowalczuk <<a href="mailto:michkowalczuk@gmail.com" target="_blank">michkowalczuk@gmail.com</a>>
<br>
<b>Lähetetty:</b> perjantai 30. elokuuta 2024 10.28<br>
<b>Vastaanottaja:</b> Rahkonen Jukka <<a href="mailto:jukka.rahkonen@maanmittauslaitos.fi" target="_blank">jukka.rahkonen@maanmittauslaitos.fi</a>><br>
<b>Kopio:</b> Robert Coup <<a href="mailto:robert.coup@koordinates.com" target="_blank">robert.coup@koordinates.com</a>>; <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<b>Aihe:</b> Re: [gdal-dev] WMTS gdal_translate vs RasterIO<u></u><u></u></span></p>
</div>
<p class="MsoNormal"><span lang="EN-US"><u></u> <u></u></span></p>
<div>
<p class="MsoNormal">Full GDAL log attached.<u></u><u></u></p>
<div>
<p class="MsoNormal">Sorry, but I do not know how to test your suggestion. GDAL logger creates some caches and I do not know which http request i should use...<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Thanks, Michał<u></u><u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">pt., 30 sie 2024 o 09:23 Rahkonen Jukka <<a href="mailto:jukka.rahkonen@maanmittauslaitos.fi" target="_blank">jukka.rahkonen@maanmittauslaitos.fi</a>> napisał(a):<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<div>
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">Capture and show the http request that your code generates and sends to the WMTS server. Does it work if you send the same request with curl or with a browser?
Or does the error come before the GetTile request is generated?</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US">-Jukka Rahkonen-</span><u></u><u></u></p>
<p class="MsoNormal"><span lang="EN-US"> </span><u></u><u></u></p>
<div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0cm 0cm">
<p class="MsoNormal"><b>Lähettäjä:</b> Michał Kowalczuk <<a href="mailto:michkowalczuk@gmail.com" target="_blank">michkowalczuk@gmail.com</a>>
<br>
<b>Lähetetty:</b> perjantai 30. elokuuta 2024 9.59<br>
<b>Vastaanottaja:</b> Robert Coup <<a href="mailto:robert.coup@koordinates.com" target="_blank">robert.coup@koordinates.com</a>><br>
<b>Kopio:</b> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>; Rahkonen Jukka <<a href="mailto:jukka.rahkonen@maanmittauslaitos.fi" target="_blank">jukka.rahkonen@maanmittauslaitos.fi</a>><br>
<b>Aihe:</b> Re: [gdal-dev] WMTS gdal_translate vs RasterIO<u></u><u></u></p>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal">Sorry for incorrect sample commands in the last message.<u></u><u></u></p>
<div>
<p class="MsoNormal">I fixed it. The problem stays the same, because the problem was in email not in my tested code.<u></u><u></u></p>
<div>
<p class="MsoNormal"><b>gdal_translate -srcwin 0 0 1073741760 1553779 -outsize 691 1 "WMTS:<a href="https://basemap.nationalmap.gov/arcgis/rest/services/USGSHydroCached/MapServer/WMTS/1.0.0/WMTSCapabilities.xml,layer=USGSHydroCached,tilematrixset=default028mm" target="_blank">https://basemap.nationalmap.gov/arcgis/rest/services/USGSHydroCached/MapServer/WMTS/1.0.0/WMTSCapabilities.xml,layer=USGSHydroCached,tilematrixset=default028mm</a>"
tile.png</b><u></u><u></u></p>
</div>
</div>
<div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>GDALDatasetRasterIO(</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>handle_to_wmts_subdataset,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>eRWFlag=GF_Read,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nXOff=0,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nYOff=0,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nXSize=1073741760,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nYSize=1553779,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>pBuffer - buffer for data,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nBufXSize=691,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nBufYSize=1,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>eBufType=GDT_Byte,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nBandCount=4,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>panBandMap=[bIndex ,gIndex, rIndex, aIndex],</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nPixelSpace=4,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nLineSpace=0,</b><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>nBandSpace=1)</b><u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">Can anyone help me to understand why gdal_translate works and generates output file, where GDALRasterIO raises error:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><b>Requested (0,0) of size 1073741760x1553779 on raster of 1073741756x1347126255?</b><u></u><u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">czw., 29 sie 2024 o 12:22 Michał Kowalczuk <<a href="mailto:michkowalczuk@gmail.com" target="_blank">michkowalczuk@gmail.com</a>> napisał(a):<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<p class="MsoNormal">I see. I will double check commands, fix and return to this.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">W dniu czw., 29.08.2024 o 12:20 Robert Coup <<a href="mailto:robert.coup@koordinates.com" target="_blank">robert.coup@koordinates.com</a>> napisał(a):<u></u><u></u></p>
</div>
<blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin:5pt 0cm 5pt 4.8pt">
<div>
<p class="MsoNormal">Hi Michał,<u></u><u></u></p>
<div>
<p class="MsoNormal"><br>
In addition to Jukka's key point:<br>
<br>
nBufXSize=1,<br>
nBufYSize=691,<br>
<br>
appears to be backwards wrt:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><br>
-outsize 691 1<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Rob :)<u></u><u></u></p>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div></blockquote></div>