ogrinfo
What is ogrinfo?
ogrinfo is the GDAL/OGR command-line utility for inspecting vector datasets. It lists layers, describes schemas (attribute fields and types), reports feature counts and extents, shows the CRS, and can dump features with their geometry. It handles every OGR-supported format: Shapefile, GeoPackage, GeoJSON, KML, FileGDB, PostGIS, MapInfo, FlatGeobuf, and dozens more.
ogrinfo [options] <datasource_name> [<layer>...]Commonly used options:
-al— report on all layers-so/--summary-only— summary only (no feature dump)-json— machine-readable JSON output-where "<expr>"— restrict to features matching an attribute expression-sql "<statement>"— execute SQL against the data source-dialect <dialect>— SQL dialect (OGRSQL,SQLite,INDIRECT_SQLITE)-spat <xmin> <ymin> <xmax> <ymax>— spatial filter-geom=NO/-geom=SUMMARY— suppress or summarise geometry in feature dump-fid <fid>— show a single feature by FID-ro— open read-only (safer on shared data)-features— list features (default when a layer is named)
When would you use ogrinfo?
Reach for ogrinfo as the first step on any unfamiliar vector delivery. Typical jobs: listing layers inside a GeoPackage (ogrinfo data.gpkg), inspecting schema and feature count of a specific layer (ogrinfo -so data.gpkg roads), running a quick count-by-category via SQL (ogrinfo -sql "SELECT class, COUNT(*) FROM roads GROUP BY class" data.gpkg), or confirming that a PostGIS connection works and exposes expected tables (ogrinfo PG:"dbname=gis" -so).
For ad-hoc SQL reporting, -dialect SQLite on non-SQLite sources gives you the richer SQLite SQL dialect over OGR's simpler native SQL. For pipelines, -json -so produces structured metadata you can consume in downstream scripts. And when debugging a mismatched CRS, ogrinfo on the source typically reveals the issue in seconds.
FAQs
How does ogrinfo differ from gdalinfo?
gdalinfo is for raster datasets; ogrinfo is for vector datasets. Same design philosophy — report everything useful — but different data models. A GeoPackage can hold both rasters and vectors, and each tool reports only its own kind.
How do I query with SQL?
Pass -sql "SELECT ...". The default OGR SQL dialect is simple (basic WHERE, GROUP BY, ORDER BY, joins via virtual tables). Switch to -dialect SQLite for full SQLite SQL including window functions, CTEs, and spatial SQL functions (ST_Area, ST_Intersects) via SpatiaLite. Source drivers that are native SQL (PostgreSQL, MySQL) pass SQL through to the database.
Why is ogrinfo slow on large datasets?
By default it dumps every feature. Pass -so for summary-only, which just reports schema and counts. For extent, -so -al gives per-layer extents without touching individual features. If counting is the bottleneck (some drivers compute it lazily), -sql "SELECT COUNT(*) FROM layer" uses the driver's optimised path when available.
Can ogrinfo write or modify data?
Mostly no — it is primarily a read tool. But there is a -sql mode that can run UPDATE/DELETE statements on writable sources, and modern versions support schema-change SQL. Prefer ogr2ogr or a dedicated editor for real write workflows; ogrinfo write capabilities are easy to misuse.