Skip to content

02.1 OpenStreetMap OSMMiner subclass

Artur André A. M. Oliveira edited this page Jul 26, 2021 · 1 revision

The OSMMiner subclass

The OSMMiner subclass is responsible for collecting data from an OpenStreetMap server. In the current implementation of the OSMMiner, this is done through the Overpass API (demo site), which provides its own query language in the current implementation.

As a subclass of the MapMiner abstract class the OSMMiner subclass implements the properties:

  1. mapMinerName = "OpenStreetMap - Used for displaying purposed (e.g. in the frontend),
  2. mapMinerId = "osm" - Used for identification purposes (i.e. routing a query to the selected Map Miner), and
  3. _basecrs = SpatialReference(3857) - Used to perform projections between different Coordinate Reference Systems (crs).
  4. _availableQueries - This is a dictionary whose key is a string corresponding to a geographical feature (e.g. Streets) and the key must be a function that returns a (MultiLineString) object. A MultiLineString represents a set with one or more LineStrings, which in turn represents a sequence (list) of 2D or 3D coordinates, that is, a path.

The OSMMiner also contains the property _OSMServerURL which may take the values 'OverpassAPI.DE' and 'inacity.org', indicating the OSM server to be used. This property is not inherited from its base class.

How streets are collected?

The OpenStreetMap platform is crowd-sourced and although it has some degree of editorial curation (i.e. some editor users may review and correct data supplied by other users) the registered geographical features are represented in a very flexible manner, thus some constraints and heuristics are necessary to collect them consistently.

The OSMMiner subclass collects streets, highways, and avenues using the following Overpass Turbo query:

/*
- stringRegion is a string with the coordinates of a rectangular area.
- `way` is an object from OpenStreetMap structure denoting a set of `node` objects and usually is used to represent linear geographical features.
*/
(way["highway"~".*"](poly:"' + stringRegion + '");              // Here we collect every `way` inside the stringRegion with the tag 'highway'
way["surface"="asphalt"](poly:"' + stringRegion + '");)->.all;  // Now we join every `way` with a tag 'surface' with value 'asphalt'
(way["fixme"](poly:"' + stringRegion + '")->.a;                 // Now we include multiple features that correspond to streets
way["highway"="footway"](poly:"' + stringRegion + '")->.a;      // into a set named as `a` (e.g. `->.a`)
way["highway"="service"](poly:"' + stringRegion + '")->.a;
way["highway"="steps"](poly:"' + stringRegion + '")->.a;
way["name"!~".*"](poly:"' + stringRegion + '")->.a;)->.remove;  // Here we collect features that don't have the 'name' tag, those aren't streets.
(.all; - .remove;)->.allfiltered;                               // Now we remove the features that are not streets
(.allfiltered;>;);out;                                          // The response is then outputted (as a json)

Note that this query is manually constructed and depends on specific knowledge about how data is organized into OpenStreetMap. In extreme cases, the tags corresponding to streets may change depending on the country/region selected.

After collecting a set of way objects the function _mergeWays of the OSMMiner subclass is called. This function deals with possible inconsistencies and issues due to intersections and 'loops'; this is necessary to avoid collecting the same image multiple times.

Clone this wiki locally