ramyaragupathy / hotosm-viz

HOTOSM Outreachy prototype
https://ramyaragupathy.github.io/hotosm-viz/#
MIT License
0 stars 0 forks source link
hotosm openstreetmap

HOTOSM map-viz

Prototype for HOTOSM Outreachy project

Local development

How does it work?

working

image relations image ways image nodes

Approach

Objective is to view the edits made in a particular geography after a mapping event, something like Total number of buildings touched or Total kms of highways touched.

Data Extraction

This is like questioning OpenStreetMap on Hey, show me all the edits made in Bangalore today. This question can be put to OpenStreetMap in several ways.

  1. Query OpenStreetMap directly from user interface using Export option
  2. OpenStreetMap API
  3. Use a third party tool like Overpass
  4. Using planet/geofabrik/metro extracts and then write a script to extract specifc data from downloaded extracts

All the above options have their merits in different situations. Let's dig our question Hey, show me all the edits made in Bangalore today to understand which option is better.

This question has three parts to it:

  1. all the edits - this is inclusive of all the feature types - buildings, highways. This part can be made very specific to say all building edits or all highway edits
  2. edits made in Bangalore - question is specific to a place
  3. edits made today - edits made from the start of the day to the current time.

All the three factors - kind of features edited, geography and timeframe are variable. We've to choose an option that could fit in these three factors.

Option Feature filtering Geography filter Time filter
Query OpenStreetMap directly from user interface using Export option :heavy_multiplication_x: only rectangluar bounding box :heavy_multiplication_x:
OpenStreetMap API :heavy_multiplication_x: only rectangluar bounding box :heavy_multiplication_x:
Overpass (read only API) :heavy_check_mark: :heavy_check_mark: (rectangular + polygon) :heavy_check_mark:
planet/geofabrik/metro extracts custom script custom script custom script

Obvious choice is Overpass API. In general Overpass is great for:

But before we go ahead, it's necessary to understand limitations to Overpass like:

Implementing Data Extaction

Geography filter - Start with a rectangular bounding box form map view, that is get the bounds of the map from the current map view on the right pane. Use this bounds to construct a rectangular bbox This should be extended to accomodate any polygon boundary

  let bounds = map.getBounds()
  let north = bounds['_ne'].lat
  let east = bounds['_ne'].lng
  let south = bounds['_sw'].lat
  let west = bounds['_sw'].lng
  let bbox = south + ',' + west + ',' + north + ',' + east

Time filter - Provide two fields to gather start date and end date for the query. Default sets to today's timeframe.

image

Tag filter - Yet to be implemented

On hitting Fetch Data, overpass query is constructed on the fly. Eg:

https://www.overpass-api.de/api/interpreter?data=[out:xml][timeout:25];(node (changed:'2018-03-21T18:30:01.000Z','2018-03-22T06:25:14.000Z') (12.227550060708552,76.3482848025194,14.011214271757382,78.9857151974922));(way (changed:'2018-03-21T18:30:01.000Z','2018-03-22T06:25:14.000Z')(12.227550060708552,76.3482848025194,14.011214271757382,78.9857151974922));(rel (changed:'2018-03-21T18:30:01.000Z','2018-03-22T06:25:14.000Z') (12.227550060708552,76.3482848025194,14.011214271757382,78.9857151974922));out body;>;out body qt;

This is sent to the overpass API and the result is obtained in xml format. Other options include json and csv format. Whatever be the format, response data has to be processed further to get geojson data. From xml format, data is converted to geojson using [osmtogeojson](https://github.com/tyrasd/osmtogeojson) module.

Visualising data

Processed data is separated into three layers(node, way, relation) for map viz using mapbox-gl js and the count for each geometry is shown in the side bar.

image

image relations image ways image nodes

This layering will change when tag filering comes into play.

View by geometry/feature - Each geometry type has a checkbox next to it. Based on what is checked, layers should display/disappear on the map