Geographic Object Library

From OpenStreetMap Wiki
Jump to navigation Jump to search

Geographic Object Library (GOL) is a file format for OpenStreetMap data. It is used by GeoDesk, an open-source toolkit for processing OSM data in Python and Java.

GOLs contain indexes to enable fast queries, yet require significantly less storage than a traditional database. Uncompressed GOLs are about 20% to 50% larger than the same data in OSM-PBF format, while compressed GOLs are similar in size (and often smaller).

Generating GOLs

GOLs can be created from any OSM-PBF file using the GeoDesk GOL Tool (Documentation).

The following command turns the country extract for France into fr.gol:

gol build fr france-latest.osm.pbf

A 64-bit system with at least 8 GB of RAM is required, and an SSD is highly recommended.

Working with GOLs

The GOL command-line tool can be used to perform basic queries and export results in various formats. For example, to retrieve all soccer fields and save them as GeoJSON:

gol query fr a[leisure=pitch][sport=soccer] -f=geojson > soccer-fields.geojson

The GeoDesk open-source toolkit provides a full range of geospatial operations, as well as integration with other GIS libraries:

Examples

This Python script retrieves all museums in Paris and lists the metro stops within 500 meters:

import geodesk

world = geodesk.Features("fr.gol")
paris = world("a[boundary=administrative][admin_level=8][name=Paris]").one
museums = world("na[tourism=museum]")
stations = world("n[railway=station]")

for museum in museums(paris):
    print(f"{museum.name}")
    for station in stations.around(museum, meters=500):
        print(f"- {station.name}")

This script displays a map and highlights all railway bridges that cross the Danube river in Bavaria:

import geodesk

germany = geodesk.Features("de.gol")
bavaria = germany(
    "a[boundary=administrative][admin_level=4][name:en=Bavaria]").one
danube = germany("r[waterway=river][name:en=Danube]").one
rail_bridges = germany("w[railway][bridge]")
rail_bridges(bavaria).crosses(danube).map("rail-crossings", 
    color="red", weight=8, opacity=0.5).show()

This script reports the 10 most common collection times for post boxes:

import geodesk
from collections import Counter

world = geodesk.Features('world.gol')
post_boxes = world("na[amenity=post_box]")
count = Counter([box.collection_times for box in post_boxes])
most_common = count.most_common(10)
for collection_times, occurrences in most_common:
    print(f"{occurrences:>10} : {collection_times}")

This script retrieves all counties of a given U.S. state (whose name is supplied as a command-line argument), displays them on a map, and also exports their boundaries as GeoJSON:

import geodesk
import sys

usa = geodesk.Features('usa.gol')
state_name = sys.argv[1]   # first command-line argument (e.g. "California")
file_name = state_name.lower().replace(' ', '-') + "-counties"
state = usa(
    f"a[boundary=administrative][admin_level=4][name='{state_name}']").one
counties = usa("a[boundary=administrative][admin_level=6]").within(state)
counties.map(file_name, tooltip="{name}").show()
counties.geojson.save(file_name)   # creates "<state_name>-counties.geojson"