<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Abel,</p>
<p>OK, I now better understand what you meant. Well, no, there's no
way for the writing part of a driver to know how many features
there are in the source layer, because in the general case, there
is no source layer... Users could potentially call CreateFeature()
without any source layer and without knowing in advance how many
features they are going to write. Ideally your driver wouldn't
need to know that, but I don't know the specificities of your
format. If you really need to know the number of features before
being able to write the file, the strategy would be that the
ICreateFeature() method of your driver actually delegates writing
those features to another GDAL driver (e.g GeoPackage) in a
temporary file, and upon layer closing, you read back that
temporary file to actually write your own file.</p>
<p>In some cases, ogr2ogr could potentially know in advance the
number of features to be written and pass them to the output
driver(as well as the extent typically), but:</p>
<p>- knowing the number of features can be a pretty slow operation
for some input drivers , or when using a SQL statement</p>
<p>- and there's no such infrastructure currently<br>
</p>
<p>Even<br>
</p>
<div class="moz-cite-prefix">Le 21/07/2023 à 19:23, Abel Pau a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:AS8PR07MB8168D50BCEE675AC35183853A23FA@AS8PR07MB8168.eurprd07.prod.outlook.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Microsoft Word 15 (filtered
medium)">
<style>@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}pre
{mso-style-priority:99;
mso-style-link:"HTML con formato previo Car";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";
mso-fareast-language:CA;}span.HTMLconformatoprevioCar
{mso-style-name:"HTML con formato previo Car";
mso-style-priority:99;
mso-style-link:"HTML con formato previo";
font-family:Consolas;
mso-fareast-language:EN-US;}p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;
mso-fareast-language:CA;}span.EstiloCorreo21
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}span.EstiloCorreo22
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}span.EstiloCorreo23
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}div.WordSection1
{page:WordSection1;}</style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D" lang="ES">Hello!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="ES"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">I’ve
been trying to use the
</span>OGRLayer::GetFeatureCount() <span
style="color:#1F497D" lang="EN-US">when I am reading another
format inside the
</span><span
style="font-size:9.5pt;font-family:Consolas;color:black;mso-fareast-language:CA">ICreateFeature()
</span><span style="color:#1F497D" lang="EN-US">but I think
it’s impossible. At this point I don’t have access to the
layer info, so to the GetFeatureCount().<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">In
fact I don’t mind where to call this function but I need to
call it in order to write our format efficiently (at least
in most of cases).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">So
the question is, in my driver, when I read a format I get
some information about the layer but I can’t acces to the
count of the features of the layer. I am right? If not, how
I do that?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">Thanks
but before sending this mail I’ve been like hours trying to
find it out debbuging and consulting the call stack from all
points and nothing seems to indicate I can do that. But
perhaps I am wrong.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">It
would be very helpful knowing that information. I not my
writting strategy with change radically. Thankssssss!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span
style="mso-fareast-language:CA" lang="ES">De:</span></b><span
style="mso-fareast-language:CA" lang="ES"> gdal-dev
<a class="moz-txt-link-rfc2396E" href="mailto:gdal-dev-bounces@lists.osgeo.org"><gdal-dev-bounces@lists.osgeo.org></a>
<b>En nombre de </b>Abel Pau<br>
<b>Enviado el:</b> divendres, 7 de juliol de 2023 12:44<br>
<b>Para:</b> Even Rouault
<a class="moz-txt-link-rfc2396E" href="mailto:even.rouault@spatialys.com"><even.rouault@spatialys.com></a>;
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br>
<b>Asunto:</b> Re: [gdal-dev] A question of eficiency<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="ES">Hi
again,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="ES"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">I
can totally give this number in
</span>GetFeatureCount()<span style="color:#1F497D"
lang="EN-US">. No problem from my driver to other.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">Then
I understand that in one way (efficient) or in another (no
efficient) I can always get the number of features with the
GetFeatureCount(). True?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">About
the other question imagine a multiline shape with two lines
of two parts every line. I need to know the total count of
individual lines (cause my driver doesn’t have multiline and
I have to convert every multiline to N lines). It is 4
(2+2). Can I get this number without asking every feature
how many parts it have? I doubt that, but...
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US">Thanks
for your kind anwser!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D" lang="EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1
1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span
style="mso-fareast-language:CA" lang="EN-US">De:</span></b><span
style="mso-fareast-language:CA" lang="EN-US"> Even
Rouault <<a href="mailto:even.rouault@spatialys.com"
moz-do-not-send="true" class="moz-txt-link-freetext">even.rouault@spatialys.com</a>>
<br>
<b>Enviado el:</b> divendres, 7 de juliol de 2023 </span><span
style="mso-fareast-language:CA" lang="ES">12:32<br>
<b>Para:</b> Abel Pau <<a
href="mailto:a.pau@creaf.uab.cat"
moz-do-not-send="true" class="moz-txt-link-freetext">a.pau@creaf.uab.cat</a>>;
<a href="mailto:gdal-dev@lists.osgeo.org"
moz-do-not-send="true" class="moz-txt-link-freetext">gdal-dev@lists.osgeo.org</a><br>
<b>Asunto:</b> Re: [gdal-dev] A question of eficiency<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>Abel,<span style="font-size:12.0pt;mso-fareast-language:CA"><o:p></o:p></span></p>
<p>At the minimum for the reading side of a vector driver, you
need to implement GetNextFeature().<o:p></o:p></p>
<p>If there is an efficient way of knowing the number of
features without iterating over the whole file (typically a
field in a header giving that number), you may implement
GetFeatureCount(). If you don't implement it, and code using
your driver needs the feature count, the generic
implementation of OGRLayer::GetFeatureCount() will call
GetNextFeature() repeatdly until it returns NULL.<o:p></o:p></p>
<p>Not totally sure to understand your question about
multielements. If you have an instance of
OGRGeometryCollection or any deriving class, there's a
getNumGeometries() method to get the number of parts<o:p></o:p></p>
<p>Even<o:p></o:p></p>
<div>
<p class="MsoNormal">Le 07/07/2023 à 11:33, Abel Pau a écrit :<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"><span lang="EN-US">Hi,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">I would like to know
if when we use the code of GDAL to program a driver (or
whatever) in vectors (so, ogr) we can assume that we can
know the number of elements we are going to import in any
way or it would be possible not knowing that until
NextFeature is empty (or something like that). So, there
is any way to obtain this number of elements without doing
a while? And in case of multielements its possible to know
how many parts are there in total?</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">I need that to write
my format (I don’t explain the details cause I don’t get
you bored :) )</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">If anyone know that
I’d appreciate an answer. Thanks in advance.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-US">Abel.</span><o:p></o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span
style="font-size:12.0pt;font-family:"Times New
Roman",serif;mso-fareast-language:CA"><o:p> </o:p></span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>gdal-dev mailing list<o:p></o:p></pre>
<pre><a href="mailto:gdal-dev@lists.osgeo.org" moz-do-not-send="true" class="moz-txt-link-freetext">gdal-dev@lists.osgeo.org</a><o:p></o:p></pre>
<pre><a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" moz-do-not-send="true" class="moz-txt-link-freetext">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><o:p></o:p></pre>
</blockquote>
<pre>-- <o:p></o:p></pre>
<pre><a href="http://www.spatialys.com" moz-do-not-send="true" class="moz-txt-link-freetext">http://www.spatialys.com</a><o:p></o:p></pre>
<pre>My software is free, but my time generally not.<o:p></o:p></pre>
</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>