Use SQL Query Syntax with ogrinfo
Use a SQL-style -where clause option to return only the features that meet the expression. In this case, only return the populated places features that meet the criteria of having NAME = ’Shanghai’:
$ ogrinfo 10m_cultural ne_10m_populated_places -where "NAME = 'Shanghai'" ... Feature Count: 1 Extent: (-179.589979, -89.982894) - (179.383304, 82.483323) ... OGRFeature(ne_10m_populated_places):6282 SCALERANK (Integer) = 1 NATSCALE (Integer) = 300 LABELRANK (Integer) = 1 FEATURECLA (String) = Admin-1 capital NAME (String) = Shanghai ... CITYALT (String) = (null) popDiff (Integer) = 1 popPerc (Real) = 1.00000000000 ls_gross (Integer) = 0 POINT (121.434558819820154 31.218398311228327)
Building on the above, you can also query across all available layers, using the -al option and removing the specific layer name. Keep the same -where syntax and it will try to use it on each layer. In cases where a layer does not have the specific attribute, it will tell you, but will continue to process the other layers:
ERROR 1: 'NAME' not recognised as an available field.
NOTE: More recent versions of ogrinfo appear to not support this and will likely give FAILURE messages instead.
Geospatial Power Tools is 350 pages long – 100 of those pages cover these kinds of workflow topic examples. Each copy includes a complete (edited!) set of the GDAL/OGR command line documentation as well as the following topics/examples:
Workflow Table of Contents
- Report Raster Information – gdalinfo 23
- Web Services – Retrieving Rasters (WMS) 29
- Report Vector Information – ogrinfo 35
- Web Services – Retrieving Vectors (WFS) 45
- Translate Rasters – gdal_translate 49
- Translate Vectors – ogr2ogr 63
- Transform Rasters – gdalwarp 71
- Create Raster Overviews – gdaladdo 75
- Create Tile Map Structure – gdal2tiles 79
- MapServer Raster Tileindex – gdaltindex 85
- MapServer Vector Tileindex – ogrtindex 89
- Virtual Raster Format – gdalbuildvrt 93
- Virtual Vector Format – ogr2vrt 97
- Raster Mosaics – gdal_merge 107