Skip to content

osmcode/osm-area-tools

Repository files navigation

OSM Area Tools

OpenStreetMap doesn't have anything like an Area, Polygon or MultiPolygon basic data type. Instead, areas are modelled as closed ways or using a relation tagged with type=multipolygon or type=boundary. This makes the data hard to edit and use, but it is the way it is.

This repository contains several programs based on the libosmium library that help with understanding what areas there are in OSM by creating statistics or other information from the OSM data. Some programs assemble areas from the nodes, ways, and relations.

The programs in this repository are not meant to be used by end users, they are for developers or mappers who want to understand what's in the OSM data and maybe fix (some of) it.

Naming Conventions

Osmium/OSM Area Tools uses the following naming conventions:

  • Area: A Polygon or MultiPolygon with tags created from a closed way or an Area Relation.
  • Area Relation: Any kind of relation that can be turned into an area, a Multipolygon Relation or a Boundary Relation.
  • Multipolygon Relation: A relation tagged type=multipolygon.
  • Boundary Relation: A relation tagged type=boundary.
  • Assembling: The process of creating an Area from the basic OSM objects.
  • Polygon: A type of geometry (as defined by the Simple Feature Definition) with one outer ring and zero or more inner rings.
  • MultiPolygon: A collection of polygons (with one or more outer rings and zero or more inner rings).

Programs

Build Status

oat_closed_way_filter

Copy only closed ways from input file to output file.

oat_complex_areas

Find all "simple" and "complex" areas and write their IDs to the output files. Complex areas are those where the boundary meets itself somewhere, i.e. they have a node more than once in the boundary. Simple areas are all others.

oat_create_areas

Assembles areas from their parts and optionally checks them for validity. Can write the areas to a Spatialite database including all the problems encountered on the way.

oat_failed_area_tags

Creates areas but only looks at those areas which could not be built due to geometry problems. Creates some tag statistics on stdout.

oat_find_problems

Find problematic data with respect to area creation. This program does not try to actually build the areas, it just looks at the data and flags some obvious problems.

oat_large_areas

Look at the largest area relations in the input OSM file in terms of the number of ways or nodes they contain. Creates a Sqlite database with information about those relations and an OSM file containing those relations.

oat_mercator

Assembles areas from their parts, projects them to Mercator (3857) and checks them for validity. Can write the areas to a Spatialite database including all the problems encountered on the way.

oat_problem_report

Create areas and report all problems encountered into shapefiles. The areas themselves are not kept.

oat_sizes

Prints sizes of some C++ structures used in assembling areas from their parts. This is only interesting for C++ developers optimizing the code.

oat_stats

Create some statistics from an OSM file related to areas. This program will not actually assemble the areas, just look at the objects potentially making up the areas. The results are stored in an Sqlite database.

Prerequisites

You need a C++11 compliant compiler. GCC 4.8 and later as well as clang 3.4 and later are known to work. You also need the following libraries:

Osmium Library
    Need at least version 2.15.4
    https://osmcode.org/libosmium

Protozero
    Need at least version 1.6.3
    https://github.com/mapbox/protozero
    Debian/Ubuntu: libprotozero-dev

gdalcpp
    https://github.com/joto/gdalcpp
    Also included in the libosmium repository.

bz2lib (for reading and writing bzipped files)
    http://www.bzip.org/
    Debian/Ubuntu: libbz2-dev

CMake (for building)
    https://cmake.org/
    Debian/Ubuntu: cmake

Expat (for parsing XML files)
    https://libexpat.github.io/
    Debian/Ubuntu: libexpat1-dev
    openSUSE: libexpat-devel

GDAL/OGR
    https://gdal.org/
    Debian/Ubuntu: libgdal-dev

GEOS
    https://trac.osgeo.org/geos/
    Debian/Ubuntu: libgeos++-dev

Sqlite
    https://sqlite.org/
    Debian/Ubuntu: libsqlite3-dev

zlib (for PBF support)
    https://www.zlib.net/
    Debian/Ubuntu: zlib1g-dev
    openSUSE: zlib-devel

Building

Build like any CMake program by creating a build directory and running cmake and then make as follows:

mkdir build
cd build
cmake ..
make

To set the build type call cmake with -DCMAKE_BUILD_TYPE=type. Possible values are empty, Debug, Release, RelWithDebInfo, MinSizeRel, and Dev. The defaults is RelWithDebInfo.

License

Copyright (C) 2016-2021 Jochen Topf [email protected]

This program is available under the GNU GENERAL PUBLIC LICENSE Version 3. See the file LICENSE.txt for the complete text of the license.

Authors

This program was written and is maintained by Jochen Topf [email protected].