<div dir="ltr">Sean,<div><br></div><div>Very cool. One follow up question, do you really need the "with" for open? Does this not work (and MemoryFile can drop the file descriptor as soon as it wants to)?</div><div><br></div><div><div style="font-size:12.8px">with MemoryFile(<span style="font-size:12.8px">open(path_zip_file, 'rb')</span><span style="font-size:12.8px">) as memfile:</span></div><div style="font-size:12.8px"> with memfile.open('white-gemini-iv.<wbr>vrt') as dataset:</div><div style="font-size:12.8px"> assert dataset.count == 3</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 31, 2017 at 3:35 PM, Sean Gillies <span dir="ltr"><<a href="mailto:sean@mapbox.com" target="_blank">sean@mapbox.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for confirming that I was on the right trail, Even! I got it figured out: I was naively trying to open the /vsizip/vsimem/ file in update mode.<div><br></div><div>In case you're interested, my new Python usage is like this:<div><div><br></div>with open(path_zip_file, 'rb') as f:<div> with MemoryFile(f) as memfile:</div><div> with memfile.open('white-gemini-iv.<wbr>vrt') as dataset:</div><div> assert dataset.count == 3</div><div><br></div><div><div><a href="https://github.com/mapbox/rasterio/pull/972/files#diff-d3388b510bd97235e4741b8417cc41e9R148" target="_blank">https://github.com/mapbox/<wbr>rasterio/pull/972/files#diff-<wbr>d3388b510bd97235e4741b8417cc41<wbr>e9R148</a><br></div></div></div><div><br></div></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Tue, Jan 31, 2017 at 5:42 PM, Even Rouault <span dir="ltr"><<a href="mailto:even.rouault@spatialys.com" target="_blank">even.rouault@spatialys.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
<div style="font-family:'Sans Serif';font-size:9pt;font-weight:400;font-style:normal"><span>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">On mardi 31 janvier 2017 17:33:23 CET Sean Gillies wrote:</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> Hey all,</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> The tests in</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> <a href="https://svn.osgeo.org/gdal/branches/1.9/autotest/gcore/vsizip.py" target="_blank">https://svn.osgeo.org/gdal/bra<wbr>nches/1.9/autotest/gcore/vsizi<wbr>p.py</a> show how</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> to create a zip archive in memory and create directories and files within</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> it. I'm looking for a shortcut.</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> Given a sequence of bytes representing an existing zip file that contains a</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> TIFF and a VRT (referencing the TIFF), is it possible to make a VSI file</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> from this buffer (using VISFileFromMemBuffer()) and then access the VRT</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> using a path like /vsizip/vsimem/archive.zip/exa<wbr>mple.vrt protocol?</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
</span><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Hi Sean,</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">That sounds like you tested it and something went wrong ? Perhaps check the path to the source in the VRT and the value of the relativeToVRT attribute.</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Your above strategy does work for me:</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">$ gdal_translate byte.tif byte.vrt -of VRT</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Input file size is 20, 20</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">$ zip byte.tif.zip byte.tif byte.vrt</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> adding: byte.tif (deflated 96%)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> adding: byte.vrt (deflated 53%)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">$ python</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">>>> from osgeo import gdal</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">>>> data = open('byte.tif.zip', 'rb').read()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">>>> gdal.FileFromMemBuffer('/vsime<wbr>m/archive.zip', data)</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">>>> ds = gdal.Open('/vsizip/vsimem/arch<wbr>ive.zip/byte.vrt')</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">>>> ds.GetRasterBand(1).Checksum()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">4672</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Even</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"> </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">-- </p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Spatialys - Geospatial professional services</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><a href="http://www.spatialys.com" target="_blank">http://www.spatialys.com</a></p></div></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div class="m_2034271880873081025gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Sean Gillies</div></div>
</font></span></div>
<br>______________________________<wbr>_________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/gdal-dev</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--<div><a href="http://schwehr.org" target="_blank">http://schwehr.org</a></div></div>
</div>