Reference
Representing map data
OpenStreetMapX.MapData
— TypeThe 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 aBounds
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 ofWay
sintersections
: roads intersectionsg
:Graphs
directed graph representing a road networkv
: vertices in the road network (node id .=> graph vertex)n
: vector of OpenStreetMap node ids for each corresponding graph vertexe
: vector of edges in the graph represented as a tuple (source,destination)w
: sparse matrix of edge weights, indexed by graph idclass
: road class of each edge
OpenStreetMapX.get_map_data
— Methodget_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 thedatapath
folderonly_intersections
: include only road system datatrim_to_connected_graph
: trim orphan nodes in such way that the map is a strongly connected graph
OpenStreetMapX.sample_map_path
— Functionsample_map_path()
Produces a path to a sample map file.
OpenStreetMapX.sample_map
— Functionsample_map()
Produces a MapData object in a lazy loaded way.
Coordinate systems
OpenStreetMapX.ECEF
— TypeECEF
Point in Earth-Centered-Earth-Fixed (ECEF) coordinates. Global cartesian coordinate system rotating with the Earth.
Constructors
ECEF(x::Float64, y::Float64, z::Float64)
OpenStreetMapX.LLA
— TypeLLA
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
: lattitudelon
: Longitudealt
: altitude
OpenStreetMapX.ENU
— TypeENU
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)
OpenStreetMapX.Bounds
— TypeBounds{T <: Union{LLA, ENU}}
Bounds for the LLA
or ENU
coordinates. If T
is not given Bounds{ENU} will be created.
OpenStreetMapX.center
— Functioncenter(bounds::Bounds{ENU})
Get Center Point of ENU Bounds Region
center(bounds::Bounds{LLA})
Get Center Point of LLA Bounds Region
OpenStreetMapX.inbounds
— Functioninbounds(loc::ENU, bounds::Bounds{ENU})
Check Whether a location loc
is within bounds bounds
inbounds(loc::LLA, bounds::Bounds{LLA})
Check whether a location loc
is within bounds bounds
OpenStreetMapX.onbounds
— Functiononbounds(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
OpenStreetMapX.latlon
— Functionlatlon(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)
).
OpenStreetMapX.getX
— FunctiongetX(lla::OpenStreetMapX.LLA)
Point Translator gets longitude
getX(enu::OpenStreetMapX.ENU)
Point Translator gets enu east
value
OpenStreetMapX.getY
— FunctiongetY(lla::OpenStreetMapX.LLA)
Point Translator gets lattitude
getY(enu::OpenStreetMapX.ENU)
Point Translator gets enu north
value
OpenStreetMapX.getZ
— FunctiongetZ(lla::OpenStreetMapX.LLA)
Point Translator gets altitude
getZ(enu::OpenStreetMapX.ENU)
Point Translator gets up
value
OpenStreetMapX.WGS84
— ConstantWorld Geodetic Coordinate System of 1984 (WGS 84) Standardized coordinate system for Earth Global ellipsoidal reference surface
Routing operations
OpenStreetMapX.generate_point_in_bounds
— Functiongenerate_point_in_bounds([rng::AbstractRNG], m::MapData)
Generates a random pair of Latitude-Longitude coordinates within boundaries of map m
OpenStreetMapX.point_to_nodes
— Methodpoint_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.
OpenStreetMapX.point_to_nodes
— Methodpoint_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.
OpenStreetMapX.shortest_route
— Functionshortest_route(m::MapData, node1::Int, node2::Int; routing::Symbol = :astar)
Find Shortest route between node1
and node2
on map m
.
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
.
OpenStreetMapX.fastest_route
— Functionfastest_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.
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.
OpenStreetMapX.a_star_algorithm
— Functiona_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 objectS
: start vertext
: end vertexdistmx
: distance matrixheuristic
: search heuristic function; by default returns zero
a_star_algorithm(m::MapData,
s::Integer,
t::Integer)
A star search algorithm with straight line distance heuristic
Arguments
m
: MapData objectS
: start vertext
: end vertexdistmx
: distance matrix
OpenStreetMapX.distance
— Functiondistance(a::ENU, b::ENU)
Calculates a distance between two points a
and b
distance(a::ECEF, b::ECEF)
Calculates a distance between two points a
and b
distance(x1, y1, z1, x2, y2, z2)
Calculates eclidean distance in three dimensions.
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
Get Distances Between Edges
OpenStreetMapX.get_distance
— Functionget_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 vertexB
: end vertexnodes
: dictionary of .osm nodes ID's and correspoding points coordinatesvertices_to_nodes
: dictionary mapping graph vertices to .osm file nodes
OpenStreetMapX.nodes_within_driving_time
— Functionnodes_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 ###
OpenStreetMapX.nodes_within_driving_distance
— Functionnodes_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 ###
OpenStreetMapX.nodes_within_weights
— Functionnodes_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 ###
OpenStreetMapX.nearest_node
— Functionnearest_node(nodes::Dict{Int,T}, loc::T) where T<:(Union{OpenStreetMapX.ENU,OpenStreetMapX.ECEF})
Find the nearest node to a given location loc
nearest_node(m::MapData, loc::ENU, vs_only::Bool=true)
Find the nearest node to a given location loc
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
OpenStreetMapX.nodes_within_range
— Functionnodes_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
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
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
Google API routing
OpenStreetMapX.get_google_route
— Methodget_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
.
OpenStreetMapX.get_google_route
— Methodget_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
.
OpenStreetMapX.node_to_string
— Methodnode_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
OpenStreetMapX.googleAPI_parameters
— ConstantDictionary 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)
OpenStreetMapX.encode_one
— FunctionEncode single coordinate (multiplied by 1e5 and rounded) in Google Polyline Algorithm Format
Arguments
val
: single coordinate (multiplied by 1e5 and rounded)
OpenStreetMapX.encode
— FunctionEncode coordinates in Google Polyline Algorithm Format
Arguments
coords
: coordinates in LLA system stored as a tuple
OpenStreetMapX.decode_one
— FunctionDecode single coordinate
Arguments
polyline
: coordinates in Google Polyline Algorithm Format stored as an array of charactersindex
: position of each single coordinate in polyline array
OpenStreetMapX.decode
— FunctionDecode coordinates in Google Polyline Algorithm Format
Arguments
polyline
: string containing coordinates in Polyline Algorithm Format
Routing parameters
OpenStreetMapX.ROAD_CLASSES
— ConstantROAD_CLASSES
Road classes. Information used for routing and plotting.
Ordered by typical significance
OpenStreetMapX.CYCLE_CLASSES
— ConstantCYCLE_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
OpenStreetMapX.PED_CLASSES
— ConstantPED_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.
OpenStreetMapX.SPEED_ROADS_URBAN
— ConstantDefault Speed Limits in Kilometers Per Hour in urban areas
OpenStreetMapX.SPEED_ROADS_RURAL
— ConstantDefault Speed Limits in Kilometers Per Hour in rural areas
Map objects
OpenStreetMapX.Way
— TypeWays in OSM data
OpenStreetMapX.Relation
— TypeRelations in OSM data
Internal library functions
OpenStreetMapX.boundary_point
— Functionboundary_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)
OpenStreetMapX.centroid
— Functioncentroid(nodes::Dict{Int,T}, node_list::Vector{Int}) where T<:(Union{OpenStreetMapX.LLA,OpenStreetMapX.ENU})
Compute Centroid of List of Nodes
OpenStreetMapX.classify_cycleways
— Functionclassify_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 vectorclasses
: classes dictionary
OpenStreetMapX.classify_walkways
— Functionclassify_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 vectorclasses
: classes dictionary
OpenStreetMapX.crop!
— Functioncrop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, way::OpenStreetMapX.Way)
Crop Single Way
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way})
Crop Ways
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way},relations::Vector{OpenStreetMapX.Relation}, relation::OpenStreetMapX.Relation)
Crop Single Relation
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way}, relations::Vector{OpenStreetMapX.Relation})
Crop Relations
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, features::Dict, id::Int)
Crop Single Node and Feature
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, features::Dict)
Crop Nodes and Features
crop!(map::OpenStreetMapX.OSMData; crop_relations = true, crop_ways = true, crop_nodes = true)
Crop Map
OpenStreetMapX.extract_highways
— Function"" extract_highways(ways::Vector{OpenStreetMapX.Way})
Extract Highways
OpenStreetMapX.features_to_graph
— FunctionFor Each Feature Find the Nearest Graph Node ###
OpenStreetMapX.filter_cycleways
— Functionfilter_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 vectorclasses
: classes dictionarylevels
: set of levels useful to compare with the way tags
OpenStreetMapX.filter_highways
— Functionfilter_highways(ways::Vector{OpenStreetMapX.Way})
OpenStreetMapX.filter_walkways
— Functionfilter_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 vectorclasses
: classes dictionarylevels
: set of levels useful to compare with the way tags
OpenStreetMapX.find_intersections
— Functionfind_intersections(highways::Vector{OpenStreetMapX.Way})
Find Intersections of Highways
OpenStreetMapX.find_optimal_waypoint_approx
— Functionfind_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.
OpenStreetMapX.find_optimal_waypoint_exact
— Functionfind_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.
OpenStreetMapX.find_route
— Functionfind_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
OpenStreetMapX.find_segments
— Functionfind_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