<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Bonjour,</p>
<p>Est-il possible d'utiliser la signature de la librairie python
Planetary_Computer pour lire des COG depuis le catalogue STAC
Microsoft ?</p>
<p>J'ai essayé plusieurs méthode en utilisant /vsicurl/ mais les
extended filenames associé à la signature ne sont pas reconnu.</p>
<p>Est-il possible de lire ces données à la manière de RasterIO ?</p>
<p>J'utilise gdal version 3.5.2</p>
<p>code python en erreur :</p>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">vsistr</span><span style="color: #d4d4d4;"> = </span><span style="color: #ce9178;">"/vsicurl?pc_url_signing=yes&pc_collection=sentinel-2-l2a&url="</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">red_href</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">vsistr</span><span style="color: #d4d4d4;"> + </span><span style="color: #4ec9b0;">planetary_computer</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">sign</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">item</span><span style="color: #d4d4d4;">).assets[</span><span style="color: #ce9178;">"B04"</span><span style="color: #d4d4d4;">].href </span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">cogtif</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">gdal</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">Open</span><span style="color: #d4d4d4;">( </span><span style="color: #9cdcfe;">red_href</span><span style="color: #d4d4d4;"> )</span></div></div>
<p>response :<br>
</p>
<pre>Warning 6: Unsupported option: se
Warning 6: Unsupported option: sp
Warning 6: Unsupported option: sv
Warning 6: Unsupported option: sr
Warning 6: Unsupported option: skoid
Warning 6: Unsupported option: sktid
Warning 6: Unsupported option: skt
Warning 6: Unsupported option: ske
Warning 6: Unsupported option: sks
Warning 6: Unsupported option: skv
Warning 6: Unsupported option: sig
ERROR 11: HTTP response code: 403
</pre>
<p>code python ok :</p>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #d4d4d4;"> </span>
<div style="color: #d4d4d4;background-color: #1e1e1e;font-family: 'Droid Sans Mono', 'monospace', monospace;font-weight: normal;font-size: 14px;line-height: 19px;white-space: pre;"><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">with</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">fiona</span><span style="color: #d4d4d4;">.open(</span><span style="color: #9cdcfe;">shp</span><span style="color: #d4d4d4;">, </span><span style="color: #ce9178;">"r"</span><span style="color: #d4d4d4;">) </span><span style="color: #c586c0;">as</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">shapefile</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">shapes</span><span style="color: #d4d4d4;"> = [</span><span style="color: #9cdcfe;">feature</span><span style="color: #d4d4d4;">[</span><span style="color: #ce9178;">"geometry"</span><span style="color: #d4d4d4;">] </span><span style="color: #c586c0;">for</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">feature</span><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">in</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">shapefile</span><span style="color: #d4d4d4;">]</span></div><div><span style="color: #d4d4d4;">
</span></div></div><span style="color: #d4d4d4;"></span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">with</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">rasterio</span><span style="color: #d4d4d4;">.open(</span><span style="color: #4ec9b0;">planetary_computer</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">sign</span><span style="color: #d4d4d4;">(</span><span style="color: #9cdcfe;">item</span><span style="color: #d4d4d4;">).assets[</span><span style="color: #ce9178;">"B04"</span><span style="color: #d4d4d4;">].href ) </span><span style="color: #c586c0;">as</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">ds</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">out_image</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">out_transform</span><span style="color: #d4d4d4;"> = </span><span style="color: #4ec9b0;">rasterio</span><span style="color: #d4d4d4;">.mask.mask(</span><span style="color: #9cdcfe;">ds</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">shapes</span><span style="color: #d4d4d4;">, </span><span style="color: #9cdcfe;">crop</span><span style="color: #d4d4d4;">=</span><span style="color: #569cd6;">True</span><span style="color: #d4d4d4;">)</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">out_meta</span><span style="color: #d4d4d4;"> = </span><span style="color: #9cdcfe;">ds</span><span style="color: #d4d4d4;">.meta</span></div><div><span style="color: #d4d4d4;"> </span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">out_meta</span><span style="color: #d4d4d4;">.update({</span><span style="color: #ce9178;">"driver"</span><span style="color: #d4d4d4;">: </span><span style="color: #ce9178;">"GTiff"</span><span style="color: #d4d4d4;">,</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #ce9178;">"height"</span><span style="color: #d4d4d4;">: </span><span style="color: #9cdcfe;">out_image</span><span style="color: #d4d4d4;">.shape[</span><span style="color: #b5cea8;">1</span><span style="color: #d4d4d4;">],</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #ce9178;">"width"</span><span style="color: #d4d4d4;">: </span><span style="color: #9cdcfe;">out_image</span><span style="color: #d4d4d4;">.shape[</span><span style="color: #b5cea8;">2</span><span style="color: #d4d4d4;">],</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #ce9178;">"transform"</span><span style="color: #d4d4d4;">: </span><span style="color: #9cdcfe;">out_transform</span><span style="color: #d4d4d4;">}) </span></div>
<div><span style="color: #d4d4d4;"> </span><span style="color: #c586c0;">with</span><span style="color: #d4d4d4;"> </span><span style="color: #4ec9b0;">rasterio</span><span style="color: #d4d4d4;">.open(</span><span style="color: #9cdcfe;">out</span><span style="color: #d4d4d4;">, </span><span style="color: #ce9178;">"w"</span><span style="color: #d4d4d4;">, **</span><span style="color: #9cdcfe;">out_meta</span><span style="color: #d4d4d4;">) </span><span style="color: #c586c0;">as</span><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">dest</span><span style="color: #d4d4d4;">:</span></div><div><span style="color: #d4d4d4;"> </span><span style="color: #9cdcfe;">dest</span><span style="color: #d4d4d4;">.write(</span><span style="color: #9cdcfe;">out_image</span><span style="color: #d4d4d4;">)</span></div></div>
<p>Merci pour vos réponses</p>
<p>Bien cordialement,</p>
<p>Loïc<br>
</p>
</body>
</html>