This python3 script uses OGR (you can run it from OSGeo4W Shell), to count all features of shapefiles in the current directory, sum the total, and give an average
✓ Published0🌍 Public
Aandrewbt
Last edited Jan 14, 2021
Created on Jan 14, 2021
This script calculates aggregate statistics for shapefiles in the current directory, reporting the total feature count and the average per file. It walks the directory tree using Python’s `os.walk`, opens each `.shp` file with OGR’s `ogr.Open`, and retrieves feature counts via `layer.GetFeatureCount()`. Results are accumulated in a list, then summed and divided by the number of files to produce the final average. The output prints each shapefile’s name and count, followed by the sum and average, using only the `os` and `osgeo.ogr` libraries.
AI-generated description