OWL/Hacking

From OpenStreetMap Wiki
< OWL
Jump to navigation Jump to search

Components

Database

  • Stores core OSM data (nodes, ways, relations, changeset metadata) as well as OWL-specific data (changes, tiles).
  • Uses PostGIS extension for handling spatial types.
  • SQL scripts can be found in the sql directory.

Osmosis plugin

  • Used for populating the database with data and also for processing OSC files (e.g. during replication).
  • Fork of the Osmosis source code including the plugin code can be found in the osmosis directory.

Tiler

  • Generates changes and tiles based on the core OSM data.
  • Ruby code can be found in the tiler directory.
  • Wrapper script to start the tiling process with different parameters is scripts/tiler.rb.

API

  • Ruby on Rails web application communicating with the OWL database and exposing a simple HTTP API for OWL clients.
  • It can output data in various formats (JSON, GeoJSON, RSS/ATOM).
  • Directory rails contains the Ruby on Rails API application.

Data

This section describes various data models used in OWL.

Core data
This is the regular OSM data including nodes, ways, relations and relation members. It is stored in a custom OWL schema which is similar to the pgsnapshot schema from Osmosis. Data comes from OSM database dumps and the replication stream.
Changeset metadata
Changeset timestamps (created at, closed at), tags (including the comment), user info. Data comes from the changeset metadata replication stream and weekly dumps.
Changes
Information about what has changed between two versions of an OSM object. It is generated by the OWL tiler component.
Tiles
A tile associates one or more changes with a specific (small) region of the world. Tiles are aggregated by changeset - meaning that if there are many changes in a region that come from the same changeset, they are placed on one tile. Tiles are generated by the OWL tiler component.

Tiling

Creating tiles is the most important process in OWL because they are needed for the tile-based API to work properly - the whole point of OWL is to place changes in OSM data in a spatial context (using tiles).

General

  • Tiles are generated at zoom level 16. This zoom level was chosen as a compromise between the total number of tiles and the real world size of a region that a tile represents.
  • There are no tiles on zoom levels greater than 16.
  • Tiles from zoom level 16 are aggregated to lower zoom levels. Specifically:
    • Tiles at zoom levels 14 and 15 contain full geometry from their respective "child" tiles.
    • Tiles at zoom levels lower than 14 contain only bounding boxes instead of full change geometry.

Code

Main tiler code can be found in the tiler/lib/tiler.rb file. High level overview of a normal tiling process:

  1. Generate changes for given changeset using the OWL_GenerateChanges(changeset_id) PL/pgSQL function and insert them into the changes table.
  2. Go through all the changes; for each change: (all this happens only for zoom level 16)
    1. Take change geometry and create tiles for it. One tile contains only relevant part of the geometry (this is done using GEOS library's intersection call).
    2. Merge all tiles from a change to already previously generated tiles.
  3. Once all changes have been processed, insert all changeset tiles into the tiles table.
  4. Use OWL_AggregateChangeset PL/pgSQL function to derive tiles at lower zoom levels than 16.