gol query
Outputs all features that match the given query to stdout
, in a variety of formats. If no query is provided, enters interactive mode, which enables more sophisticated access to the GOL’s features.
Usage:
gol query <gol-file> [<query>] [<options>]
Any query must be written in GOQL, the Geo-Object Query Language. GOQL is similar to MapCSS, which is used by Mapnik and Overpass to select OSM objects.
For example:
gol query geodata/france \
na[amenity=fire_station], n[emergency=fire_hydrant] \
-b 2.2,48.8,2.5,48.9 -f geojson
retrieves all fire stations (which can be nodes or areas) and hydrants (which only exist as nodes) from the france.gol
library (stored in the geodata
folder). The features must lie fully or partially inside the specified bounding box (a rectangle that covers metropolitan Paris) and are printed to stdout
as GeoJSON (see below).
Interactive mode
Interactive mode supports complex queries using GeoDesk for Python.
You will need to install Python. On Windows, required Python modules are downloaded automatically; on Linux and macOS, install them manually via
pip install geodesk2
.
For example:
gol query france
begins interactive mode using france.gol
.
Let’s retrieve the administrative area of Paris:
>>> paris = france("a[boundary=administrative][admin_level=6][name=Paris]").one
We can query its tags like this:
>>> paris.population
2165423
>>> paris["name:it"]
'Parigi'
Now, we’ll get all named main roads in Paris and count them:
>>> streets = france("w[highway=primary][name]")(paris)
>>> streets.count
27525
Next, we’ll get their unique names, sorted alphabetically:
>>> sorted({s.name for s in streets})
['Allée de Longchamp', "Allée du Bord de l'Eau", 'Avenue Aristide Briand', ... ]
Let’s compute their combined length (in meters):
>>> round(streets.length)
235472
Finally, we’ll display them on a map:
>>> streets.map.show()
When you’re done, press Ctrl-Z
followed by Enter
to return to the shell.
Options
-a
, --area
<COORDS>
| <FILE>
Defines the (multi)polygon area to which the command should be applied. The following coordinate formats are supported:
GeoJSON
WKT
Raw coordinates in the form
lon_0, lat_0, ... , lon_n, lat_n
. To specify multiple polygons, or a polygon with one or more “holes,” place each ring in parentheses. Rings do not need to be closed.
You can specify coordinate values directly, or via a file.
-b
, --bbox
<W>,<S>,<E>,<N>
Defines the rectangular area (bounding box) to which the command should be applied. Coordinates are specified in WGS-84 (degrees longitude and latitude) and take the form <west>,<south>,<east>,<north>
. Coordinates must not be separated by spaces (otherwise, they would be interpreted as separate arguments).
As an alternative, this option accepts a tile descriptor in the form z/x/y
.
-f
, --format
<TYPE>
The output format of the results:
brief | Prints a per-feature overview (default) |
count | Prints only the number of features. |
csv | Comma-separated values |
geojson / geojsonl | GeoJSON (traditional / one feature per line) |
list | Simple list of IDs |
table | Simple text-based table |
wkt | Well-known text (geometries only) |
xml | OSM-XML |
-k
, --keys
<LIST>
A comma-separated list of OSM keys, which determine the feature tags to be included in the output.
There are several special keys that only apply to the csv
output option and produce additional columns:
bbox | The bounding-box coordinates of the feature (West, South, East, North). For --format=geojson , this becomes the bbox member of the Feature object. |
geom | The geometry of the feature (as well-known text). Only applies to --format=csv . |
lat | The WGS-84 latitude of the feature's centroid |
lon | The WGS-84 longitude of the feature's centroid |
tags (or * ) | A comma-separated list of key-value pairs, representing the keys of the tags that are not already printed in a column of their own. |
If --keys
is omitted, all tags are included in the output.
--keys
is ignored for the count
and list
formats.
-p
, --precision
<NUMBER>
Value: 0 – 15 (default: 7)
The coordinate precision (digits after the decimal point).
Applies only to csv
, geojson
/geojsonl
and wkt
.
-q
, --quiet
Displays only minimal output. Apart from error messages, only minimal progress updates are written to stderr
.
-s
, --silent
No output at all is written to stderr
, not even error messages. (Whether a command succeeded or failed can only be ascertained via the status code returned by the process).
-v
, --verbose
Writes extra information to stderr
.