Coder Social home page Coder Social logo

vouillon / osm Goto Github PK

View Code? Open in Web Editor NEW
17.0 7.0 3.0 6.97 MB

Experiments with the OpenStreetMap database : map rendering, routing, ...

License: Other

Makefile 0.38% OCaml 55.43% C 4.85% Java 10.64% HTML 0.04% Standard ML 2.64% JavaScript 26.01%

osm's Introduction

Map display

Installation

This software only works on 64-bit machines. The following external libraries are needed: camlzip, cairo2-gtk. They can be install through opam:

   opam install camlzip cairo2-gtk

To compile, just type make.

Usage

At the moment, we provide a tool display that displays a map and can be used to compute shortest paths on this map. A number of tools need to be run first to build the data used by display. All these tools should scale to the whole world, except for the routing preprocessor which currently requires a huge amount of memory (~ 100 GB?) in this case. The France data can be processed on a 8 GB machine.

Loading a PBF file

The load tool will load a PBF file into the database:

./load ile-de-france-latest.osm.pbf

PBF files can be found for instance at this address: http://download.geofabrik.de/europe/france.html

The data is written to the base, source and string subdirectories of a database (currently hardcoded to /tmp/osm). (See the database section for more details on the structure of the database.)

The base directory contains the following tables:

  Nodes
    node/id                    The node id in the OpenStreetMap database
    node/lat                   Node latitude
    node/lon                   Node longitude
  Node tags
    node_assoc/idx             Index of the node in the node table
    node_assoc/key             Key (string)
    node_assoc/val             Value (string)
  Ways
    way/id                     The way id in the OpenStreetMap database
  Way tags
    way_assoc/idx              Index of the way in the way table
    way_assoc/key              Key (string)
    way_assoc/val              Value (string)
  Way nodes
    way_refs/way               Index of the way in the way table
    way_refs/node              Index of the node in the node table
  Relations
    relation/id                The relation id in the OpenStreetMap database
  Relation tags
    relation_assoc/idx         Index of the relation in the relation table
    relation_assoc/key         Key (string)
    relation_assoc/val         Value (string)
  Relation members
    relation_members/relation  Index of the relation in the relation table
    relation_members/type      Type of the member (0: node, 1: way, 2:relation)
    relation_members/member    Index of the member in the appropriate table
    relation_members/role      Role of the member (string)

The string directory contains a string dictionary associating a unique integer to each string.

Querying the database

The tool query can be used to access the contents of this database:

  • Without argument, it will list all columns.
  • Given a subdirectory of the database, it will list the columns in this directory:
./query base
  • Given a list of columns, it will output the contents of these columns:
./query base/node/{id,lat,lon}
  • The --string option tells the tool to resolve and output the strings contained in the subsequent columns, using the string dictionary:
./query base/node_assoc/idx --string base/node_assoc/{key,val}

(The --num option swithes back to outputing integers.)

  • The --index i option can be used to read this one line of table. For instance, this returns the OSM id of the node at index 1234:
./query base/node/id --index 1234

Preprocessing

The five following operations need to be performed before being able to display the map:

  • extract multipolygons: ./multipolygons
  • build surface R-trees: ./surfaces
  • build R-trees of linear features: ./linear
  • build the routing graph: ./highway
  • preprocess the routing graph: ./contraction (we use so-called contraction hierarchies to speed-up route searches)

Optionally, you can include the coastline data:

./coastline /path/to/coastlines-split-4326.zip

Map display

The command display displays the map. One can pan the map with the mouse and zoom using the mouse wheel. The start and destination of a route can be set by clicking respectively with the left and right mouse button.

Database

We make heavy use of a specialized database engine for data storage and processing.

Currently, the database path is hardcoded as /tmp/osm

Data is stored using three possible formats:

  • columns of 63-bit integers
  • string dictionaries
  • R-trees

Columns

Columns contain 63-bit integers.

Columns are compressed by performing a delta encoding and using a variable-length encoding. This considerably reduces the disk memory usage and speeds up I/Os.

A number of operations are implemented to process columns in an efficient manner: one can read sequentially the contents of a column, sort two columns according to the first column, perform a join between two pairs of columns, ...

Random access is possible, but should be avoided when possible, as it is slow.

String dictionaries

A string dictionnary associates a unique positive integer to each string. Strings can thus be compared by their id, without lookup. A two-way mapping between strings and their identifier is provided.

At the moment, we use a single dictionnary, stored in the strings directory.

R-tree

An R-tree is a kind of extension of B-trees to multidimensional objects. Each node in the tree holds the bounding box of its children. Hence, given a rectangle, one can efficiently find all leaves whose bounding box intersects with the rectangle.

R-trees are stored as a directories containing files 0, 1, ..., n. Files 1 to n contain nodes and are managed by the database. The contents of the leaf file 0 is free: when performing a request, we will get a list of leaf pages and it is our job to decode these pages. Page overflows (chunk of data that spans several pages) are possible, by reporting an empty bounding boxe for overflow pages.

In order to build a R-tree, we sort the data according to there position on the Hilbert curve (which ensure good locality properties) and then insert them sequentially in the R-tree. (http://en.wikipedia.org/wiki/Hilbert_R-tree)

osm's People

Contributors

kit-ty-kate avatar vouillon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

osm's Issues

Index out of bound when trying to display a map

I tried to launch osm like:

$ ./load ~/Downloads/ile-de-france-latest.osm.pbf
$ ./multipolygons && ./surfaces && ./linear && ./highway && ./contraction
$ ./display
[48020077 49276423 1393187 3576257] 48850000 2350000
218779 -5232859
Loading surfaces: 0.006
Loading lines: 0.010
Loading coastline: 0.000
Surfaces: 36 / lines: 12
Sorting surfaces (891 elements): 0.002
Sorting lines (90 elements): 0.000
Surfaces: 13667 nodes
Surfaces: 13667 nodes, 891 elements (100.00%)
Lines: 2322 nodes
Drawing surfaces: 0.069
Drawing lines: 0.045
Redraw: 0.133294
Loading surfaces: 0.007
Loading lines: 0.011
Loading coastline: 0.000
Surfaces: 68 / lines: 22
Sorting surfaces (1769 elements): 0.005
Sorting lines (159 elements): 0.000
Surfaces: 26193 nodes
Surfaces: 26193 nodes, 1769 elements (100.00%)
Lines: 4222 nodes
Drawing surfaces: 0.266
In callback for signal expose_event, uncaught exception: Invalid_argument("index out of bounds")
Raised by primitive operation at file "osm/line_smoothing.ml", line 119, characters 21-26
Called from file "osm/line_smoothing.ml", line 175, characters 2-32
Called from file "osm/display.ml", line 781, characters 18-44
Called from file "list.ml", line 73, characters 12-15
Called from file "osm/category.ml", line 265, characters 8-34
Called from file "osm/display.ml", line 765, characters 2-1023
Called from file "osm/category.ml", line 253, characters 16-68
Called from file "osm/display.ml", line 68, characters 15-18
Called from file "osm/display.ml", line 1904, characters 9-43

But I got this instead of the map. If I comment the line 119 and 120, the map is displayed, but it's really slow and the lines are not well displayed (not usable).

map_file /dev/zero on OSX

Fatal error: exception Sys_error("Operation not supported by device")
Raised by primitive operation at file "bigarray.ml", line 99, characters 4-47
Called from file "generic/task.ml", line 116, characters 6-87
Called from file "osm/parser.ml", line 454, characters 14-50
Called from file "osm/parser.ml", line 502, characters 2-19

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.