Reference

Representing map data

OpenStreetMapX.MapDataType

The MapData represents all data that have been processed from OpenStreetMap osm file This is the main data structure used fot map data analytics.

Fields

  • bounds : bounds of the area map (stored as a Bounds object)
  • nodes : dictionary of nodes representing all the objects on the map (with coordinates in East, North, Up system)
  • roadways : unique roads stored as a set of Ways
  • intersections : roads intersections
  • g : Graphs directed graph representing a road network
  • v : vertices in the road network (node id .=> graph vertex)
  • n : vector of OpenStreetMap node ids for each corresponding graph vertex
  • e : vector of edges in the graph represented as a tuple (source,destination)
  • w : sparse matrix of edge weights, indexed by graph id
  • class : road class of each edge
source
OpenStreetMapX.get_map_dataMethod
get_map_data(filepath::String,filename::Union{String,Nothing}=nothing;
             road_levels::Set{Int} = Set(1:length(OpenStreetMapX.ROAD_CLASSES)),
			 use_cache::Bool = true, only_intersections::Bool=true)::MapData

High level function - parses .osm file and create the road network based on the map data. This code currently can parse both *.osm and *.pbf (@blegat - thank you!) files. The data type is determined by file extension.

Arguments

  • filepath : path with an .osm/.pbf file (directory or path to a file)
  • filename : name of the file (when the first argument is a directory)
  • road_levels : a set with the road categories (see: OpenStreetMapX.ROAD_CLASSES for more informations)
  • use_cache : a *.cache file will be crated with a serialized map image in the datapath folder
  • only_intersections : include only road system data
  • trim_to_connected_graph: trim orphan nodes in such way that the map is a strongly connected graph
source

Coordinate systems

OpenStreetMapX.ECEFType
ECEF

Point in Earth-Centered-Earth-Fixed (ECEF) coordinates. Global cartesian coordinate system rotating with the Earth.

Constructors

ECEF(x::Float64, y::Float64, z::Float64)
source
OpenStreetMapX.LLAType
LLA

Point in Latitude-Longitude-Altitude (LLA) coordinates Used to store node data in OpenStreetMapX XML files

Constructors

LLA(lat::Float64, lon::Float64)
LLA(lat::Float64, lon::Float64, alt::Float64)
LLA(xyz::XYZ)

Arguments

  • lat : lattitude
  • lon : Longitude
  • alt : altitude
source
OpenStreetMapX.ENUType
ENU

Point in East-North-Up (ENU) coordinates.

Local cartesian coordinate system. Linearized about a reference point.

Constructors

ENU(east::Float64, north::Float64, up::Float64)
ENU(east::Float64, north::Float64)
ENU(xyz::XYZ)
source
OpenStreetMapX.BoundsType
Bounds{T <: Union{LLA, ENU}}

Bounds for the LLA or ENUcoordinates. If T is not given Bounds{ENU} will be created.

source
OpenStreetMapX.centerFunction
center(bounds::Bounds{ENU})

Get Center Point of ENU Bounds Region

source
center(bounds::Bounds{LLA})

Get Center Point of LLA Bounds Region

source
OpenStreetMapX.inboundsFunction
inbounds(loc::ENU, bounds::Bounds{ENU})

Check Whether a location loc is within bounds bounds

source
inbounds(loc::LLA, bounds::Bounds{LLA})

Check whether a location loc is within bounds bounds

source
OpenStreetMapX.onboundsFunction
onbounds(loc::T, bounds::Bounds{T}) where T<:Union{LLA,ENU}

Check whether a location loc is onbounds bounds Works only for points that have passed the inbounds test

source
OpenStreetMapX.latlonFunction
latlon(m::MapData,map_g_point_id::Int64)::Tuple{Float64, Float64}

Returns a tuple of lattitute and longitude for a given graph node identifier map_g_point_id in graph m.g (i.e. map_g_point_id ∈ 1:nv(m.g)).

source
OpenStreetMapX.getXFunction
getX(lla::OpenStreetMapX.LLA)

Point Translator gets longitude

source
getX(enu::OpenStreetMapX.ENU)

Point Translator gets enu east value

source
OpenStreetMapX.getYFunction
getY(lla::OpenStreetMapX.LLA)

Point Translator gets lattitude

source
getY(enu::OpenStreetMapX.ENU)

Point Translator gets enu north value

source
OpenStreetMapX.getZFunction
getZ(lla::OpenStreetMapX.LLA)

Point Translator gets altitude

source
getZ(enu::OpenStreetMapX.ENU)

Point Translator gets up value

source
OpenStreetMapX.WGS84Constant

World Geodetic Coordinate System of 1984 (WGS 84) Standardized coordinate system for Earth Global ellipsoidal reference surface

source

Routing operations

OpenStreetMapX.point_to_nodesMethod
point_to_nodes(point::Tuple{Float64,Float64}, m::MapData)

Converts a pair Latitude-Longitude of coordinates point to a node on a map m The result is a node indentifier.

source
OpenStreetMapX.point_to_nodesMethod
point_to_nodes(point::LLA, m::MapData)

Converts a pair of coordinates LLA (Latitude-Longitude-Altitude) point to a node on a map m The result is a node indentifier.

source
OpenStreetMapX.shortest_routeFunction
shortest_route(m::MapData, node1::Int, node2::Int; routing::Symbol = :astar)

Find Shortest route between node1 and node2 on map m.

source
shortest_route(m::MapData, node1::Int, node2::Int, node3::Int; routing::Symbol = :astar)

Find Shortest route between node1 and node2 and node3 on map m.

source
OpenStreetMapX.fastest_routeFunction
fastest_route(m::MapData, node1::Int, node2::Int;
                    routing::Symbol = :astar,
                    speeds::Dict{Int,Float64}=SPEED_ROADS_URBAN)

Find fastest route between node1 and node2 on map m with assuming speeds for road classes.

source
fastest_route(m::MapData, node1::Int, node2::Int, node3::Int;
                    routing::Symbol = :astar,
                    speeds::Dict{Int,Float64}=SPEED_ROADS_URBAN)

Find fastest route between node1 and node2 and node3 on map m with assuming speeds for road classes.

source
OpenStreetMapX.a_star_algorithmFunction
a_star_algorithm(g::AbstractGraph{U},  
                s::Integer,                       
                t::Integer,                       
                distmx::AbstractMatrix{T}=Graphs.weights(g),
                heuristic::Function = (u,v) -> zero(T)) where {T, U}

High level function - implementation of A star search algorithm: (https://en.wikipedia.org/wiki/A*searchalgorithm). Based on the implementation in Graphs library, however significantly improved in terms of performance.

Arguments

  • g : graph object
  • S : start vertex
  • t : end vertex
  • distmx : distance matrix
  • heuristic : search heuristic function; by default returns zero
source
a_star_algorithm(m::MapData,  
                s::Integer,                       
                t::Integer)

A star search algorithm with straight line distance heuristic

Arguments

  • m : MapData object
  • S : start vertex
  • t : end vertex
  • distmx : distance matrix
source
OpenStreetMapX.distanceFunction
distance(a::ENU, b::ENU)

Calculates a distance between two points a and b

source
distance(a::ECEF, b::ECEF)

Calculates a distance between two points a and b

source
distance(x1, y1, z1, x2, y2, z2)

Calculates eclidean distance in three dimensions.

source
distance(nodes::Dict{Int,T}, route::AbstractVector{Int}) where T<:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})

Compute the distance of a route for some nodes data

source

Get Distances Between Edges

source
OpenStreetMapX.get_distanceFunction
get_distance(A::Int, B::Int, 
             nodes::Dict{Int,T} , 
             vertices_to_nodes::Vector{Int}) where T<:Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF}

Auxiliary function - takes two vertices of graph and return the distance between them. Used to compute straight line distance heuristic for A* algorithm.

Arguments

  • A : start vertex
  • B : end vertex
  • nodes : dictionary of .osm nodes ID's and correspoding points coordinates
  • vertices_to_nodes : dictionary mapping graph vertices to .osm file nodes
source
OpenStreetMapX.nodes_within_driving_timeFunction
nodes_within_driving_time(m::MapData, start_indices::Vector{Int}, limit::Float64=Inf, speeds::Dict{Int,Float64}=SPEED_ROADS_URBAN)

nodes_within_driving_time(nodes::Dict{Int,T}, m::MapData, loc::T, limit::Float64=Inf, locrange::Float64=500.0, speeds::Dict{Int,Float64}=SPEED_ROADS_URBAN) where T<:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})

Extract Nodes from bellman_fordStates Object Within an (Optional) Limit ### Based on Driving Time ###

source
OpenStreetMapX.nodes_within_driving_distanceFunction
nodes_within_driving_distance(m::MapData, start_indices::Vector{Int}, limit::Float64=Inf)

Extract Nodes from bellman_fordStates Object Within an (Optional) Limit ### Based on Driving Distance ###

source
OpenStreetMapX.nodes_within_weightsFunction
nodes_within_weights(m::MapData, weights::SparseArrays.SparseMatrixCSC{Float64,Int64}, start_indices::Vector{Int}, limit::Float64=Inf)

Extract Nodes from bellman_fordStates Object Within an (Optional) Limit ### Based on Weights ###

source
OpenStreetMapX.nearest_nodeFunction
nearest_node(nodes::Dict{Int,T}, loc::T) where T<:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})

Find the nearest node to a given location loc

source
nearest_node(m::MapData, loc::ENU, vs_only::Bool=true)

Find the nearest node to a given location loc

source
nearest_node(nodes::Dict{Int,T}, loc::T, node_list::AbstractSet{Int}) where T<:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})

Find the nearest node in a list of nodes

source
OpenStreetMapX.nodes_within_rangeFunction
nodes_within_range(nodes::Dict{Int,T}, loc::T, range::Float64 = Inf) where T<:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})

Find all nodes within range of a location

source
nodes_within_range(nodes::Dict{Int,T}, loc::T, node_list::AbstractSet{Int}, range::Float64 = Inf) where T<:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})

Find nodes within range of a location using a subset of nodes

source
nodes_within_range(nodes::Dict{Int,T},loc::T, m::OpenStreetMapX.MapData, range::Float64 = Inf) where T <:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})

Find vertices of a routing network within range of a location

source

Google API routing

OpenStreetMapX.get_google_routeMethod
get_google_route(origin::Int, destination::Int,
                 map_data:MapData, googleapi_key::String;
                 googleapi_parameters::Dict{Symbol,String} = googleAPI_parameters)

Get route from to based on Google Distances API with two points (origin and destination) on map map_data using Google API key googleapi_key with optional Google Distances API request parameters googleapi_parameters.

source
OpenStreetMapX.get_google_routeMethod
get_google_route(origin::Int, destination::Int, waypoint::Int,
                 map_data:MapData, googleapi_key::String;
                 googleapi_parameters::Dict{Symbol,String} = googleAPI_parameters)

Get route from to based on Google Distances API with three points (origin, destination and waypoint between) on map map_data using Google API key googleapi_key with optional Google Distances API request parameters googleapi_parameters.

source
OpenStreetMapX.node_to_stringMethod
node_to_string(node_id::Int,map_data::MapData)

Convert node coordinates (stored in ENU system in the nodes field of map_data) identified by node_id to string with LLA system coordinates

source
OpenStreetMapX.googleAPI_parametersConstant

Dictionary for Google Distances API requests:

Keys

  • :url : url for google API, only JSON files outputs are accepted
  • :mode : transportation mode used in simulation, in the current library scope only driving is accepted
  • :avoid : map features to avoid (to mantain compatibility with OSM routes ferries should be avoided)
  • :units : unit system for displaing distances (changing to imperial needs deeper changes in both OSMsim and OpenStreetMapX modules)
source
OpenStreetMapX.encode_oneFunction

Encode single coordinate (multiplied by 1e5 and rounded) in Google Polyline Algorithm Format

Arguments

  • val : single coordinate (multiplied by 1e5 and rounded)
source
OpenStreetMapX.encodeFunction

Encode coordinates in Google Polyline Algorithm Format

Arguments

  • coords : coordinates in LLA system stored as a tuple
source
OpenStreetMapX.decode_oneFunction

Decode single coordinate

Arguments

  • polyline : coordinates in Google Polyline Algorithm Format stored as an array of characters
  • index : position of each single coordinate in polyline array
source
OpenStreetMapX.decodeFunction

Decode coordinates in Google Polyline Algorithm Format

Arguments

  • polyline : string containing coordinates in Polyline Algorithm Format
source

Routing parameters

OpenStreetMapX.CYCLE_CLASSESConstant
CYCLE_CLASSES

Cycle classes - Level 1: Bike paths - Level 2: Separated bike lanes (tracks) - Level 3: Bike lanes - Level 4: Bikes typically allowed but not specified

source
OpenStreetMapX.PED_CLASSESConstant
PED_CLASSES

Pedestrain paths

- Level 1: Cycleways, walking paths, and pedestrian streets
- Level 2: Sidewalks
- Level 3: Pedestrians typically allowed but unspecified
- Level 4: Agricultural or horse paths, etc.
source

Map objects

Internal library functions

OpenStreetMapX.boundary_pointFunction
boundary_point(p1::T, p2::T, bounds::Bounds{T}) where T<:Union{LLA,ENU}

Find the closest point within bounds Works only for points where inbounds(p1) != inbounds(p2)

source
OpenStreetMapX.centroidFunction
centroid(nodes::Dict{Int,T}, node_list::Vector{Int}) where T<:(Union{OpenStreetMapX.LLA,OpenStreetMapX.ENU})

Compute Centroid of List of Nodes

source
OpenStreetMapX.classify_cyclewaysFunction
classify_cycleways(ways::Vector{OpenStreetMapX.Way},
                   classes::Dict{String, Int} = OpenStreetMapX.CYCLE_CLASSES)

Classifies a vector of OpenStreetMapX ways based on their cycleway attributes. It considers the presence of "bicycle", "cycleway", and "highway" tags and checks if the corresponding values or the constructed class strings are present in the specified classes dictionary.

Arguments

  • ways::Vector{OpenStreetMapX.Way} : Way's vector
  • classes : classes dictionary
source
OpenStreetMapX.classify_walkwaysFunction
classify_walkways(ways::Vector{OpenStreetMapX.Way},
                  classes::Dict{String, Int} = OpenStreetMapX.PED_CLASSES)

Classifies a vector of OpenStreetMapX ways based on their pedestrian attributes. It considers the presence of a "sidewalk" tagand checks if the corresponding value or the "highway" tag value is present in the specified classes dictionary

Arguments

  • ways::Vector{OpenStreetMapX.Way} : Way's vector
  • classes : classes dictionary
source
OpenStreetMapX.crop!Function
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, way::OpenStreetMapX.Way)

Crop Single Way

source
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way})

Crop Ways

source
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way},relations::Vector{OpenStreetMapX.Relation}, relation::OpenStreetMapX.Relation)

Crop Single Relation

source
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way}, relations::Vector{OpenStreetMapX.Relation})

Crop Relations

source
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, features::Dict, id::Int)

Crop Single Node and Feature

source
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, features::Dict)

Crop Nodes and Features

source
crop!(map::OpenStreetMapX.OSMData; crop_relations = true, crop_ways = true, crop_nodes = true)

Crop Map

source
OpenStreetMapX.filter_cyclewaysFunction
filter_cycleways(ways::Vector{OpenStreetMapX.Way},
                classes::Dict{String, Int} = OpenStreetMapX.CYCLE_CLASSES;
                levels::Set{Int} = Set(1:length(OpenStreetMapX.CYCLE_CLASSES)))

Filters a vector of OpenStreetMapX ways to include only those that are relevant for cycleways. It considers the presence of "bicycle", "cycleway", and "highway" tags and checks if the corresponding values or the constructed class strings are present in the specified classes dictionary and levels set.

Arguments

  • ways::Vector{OpenStreetMapX.Way} : Way's vector
  • classes : classes dictionary
  • levels : set of levels useful to compare with the way tags
source
OpenStreetMapX.filter_walkwaysFunction
filter_walkways(ways::Vector{OpenStreetMapX.Way},
                classes::Dict{String, Int} = OpenStreetMapX.PED_CLASSES;
                levels::Set{Int} = Set(1:length(OpenStreetMapX.PED_CLASSES)))

Filters a vector of ways to include only those that are relevant for pedestrian walkways. It considers the presence of a "sidewalk" tag and checks if the corresponding value or the "highway" tag value is present in the specified classes dictionary and levels set.

Arguments

  • ways::Vector{OpenStreetMapX.Way} : Way's vector
  • classes : classes dictionary
  • levels : set of levels useful to compare with the way tags
source
OpenStreetMapX.find_optimal_waypoint_approxFunction
find_optimal_waypoint_approx(m::MapData, weights::SparseArrays.SparseMatrixCSC{Float64,Int64}, node0::Int, node1::Int, waypoints::Dict{Int,Int})

Find waypoint minimizing the route. Returns an approximate solution.

source
OpenStreetMapX.find_optimal_waypoint_exactFunction
find_optimal_waypoint_exact(m::MapData, weights::SparseArrays.SparseMatrixCSC{Float64,Int64}, node0::Int, node1::Int, waypoints::Dict{Int,Int})

Find waypoint minimizing the route. Returns an exact solution.

source
OpenStreetMapX.find_routeFunction
find_route(m::MapData, node0::Int, node1::Int, node2::Int,
                    weights::SparseArrays.SparseMatrixCSC{Float64,Int64};
                    routing::Symbol = :astar, heuristic::Function = (u,v) -> zero(Float64),
                    get_distance::Bool = false, get_time::Bool = false)

Find Route Connecting 3 Points (node0, node1, node2) with Given Weights

source
OpenStreetMapX.find_segmentsFunction
find_segments(nodes::Dict{Int,T}, highways::Vector{OpenStreetMapX.Way}, intersections::Dict{Int,Set{Int}}) where T<:Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF}

Find Segments of Highways

source