<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">Le 06/10/2023 à 01:11, Soren Saville
Scott a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:CALK_jWY2Yjf+UKDf9XkBTTbka3ukVMhZbu-=6czEavWpk2uPzA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>Hi Even,</div>
<div><br>
</div>
<div>Suggests something wrong with my build. Is there possibly
something strange happening across DLL boundaries? Do you know
of any build flags that could change the VSIMEM behaviour?<br>
</div>
</div>
</blockquote>
I'm not seeing anything suspicious here, especially because
VSIGetMemFileBuffer() is in the C API.<br>
<blockquote type="cite"
cite="mid:CALK_jWY2Yjf+UKDf9XkBTTbka3ukVMhZbu-=6czEavWpk2uPzA@mail.gmail.com">
<div dir="ltr">
<div><br>
</div>
<div>As a secondary question, for multi-file datasets (like
shapefiles) does VSIGetMemFileBuffer() encapsulate all those
files - i.e. I should be able to call VSIFileFromMemBuffer()
on that buffer and GDALOpen() and get the same information
back? <br>
</div>
</div>
</blockquote>
<p>You need to read each file separately. VSIGetMemFileBuffer()
works at the file level. It has no idea of what a GDAL dataset is.</p>
<p>You can use GDALGetFileList() to get the list of files of a
dataset. You might want to do that on a dataset after re-opening,
since there has been a recent bug fix w.r.t GetFileList() on
shapefiles just created where one of the side car file wasn't
listed </p>
<blockquote type="cite"
cite="mid:CALK_jWY2Yjf+UKDf9XkBTTbka3ukVMhZbu-=6czEavWpk2uPzA@mail.gmail.com">
<div dir="ltr">
<div><br>
</div>
<div>Thanks for your help,</div>
<div>Soren</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, 4 Oct 2023 at 21:09,
Even Rouault <<a href="mailto:even.rouault@spatialys.com"
target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">even.rouault@spatialys.com</a>>
wrote:<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>
<p>Hi,</p>
<p>size_t is an incorrect size for DataLength (if you run on
32 bit architecture). You should use vsi_l_offset.</p>
<p>Besides that the following standalone inspired from your
code works fine for me:<br>
</p>
<p>#include <stdio.h><br>
#include "gdal_priv.h"<br>
<br>
int main()<br>
{<br>
GDALAllRegister();<br>
GDALDataset* Dataset
=GDALDataset::FromHandle(GDALOpenEx("poly.shp",
GDAL_OF_VECTOR | GDAL_OF_VERBOSE_ERROR, nullptr, nullptr,
nullptr));<br>
GDALDataset* Copy =
Dataset->GetDriver()->CreateCopy("/vsimem/foo.shp",
Dataset, false, nullptr, nullptr, nullptr); //appears to
produce a valid Dataset containing the same layers &
features as its source.<br>
GDALClose(Dataset);<br>
GDALClose(Copy);<br>
vsi_l_offset DataLength = 0;<br>
GByte* Buffer = VSIGetMemFileBuffer("/vsimem/foo.shp",
&DataLength, true);<br>
printf("%p %d\n", Buffer, int(DataLength)); // buffer
not null and DataLength > 0<br>
CPLFree(Buffer);<br>
VSIUnlink("/vsimem/foo.dbf");<br>
VSIUnlink("/vsimem/foo.shx");<br>
return 0;<br>
}</p>
<p>Even<br>
</p>
<div>Le 04/10/2023 à 06:26, Soren Saville Scott via gdal-dev
a écrit :<br>
</div>
<blockquote type="cite">
<div dir="ltr">Hi,
<div><br>
</div>
<div>I'm integrating GDAL in C++ with a system that
defines its own asset types stored on disk, and am
writing a wrapper for datasets using this asset
system. To 'import' a dataset I call GDALOpenEx on it,
CreateCopy() it to some "/vsimem/foo.shp" path,
GDALClose() the datasets to flush it, and call
VSIGetMemFileBuffer with bUnlinkAndSeize=true to take
ownership of the underlying memory buffer. </div>
<div><br>
</div>
<div>GDALDataset* Dataset = GDALOpenEx("foo.shp",
GDAL_OF_VECTOR | GDAL_OF_VERBOSE_ERROR, nullptr,
nullptr, nullptr);</div>
<div>GDALDataset* Copy =
Dataset->GetDriver()->CreateCopy("/vsimem/foo.shp",
Dataset, false, nullptr, nullptr, nullptr); //appears
to produce a valid Dataset containing the same layers
& features as its source.</div>
<div>GDALClose(Dataset);</div>
<div>GDALClose(Copy);</div>
<div>size_t DataLength;</div>
<div>GByte* Buffer =
VSIGetMemFileBuffer("/vsimem/foo.shp",
&DataLength, true); //<-- returns NULL</div>
<div><br>
</div>
<div>For some reason VSIGetMemFileBuffer always fails,
returning a nullptr. This is basically identical to a
similar problem I had, described here:<a
href="https://stackoverflow.com/questions/73644157/get-raw-buffer-for-in-memory-dataset-in-gdal-c-api"
target="_blank" moz-do-not-send="true"> https://stackoverflow.com/questions/73644157/get-raw-buffer-for-in-memory-dataset-in-gdal-c-api </a> which
I never really found a solution to. I have similar
issues with other VSI functions, e.g. calling
GDALOpenEx on a path created by VSIFileFromMemBuffer
also fails.</div>
<div><br>
</div>
<div>Any idea as to what the problem is here?</div>
<div><br>
</div>
<div>Alternatively, maybe there's a better way to
'emplace' datasets inside some other file?</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Soren Saville Scott</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
gdal-dev mailing list
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">gdal-dev@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre cols="72">--
<a href="http://www.spatialys.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</div>
</blockquote>
</div>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>