Class OsmExtract

java.lang.Object
com.codename1.backend.osm.OsmExtract

public final class OsmExtract extends Object

A road network and a place index built from one OpenStreetMap .osm.pbf extract, shared by OsmRouting and OsmGeocoding.

Everything is read into memory once, at load(String), and is immutable afterwards, so any number of request threads can use one extract. The structures are compact arrays, sized for a city, a region or a small country: Monaco loads in well under a second, and a dense region of a few million road nodes needs a few hundred megabytes of heap. A whole continent is out of scope; cut an extract with osmium extract instead.

The data is OpenStreetMap's, under the Open Database License: an application that answers routes or places from it must credit "OpenStreetMap contributors" where its users see the results.

  • Method Details

    • load

      public static OsmExtract load(String path) throws IOException
      Reads an extract. Both the router and the geocoder are built from it.
      Parameters:
      path - the .osm.pbf file
      Returns:
      the loaded extract
      Throws:
      IOException - when the file is missing, is not an OSM PBF file, or uses a blob compression other than zlib
    • getRoadVertexCount

      public int getRoadVertexCount()
      The number of road vertices a route can be snapped to.
      Returns:
      the count
    • getPlaceCount

      public int getPlaceCount()
      The number of places and addresses the geocoder can find.
      Returns:
      the count