osm4j

osm4j is a Java library for working with OpenStreetMap data. Our first attempts of using OSM data on the Java platform were based on Osmosis. The callback-driven style of programming didn't feel very comfortable however, so that we decided to write our own abstraction layer.

Our library provides abstract data types for representing OSM data and iterative input and output handlers for various common file formats. In addition, callback-based handlers are also available so that programs written in this style can easily be ported.

It also provides support for processing and manipulating the geometry of OSM objects by providing bindings to the data structures from JTS.

Package overview

The library consists of a few modules that package related functionality, so that you can easily select just those components that you need:

osm4j-core

osm4j-xml

osm4j-pbf

osm4j-tbo

osm4j-geometry

osm4j-utils

osm4j-core

osm4j provides the basic interfaces and data types for representing objects from the OpenStreetMap. Additionally, it provides common interfaces and data handlers for reading OSM data as well as some useful utility methods that make some basics operations on the data easy to accomplish.

osm4j-pbf

osm4j-pbf provides the tools for working with the very widely used PBF file format for OSM data that is based on Google's Protocol Buffers.

osm4j-tbo

osm4j-tbo can be used to read and write our own binary OSM file format. The file format is very similar to PBF, but is not based on Protocol Buffers. It has been designed to offer similar compression while offering enhanced access methods and to allow for improved I/O performance.

osm4j-geometry

osm4j-geometry is a package for making it easy to perform geometric operations with OpenStreetMap data. It contains utilities for converting the basic types of elements defined in the OSM data model to their geoemtric representations. It uses the JTS Topology Suite to represent geometric objects, which allows you to apply a number of typical GIS operations to your data.

OSM nodes can be converted to JTS Coordinates or Points

OSM ways can be converted to JTS LineStrings, LinearRings or Polygons

OSM relations can be converted to JTS MultiPolygons

osm4j-utils

osm4j-utils is a collection of command line tools for performing recurring tasks on OSM data such as conversion between different file formats. It also provides some tools for data analyis.

The classes of this package can also be used as helpful utilities when implementing custom data manipulation tasks.

Installation

Maven / Gradle

All packages are available through a public Maven repository. Add the following repositories to your build.gradle file: