Hi Ian, That's more or less what I was doing, calling GetNextFeature twice. I figured GetFeatureCount would be doing that under the hood anyway, but it didn't seem to run any faster.
Jon e: jon.mor...@jbarisk.com t: +44 (0)1756 799919 www.jbarisk.com 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. Please notify the sender immediately by email if you have received this email by mistake and delete this email from your system. JBA Risk Management Limited is registered in England, company number 07732946, 1 Broughton Park, Old Lane North, Broughton, Skipton, North Yorkshire, BD23 3FD, England. From: Ian Turton <ijtur...@gmail.com> Sent: 20 January 2022 10:55 To: Jon Morris <jon.mor...@jbarisk.com> Cc: gdal-dev@lists.osgeo.org Subject: Re: [gdal-dev] Faster alternative to GetFeatureCount? CAUTION: This email originated from outside of JBA and contains one or more links and one or more attachments. DO NOT click links or open attachments unless you recognise the sender's email address and are absolutely certain that the content is safe. See the Phishing page on IMS on SP for more information about how to spot and report suspicious messages. 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. Ian On Thu, 20 Jan 2022 at 09:00, Jon Morris <jon.mor...@jbarisk.com<mailto:jon.mor...@jbarisk.com>> wrote: 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. 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. Thanks, Jon Jon Morris Software Developer e: jon.mor...@jbarisk.com<mailto:jon.mor...@jbarisk.com> t: +44 (0)1756 799919<tel:+44%20(0)1756%20799919> www.jbarisk.com<http://www.jbarisk.com/> [cid:image001.png@01D80E16.665C3D20] [Facebook]<https://www.facebook.com/TheFloodPeople> [LinkedIn]<https://www.linkedin.com/company/jba-risk-management/> [Twitter]<https://twitter.com/JBARisk> [YouTube]<https://www.youtube.com/channel/UC0iatom2jYbW96voW0rlpCw> 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. Please notify the sender immediately by email if you have received this email by mistake and delete this email from your system. JBA Risk Management Limited is registered in England, company number 07732946, 1 Broughton Park, Old Lane North, Broughton, Skipton, North Yorkshire, BD23 3FD, England. _______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org<mailto:gdal-dev@lists.osgeo.org> https://lists.osgeo.org/mailman/listinfo/gdal-dev -- Ian Turton
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev