1 of 27

Workshop:�Using OpenStreetMap Data

Benjamin Herfort, Melanie Eckle,�Marcel Reinmuth

GIScience Research Group

Heidelberg University

disastermappers heidelberg

GeOnG Forum 2016, Chambéry, France

2 of 27

Agenda

  • OSM data on your mobile device (Garmin-GPS, Osmand)
  • Get OSM data: the Overpass-API and overpass-turbo.eu
  • Get the OSM raw data: OpenStreetMap-API
  • OSM data in your database: PostGIS and PostgreSQL

2

GeOnG Forum 2016, Chambéry, France

3 of 27

Agenda

  • OSM data on your mobile device (Garmin-GPS, Osmand)
  • Get OSM data: the Overpass-API and overpass-turbo.eu
  • Get the OSM raw data: OpenStreetMap-API
  • OSM data in your database: PostGIS and PostgreSQL

3

GeOnG Forum 2016, Chambéry, France

4 of 27

OSM data on your mobile device ::�download data via BBBike.org

  1. http://extract.bbbike.org/
  2. Select output file format:
    • Garmin → Garmin OSM
    • Android → Osmand (OBF)
  3. Insert email address
  1. Select area of interest
    • Add points
    • resize or drag polygon
  2. Run export

4

GeOnG Forum 2016, Chambéry, France

5 of 27

OSM data on your mobile device ::�download data via HOT Export Tool

  1. http://export.hotosm.org/de/
  2. Login with your OpenStreetMap Account
  3. „Create“ or use previous „Exports“
  4. Describe your export
  5. Select area of interest

  1. Select output file format:
    • Garmin Map
    • OSMand OBF
  2. Option: Select only specific object types
  3. Run export

5

GeOnG Forum 2016, Chambéry, France

6 of 27

OSM data on your mobile device ::�Insert data to your device

OSMand:

  1. Connect your device with your computer
  2. Search for „.obf“-files on your device
  3. Copy „.obf“-files to the same folder
  4. Open the app and zoom to your area

Garmin:

  1. Connect your device with your computer
  2. Unpack Zip-file
  3. Copy „.img“-file to the Garmin device
  4. Open Garmin map

6

GeOnG Forum 2016, Chambéry, France

7 of 27

Get OSM data

  1. How big is your area of interest?
    1. City level
    2. Regional level
    3. National level
    4. Global level
  1. What objects are important for you?
    1. Everything
    2. Just buildings and streets
    3. Specific objects (e.g. water points, schools)

7

GeOnG Forum 2016, Chambéry, France

8 of 27

Agenda

  • OSM data on your mobile device (Garmin-GPS, Osmand)
  • Get OSM data: the Overpass-API and overpass-turbo.eu
  • Get the OSM raw data: OpenStreetMap-API
  • OSM data in your database: PostGIS and PostgreSQL

8

GeOnG Forum 2016, Chambéry, France

9 of 27

Get OSM data :: Overpass-API and overpass-turbo

  1. Overpass-API is a good tool for:
    1. regional level + specific objects
    2. City level + buildings + streets
    3. Show temporal change for city + regional level

Overpass-API intro:

You need everything for large areas?

    • geofabrik, HOT Export Tool, BBBike + PostGIS + PostgreSQL

9

GeOnG Forum 2016, Chambéry, France

10 of 27

Overpass-API and overpass-turbo :: filter by tag

/*

This has been generated by the overpass-turbo wizard.

The original search was:

“amenity=school”

*/

[out:json][timeout:25];

// gather results

(

// query part for: “amenity=school”

node["amenity"="school"]({{bbox}});

way["amenity"="school"]({{bbox}});

relation["amenity"="school"]({{bbox}});

);

// print results

out body;

>;

out skel qt;

10

GeOnG Forum 2016, Chambéry, France

11 of 27

Overpass-API and overpass-turbo :: filter by tag

/*

The original search was:

“highway=trunk and ref=RN1”

*/

[out:json][timeout:25];

// gather results

(

// query part for: “highway=trunk and ref=RN1”

node["highway"="trunk"]["ref"="RN1"]({{bbox}});

way["highway"="trunk"]["ref"="RN1"]({{bbox}});

relation["highway"="trunk"]["ref"="RN1"]({{bbox}});

);

// print results

out body;

>;

out skel qt;

11

GeOnG Forum 2016, Chambéry, France

12 of 27

Overpass-API and overpass-turbo :: filter by area

/*

The original search was:

“highway=* in Chambery”

*/

[out:json][timeout:25];

// fetch area “Chambery” to search in

{{geocodeArea:Chambery}}->.searchArea;

// gather results

(

// query part for: “highway=*”

node["highway"](area.searchArea);

way["highway"](area.searchArea);

relation["highway"](area.searchArea);

);

// print results

out body;

>;

out skel qt;

12

GeOnG Forum 2016, Chambéry, France

13 of 27

Overpass-API and overpass-turbo :: filter by username

/*

This has been generated by the overpass-turbo wizard.

The original search was:

“user:Hagellach37”

*/

[out:json][timeout:25];

// gather results

(

// query part for: “user:Hagellach37”

node(user:"Hagellach37")({{bbox}});

way(user:"Hagellach37")({{bbox}});

relation(user:"Hagellach37")({{bbox}});

);

// print results

out body;

>;

out skel qt;

13

GeOnG Forum 2016, Chambéry, France

14 of 27

Overpass-API and overpass-turbo ::

get only latest/new OSM data

/*

This has been generated by the overpass-turbo wizard.

The original search was:

“newer:"2016-10-01T00:00:00Z"”

*/

[out:json][timeout:25];

// gather results

(

// query part for: “newer:"2016-10-01T00:00:00Z"”

node(newer:"2016-10-01T00:00:00Z")({{bbox}});

way(newer:"2016-10-01T00:00:00Z")({{bbox}});

relation(newer:"2016-10-01T00:00:00Z")({{bbox}});

);

// print results

out body;

>;

out skel qt;

14

GeOnG Forum 2016, Chambéry, France

15 of 27

Overpass-API and overpass-turbo ::

get historic OSM data

/*

The original search was:

“idp:camp_site=spontaneous_camp ”

*/

[out:json][timeout:25][date:"2015-05-05T00:00:00Z"];

// gather results

(

// query part for: “"idp:camp_site"=spontaneous_camp”

node["idp:camp_site"="spontaneous_camp"]({{bbox}});

way["idp:camp_site"="spontaneous_camp"]({{bbox}});

relation["idp:camp_site"="spontaneous_camp"]({{bbox}});

);

// print results

out body;

>;

out skel qt;

15

GeOnG Forum 2016, Chambéry, France

16 of 27

Overpass-API and overpass-turbo :: output meta data

/*

This has been generated by the overpass-turbo wizard.

The original search was:

“idp:camp_site=spontaneous_camp ”

*/

[out:json][timeout:25][date:"2015-05-05T00:00:00Z"];

// gather results

(

// query part for: “"idp:camp_site"=spontaneous_camp”

node["idp:camp_site"="spontaneous_camp"]({{bbox}});

way["idp:camp_site"="spontaneous_camp"]({{bbox}});

relation["idp:camp_site"="spontaneous_camp"]({{bbox}});

);

// print results

out meta;

>;

out skel qt;

16

GeOnG Forum 2016, Chambéry, France

17 of 27

Overpass-API and overpass-turbo :: export data and save queries

17

GeOnG Forum 2016, Chambéry, France

18 of 27

Overpass-API and overpass-turbo :: dynamic web map in uMap

  • Export query as link:

  • Import data in uMap:

18

GeOnG Forum 2016, Chambéry, France

19 of 27

Overpass-API and overpass-turbo :: dynamic web map in uMap

  • Layer properties:

  • Results in uMap:

19

GeOnG Forum 2016, Chambéry, France

20 of 27

Agenda

  • OSM data on your mobile device (Garmin-GPS, Osmand)
  • Get OSM data: the Overpass-API and overpass-turbo.eu
  • Get the OSM raw data: OpenStreetMap-API
  • OSM data in your database: PostGIS and PostgreSQL

20

GeOnG Forum 2016, Chambéry, France

21 of 27

OpenStreetMap-API: Get raw data

  • More information:�https://wiki.openstreetmap.org/wiki/API_v0.6
  • Filter by bounding box
  • Filter by OSM id
  • Filter by OSM version
    • Get OSM history data
  • Get history of OSM objects
  • Not suitable to extract large areas
  • Maximum area: bbox with 0.25° * 0.25°

21

GeOnG Forum 2016, Chambéry, France

22 of 27

Agenda

  • OSM data on your mobile device (Garmin-GPS, Osmand)
  • Get OSM data: the Overpass-API and overpass-turbo.eu
  • Get the OSM raw data: OpenStreetMap-API
  • OSM data in your database: PostGIS and PostgreSQL

22

GeOnG Forum 2016, Chambéry, France

23 of 27

OSM data in your database

  1. Install PostgreSQL + PostGIS
  2. Download Osmosis�(http://wiki.openstreetmap.org/wiki/Osmosis )
  3. Get OSM data (.osm.pbf)
    • e.g. Geofabrik, HOT Export Tool, BBBike
  1. Create new database
  2. Create „hstore“ extension
  3. Create database schema for OSM data
  4. Create spatial index
  5. Import OSM data

23

GeOnG Forum 2016, Chambéry, France

24 of 27

OSM data in your database :: Prepare PostGIS database

Import data:

  • Open console and run:

osmosis --read-pbf file="sud_kivu.osm.pbf" --write-pgsql host="123.208.218.97" database="missing_maps_kivu" user=“crazy_user" password=“crazy_password“

  • Adapt to your settings.

24

GeOnG Forum 2016, Chambéry, France

25 of 27

OSM data in your database :: Run your queries

SELECT count(*) FROM ways WHERE (tags @> '"amenity"=>"school"')

SELECT * FROM ways WHERE tags ? 'building‘

SELECT * FROM nodes WHERE (tags @> '"amenity"=>"school"') AND (tags ? 'name');

+ spatial queries and analysis:

    • ST_intersect()
    • ST_union()
    • ST_Area()
    • ST_Distance()
    • And many more

25

GeOnG Forum 2016, Chambéry, France

26 of 27

OSM data in your database :: Load data in QGIS

26

GeOnG Forum 2016, Chambéry, France

27 of 27

Thank you. ☺

Eckle@uni-heidelberg.de

marcel.reinmuth@stud.uni-heidelberg.de

Herfort@uni-heidelberg.de

disastermappers@posteo.de

27

GeOnG Forum 2016, Chambéry, France