[gdal-dev] Faster alternative to GetFeatureCount?

Jon Morris Jon.Morris at jbarisk.com
Thu Jan 20 01:00:27 PST 2022


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.Morris at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220120/473d64e1/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image918956.png
Type: image/png
Size: 9886 bytes
Desc: image918956.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220120/473d64e1/attachment-0005.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image215268.png
Type: image/png
Size: 651 bytes
Desc: image215268.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220120/473d64e1/attachment-0006.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image706640.png
Type: image/png
Size: 715 bytes
Desc: image706640.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220120/473d64e1/attachment-0007.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image011385.png
Type: image/png
Size: 966 bytes
Desc: image011385.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220120/473d64e1/attachment-0008.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image866509.png
Type: image/png
Size: 784 bytes
Desc: image866509.png
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220120/473d64e1/attachment-0009.png>


More information about the gdal-dev mailing list