<div dir="ltr"><div>I'm not sure if it's a shortcut but couldn't you do a getFeatures loop with a counter and break after 2 times round the loop, then your counter would be 0,1 or 2 for your 3 cases.</div><div><br></div><div>Ian<br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 20 Jan 2022 at 09:00, Jon Morris <<a href="mailto:Jon.Morris@jbarisk.com">Jon.Morris@jbarisk.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 style="overflow-wrap: break-word;" lang="EN-GB">
<div class="gmail-m_-3272004911288444094WordSection1">
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black">I'm writing applications using the GDAL Python bindings and when I profile for performance, GetFeatureCount frequently comes out near the top. I'm often using it to check whether
 a spatial or attribute filter has returned any features and don't need the full count. When the layer contains millions of features, there would be a big performance improvement if we could exit the count early.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black">Is there a better way of doing this? I've tried using GetNextFeature instead, but there must be quite a lot of overhead in that function as it is much slower. All I need to know is
 if the layer has has 0, 1 or >1 features, I don't need the actual count. Can anyone suggest the fastest way of doing this in Python? I'm using GDAL 3.3.1 at the moment but could upgrade if there is new functionality that would help.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black">Thanks,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black">Jon<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-family:"Arial",sans-serif;color:rgb(246,161,36)">Jon Morris<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="font-family:"Arial",sans-serif;color:rgb(74,74,73)">Software Developer<u></u><u></u></span></b></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif;color:black"><u></u> <u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div dir="ltr" style="direction:ltr"><table style="width:100%" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="vertical-align:top" align="left"><table style="font-size:0px" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:10px 0px 0px;vertical-align:top" align="left"><table style="font-size:0px;color:rgb(74,74,73);font-style:normal;font-weight:700;white-space:nowrap" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:14.67px"><td style="padding:0px;vertical-align:top;font-family:Arial" align="left">e: <span style="font-family:remialcxesans;font-size:1px;color:rgb(255,255,255);line-height:1px">​</span></td><td style="padding:0px 0px 0px 4px;vertical-align:top;color:rgb(246,161,36);font-family:Arial;font-weight:400" align="left"><a href="mailto:Jon.Morris@jbarisk.com" id="gmail-m_-3272004911288444094LPlnk689713" style="text-decoration:none;color:rgb(246,161,36)" target="_blank"><strong style="font-weight:400">Jon.Morris@jbarisk.com</strong></a></td></tr><tr style="font-size:14.67px"><td style="padding:0px;vertical-align:top;font-family:Arial" align="left">t: </td><td style="padding:0px 0px 0px 4px;vertical-align:top;color:rgb(246,161,36);font-family:Arial;font-weight:400" align="left"><a href="tel:+44%20(0)1756%20799919" id="gmail-m_-3272004911288444094LPlnk689713" style="text-decoration:none;color:rgb(246,161,36)" target="_blank"><strong style="font-weight:400">+44 (0)1756 799919</strong></a></td></tr><tr style="font-size:0px"><td style="padding:0px;vertical-align:top" align="left"></td><td style="padding:0px 0px 0px 4px;vertical-align:top" align="left"></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr style="color:rgb(0,0,1);font-size:14.67px;font-style:normal;font-weight:400;white-space:nowrap"><td style="vertical-align:top;font-family:Arial" align="left"><a href="http://www.jbarisk.com/" id="gmail-m_-3272004911288444094LPlnk689713" title="Click to visit our website" style="text-decoration:none;color:rgb(246,161,36)" target="_blank"><strong style="font-weight:400">www.jbarisk.com</strong></a></td></tr><tr style="font-size:0px"><td style="vertical-align:top" align="left"><table style="font-size:0px" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:10px 0px 0px;vertical-align:top" align="left"><table style="font-size:0px" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td rowspan="3" style="padding:0px 0px 5px;vertical-align:top" align="left"><table style="width:100%;font-size:0px" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="vertical-align:top" align="left"><table style="font-size:0px;line-height:normal" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:10px 0px 15px;vertical-align:top" align="left"><img src="cid:17e771eeeffe03fce501" alt="" style="height: 52px; min-height: 52px; max-height: 52px; font-size: 0px;" height="52" border="0"></td></tr></tbody></table></td></tr><tr style="font-size:0px"><td style="vertical-align:top" align="left"><table style="font-size:0px" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:0px 0px 12px;vertical-align:top" align="left"><table style="height:30px;font-size:0px" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="vertical-align:top" align="left"><table style="font-size:0px;line-height:normal" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:0px 4px 5px 0px;vertical-align:top" align="left"><a href="https://www.facebook.com/TheFloodPeople" id="gmail-m_-3272004911288444094LPlnk689713" style="text-decoration:none" target="_blank"><img src="cid:17e771eef008a1f98b42" title="Facebook" alt="Facebook" style="width: 34px; min-width: 34px; max-width: 34px; font-size: 12px;" width="34" border="0"></a></td></tr></tbody></table></td><td style="vertical-align:top" align="left"><table style="font-size:0px;line-height:normal" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:0px 4px 5px 0px;vertical-align:top" align="left"><a href="https://www.linkedin.com/company/jba-risk-management/" id="gmail-m_-3272004911288444094LPlnk689713" style="text-decoration:none" target="_blank"><img src="cid:17e771eef00f2ea0beb3" title="LinkedIn" alt="LinkedIn" style="width: 34px; min-width: 34px; max-width: 34px; font-size: 12px;" width="34" border="0"></a></td></tr></tbody></table></td><td style="vertical-align:top" align="left"><table style="font-size:0px;line-height:normal" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:0px 4px 5px 0px;vertical-align:top" align="left"><a href="https://twitter.com/JBARisk" id="gmail-m_-3272004911288444094LPlnk689713" style="text-decoration:none" target="_blank"><img src="cid:17e771eef003a2da8f64" title="Twitter" alt="Twitter" style="width: 34px; min-width: 34px; max-width: 34px; font-size: 12px;" width="34" border="0"></a></td></tr></tbody></table></td><td style="vertical-align:top" align="left"><table style="font-size:0px;line-height:normal" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:0px 4px 5px 0px;vertical-align:top" align="left"><a href="https://www.youtube.com/channel/UC0iatom2jYbW96voW0rlpCw" id="gmail-m_-3272004911288444094LPlnk689713" style="text-decoration:none" target="_blank"><img src="cid:17e771eef0125934cdc5" title="YouTube" alt="YouTube" style="width: 34px; min-width: 34px; max-width: 34px; font-size: 12px;" width="34" border="0"></a></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td><td style="padding:0px"> </td></tr><tr style="font-size:0px"><td style="padding:0px"> </td></tr><tr style="font-size:0px"><td style="padding:0px"> </td></tr></tbody></table></td></tr></tbody></table></td></tr><tr style="font-size:0px"><td style="vertical-align:top" align="left"><table style="font-size:0px" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:0px"><td style="padding:7px 0px 5px;border-color:rgb(74,74,73) currentcolor currentcolor;border-style:solid none none;border-width:1px medium medium;vertical-align:top" align="left"><table style="white-space:normal;color:rgb(68,68,68);font-size:14.67px;font-family:Calibri,Arial,sans-serif;font-weight:400;font-style:normal;text-align:left;line-height:12px" cellspacing="0" cellpadding="0" border="0"><tbody><tr style="font-size:9px"><td style="font-family:Arial"><span style="background-color:rgb(255,255,255)">All JBA Risk Management's email messages contain confidential information and are intended only for the individual(s) named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.</span><br><span style="background-color:rgb(255,255,255)">Please notify the sender immediately by email if you have received this email by mistake and delete this email from your system.</span> <br><span style="background-color:rgb(255,255,255)">JBA Risk Management Limited is registered in England, company number 07732946, 1 Broughton Park, Old Lane North, Broughton, Skipton, North Yorkshire, BD23 3FD, England</span><span style="color:rgb(0,0,1)">.</span><br></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></div></div>

_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">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/mailman/listinfo/gdal-dev</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Ian Turton<br></div>