Planetiler (pla·nuh·tai·lr, formerly named "Flatmap") is a tool that generates Vector Tiles from geographic data sources like OpenStreetMap.
 
 
Go to file
Mike Barry 39b7eca2a1 CI and docs 2021-10-19 21:57:47 -04:00
.github CI and docs 2021-10-19 21:57:47 -04:00
.idea CI and docs 2021-10-19 21:57:47 -04:00
.mvn/wrapper CI and docs 2021-10-19 21:57:47 -04:00
diagrams CI and docs 2021-10-19 21:57:47 -04:00
flatmap-basemap CI and docs 2021-10-19 21:57:47 -04:00
flatmap-benchmarks CI and docs 2021-10-19 21:57:47 -04:00
flatmap-core CI and docs 2021-10-19 21:57:47 -04:00
flatmap-dist CI and docs 2021-10-19 21:57:47 -04:00
flatmap-examples CI and docs 2021-10-19 21:57:47 -04:00
planet-logs CI and docs 2021-10-19 21:57:47 -04:00
scripts CI and docs 2021-10-19 21:57:47 -04:00
.editorconfig initial commit 2021-04-05 20:33:54 -04:00
.gitignore CI and docs 2021-10-19 21:57:47 -04:00
ARCHITECTURE.md CI and docs 2021-10-19 21:57:47 -04:00
CONTRIBUTING.md CI and docs 2021-10-19 21:57:47 -04:00
LICENSE apache 2.0 license 2021-09-21 06:43:49 -04:00
NOTICE.md CI and docs 2021-10-19 21:57:47 -04:00
PLANET.md CI and docs 2021-10-19 21:57:47 -04:00
README.md CI and docs 2021-10-19 21:57:47 -04:00
config-example.properties CI and docs 2021-10-19 21:57:47 -04:00
grafana.json comments and cleanup 2021-09-09 20:46:20 -04:00
mvnw CI and docs 2021-10-19 21:57:47 -04:00
mvnw.cmd CI and docs 2021-10-19 21:57:47 -04:00
pom.xml CI and docs 2021-10-19 21:57:47 -04:00
quickstart-from-source.sh CI and docs 2021-10-19 21:57:47 -04:00

README.md

Flatmap

Flatmap is a tool that generates Mapbox Vector Tiles from geographic data sources like OpenStreetMap. Flatmap aims to be fast and memory-efficient so that you can build a map of the world in a few hours on a single machine without any external tools or database.

Vector tiles contain raw point, line, and polygon geometries that clients like MapLibre can use to render custom maps in the browser, native apps, or on a server. Flatmap packages tiles into an MBTiles (sqlite) file that can be served using tools like TileServer GL or even queried directly from the browser. See awesome-vector-tiles for more projects that work with data in this format.

Flatmap is named after the "flatmap" operation that it performs: map input elements to rendered tile features, flatten them into a big list, and sort by tile ID to group into tiles. The output is also a "flat map" where zoom level 0 contains the entire planet in a 256x256 px tile, and each zoom level splits parent tiles into 4 quadrants, revealing more detail.

See ARCHITECTURE.md for more details on how Flatmap works.

Demo

See the live demo of vector tiles created by Flatmap.

Flatmap Demo Screenshot Style © OpenMapTiles · Data © OpenStreetMap contributors

Usage

To generate a map of an area using the basemap profile, you will need:

  • Java 16+ or Docker
  • at least 1GB of free disk space plus 5-10x the size of the .osm.pbf file
  • at least 1.5x as much free RAM as the input .osm.pbf file size

To build the map:

Using Java, download flatmap.jar from the latest release and run it:

wget https://github.com/onthegomap/flatmap/releases/latest/download/flatmap.jar
java -Xmx1g -jar flatmap.jar --download --area=monaco

Or using Docker:

docker run -e JAVA_TOOL_OPTIONS="-Xmx1g" -v "$(pwd)/data":/data ghcr.io/onthegomap/flatmap:latest --download --area=monaco

To view tiles locally:

Using Node.js:

npm install -g tileserver-gl-light
tileserver-gl-light --mbtiles data/output.mbtiles

Or using Docker:

docker run --rm -it -v "$(pwd)/data":/data -p 8080:8080 maptiler/tileserver-gl -p 8080

Then open http://localhost:8080 to view tiles.

Some common arguments:

  • --download downloads input sources automatically and --only-download exits after downloading
  • --area=monaco downloads a .osm.pbf extract from Geofabrik
  • --osm-path=path/to/file.osm.pbf points Flatmap at an existing OSM extract on disk
  • -Xmx1g controls how much RAM to give the JVM (recommended: 0.5x the input .osm.pbf file size to leave room for memory-mapped files)
  • --force overwrites the output file
  • --help shows all of the options and exits

Generating a Map of the World

See PLANET.md.

Creating a Custom Map

See the flatmap-examples project.

Benchmarks

Some example runtimes (excluding downloading resources):

Input Input Size Profile Machine Time mbtiles size Logs
s3://osm-pds/2021/planet-211011.osm.pbf 64.7GB Basemap DO 16cpu 128GB RAM 3h9m (cpu: 42h1m @ 13.3) 99.6GB logs VisualVM Profile
Daylight Distribution v1.6 with ML buildings and admin boundaries 68.6GB Basemap DO 16cpu 128GB RAM 3h13m (cpu: 43h40m @ 13.5) 101.4GB logs
s3://osm-pds/2021/planet-211011.osm.pbf 64.7GB Basemap (without z13 building merge) c5ad.16xlarge (64cpu/128GB RAM) 59m26s (cpu: 27h6m @ 27.4) 97.3GB logs

Alternatives

Some other tools that generate vector tiles from OpenStreetMap data:

  • OpenMapTiles is the reference implementation of the OpenMapTiles schema that the basemap profile is based on. It uses an intermediate postgres database and operates in two modes:
    1. Import data into database (~1 day) then serve vector tiles directly from the database. Tile serving is slower and requires bigger machines, but lets you easily incorporate realtime updates
    2. Import data into database (~1 day) then prerender every tile for the planet into an mbtiles file which takes over 100 days or a cluster of machines, but then tiles can be served faster on smaller machines
  • Tilemaker uses a similar approach to Flatmap (no intermediate database), is more mature, and has a convenient lua API for building custom profiles without recompiling the tool, but takes about a day to generate a map of the world

Some companies that generate and host tiles for you:

If you want to host tiles yourself but have someone else generate them for you, those companies also offer plans to download regularly-updated tilesets.

Features

  • Supports Natural Earth, OpenStreetMap .osm.pbf, and Esri Shapefiles data sources
  • Java-based Profile API to customize how source elements map to vector tile features, and post-process generated tiles using JTS geometry utilities
  • Automatically fixes self-intersecting polygons
  • Built-in basemap profile based on OpenMapTiles v3.12.2
  • Optionally download additional name translations for elements from Wikidata
  • Export real-time stats to a prometheus push gateway using --pushgateway=http://user:password@ip argument (and a grafana dashboard for viewing)
  • Automatically downloads region extracts from Geofabrik using geofabrik:australia shortcut as a source URL
  • Unit-test profiles to verify mapping logic, or integration-test to verify the actual contents of a generated mbtiles file (example)

Limitations

  • It is harder to join and group data than when using database. To join input data sources, profiles must explicitly store data when processing a feature to use with later features, or apply post-processing to rendered features immediately before emitting the vector tile.
  • Flatmap only does full imports from .osm.pbf snapshots, there is no way to incorporate real-time updates.

Roadmap

  • Enough flatmap-core functionality to support basemap profile based on OpenMapTiles
  • Basemap profile based on OpenMapTiles v3.12.2
    • Port all layers
    • Download name translations from wikidata
    • Merge buildings at z13
    • adm0_l/adm0_r boundary labels
    • Abbreviate road names to improve visibility
    • Poi layer agg_stop tag
  • Get flatmap-core into Maven Central
  • Remove geotools dependency for reading shapefiles (not in Maven Central)
  • Remove graphhopper dependency for reading OSM files
  • "Sparse mode" to only store node and relation data for elements used by a profile
  • Support zoom levels higher than 14
  • Handle nodes and relations in relations (only ways handled now)
  • Lake centerline support in flatmap-core
  • Improve line merging to combine nearby parallel roads
  • Basemap schema improvements for onthegomap.com
  • Accept other kinds of data sources
  • Extract reusable utilities for complex schemas from flatmap-basemap to flatmap-core
  • Other schemas

Contributing

Pull requests are welcome! See CONTRIBUTING.md for details.

Support

Have a question or want to share something you've built? Start a GitHub discussion.

Found a bug or have a feature request? Open a GitHub issue to report.

This is a side project, so support is limited. If you have the time and ability, feel free to open a pull request to fix issues or implement new features.

Acknowledgement

Flatmap is made possible by these awesome open source projects:

See NOTICE.md for a full list and license details.

Author

Flatmap was created by Michael Barry for future use generating custom basemaps or overlays for On The Go Map.

License and Attribution

Flatmap source code is licensed under the Apache 2.0 License, so it can be used and modified in commercial or other open source projects according to the license guidelines.

Maps built using flatmap do not require any special attribution, but the data or schema used might. Any maps generated from OpenStreetMap data must visibly credit OpenStreetMap contributors. Any map generated with the profile based on OpenMapTiles or a derivative must visibly credit OpenMapTiles as well.