Skip to content

Commit

Permalink
Relase 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pszufe committed Oct 30, 2023
1 parent ac32b8c commit 6b37273
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 89 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OpenStreetMapX"
uuid = "86cd37e6-c0ff-550b-95fe-21d72c8d4fc9"
authors = ["Przemyslaw Szufel <pszufe@gmail.com>", "Bartosz Pankratz <bartosz.pankratz@gmail.com>", "Anna Szczurek <annaszczurek2@gmail.com>", "Bogumil Kaminski <bogumil.kaminski@gmail.com>", "Pawel Pralat <pralat@ryerson.ca>"]
version = "0.3.4"
version = "0.4.0"

[deps]
CodecZlib = "944b1d66-785c-5afd-91f1-9de20f533193"
Expand Down
18 changes: 11 additions & 7 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
using Documenter
using Pkg

try
using OpenStreetMapX
catch
if !("../src/" in LOAD_PATH)
push!(LOAD_PATH,"../src/")
@info "Added \"../src/\"to the path: $LOAD_PATH "
using OpenStreetMapX

if isfile("src/OpenStreetMapX.jl")
if !("." in LOAD_PATH)
push!(LOAD_PATH,".")
end
elseif isfile("../src/OpenStreetMapX.jl")
if !(".." in LOAD_PATH)
push!(LOAD_PATH,"..")
end
end

using OpenStreetMapX

makedocs(
sitename = "OpenStreetMapX",
format = format = Documenter.HTML(
prettyurls = get(ENV, "CI", nothing) == "true"
),
modules = [OpenStreetMapX],
pages = ["index.md", "spatial.md", "reference.md"],
checkdocs = :exports,
doctest = true
)

Expand Down
40 changes: 40 additions & 0 deletions docs/src/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Representing map data
```@docs
MapData
get_map_data(::String,::Union{String,Nothing}; ::Set{Int},::Bool,::Bool)
sample_map_path
sample_map
```

Coordinate systems
Expand All @@ -26,6 +28,10 @@ center
inbounds
onbounds
latlon
getX
getY
getZ
WGS84
```


Expand All @@ -39,6 +45,12 @@ shortest_route
fastest_route
a_star_algorithm
distance
get_distance
nodes_within_driving_time
nodes_within_driving_distance
nodes_within_weights
nearest_node
nodes_within_range
```

Google API routing
Expand All @@ -64,3 +76,31 @@ PED_CLASSES
SPEED_ROADS_URBAN
SPEED_ROADS_RURAL
```


Map objects
-----------
```@docs
Way
Relation
```

Internal library functions
--------------------------
```@docs
boundary_point
centroid
classify_cycleways
classify_walkways
crop!
extract_highways
features_to_graph
filter_cycleways
filter_highways
filter_walkways
find_intersections
find_optimal_waypoint_approx
find_optimal_waypoint_exact
find_route
find_segments
```
3 changes: 2 additions & 1 deletion src/OpenStreetMapX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ export get_map_data
export get_google_route
export encode, decode
export generate_point_in_bounds, point_to_nodes

export sample_map, sample_map_path
export latlon
export Bounds, Way

export ROAD_CLASSES, CYCLE_CLASSES, PED_CLASSES, SPEED_ROADS_URBAN, SPEED_ROADS_RURAL

Expand Down
52 changes: 28 additions & 24 deletions src/classification.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ end

getlanes(w::OpenStreetMapX.Way) = parse(Int, w.tags["lanes"])

visible(obj::T) where T <: OSMElement = (get(obj.tags, "visible", "") != "false")
visible(obj::T) where T <: OSMElement = (get(obj.tags, "visible", "") != "false")

services(w::OpenStreetMapX.Way) = (get(w.tags,"highway", "") == "services")

########################
### Extract Highways ###
########################
"""""
extract_highways(ways::Vector{OpenStreetMapX.Way})
Extract Highways
"""
extract_highways(ways::Vector{OpenStreetMapX.Way}) = [way for way in ways if isdefined(way,:tags) && haskey(way.tags, "highway")]

filter_highways(ways::Vector{OpenStreetMapX.Way}) = [way for way in ways if OpenStreetMapX.visible(way) && !OpenStreetMapX.services(way)]
"""
filter_highways(ways::Vector{OpenStreetMapX.Way})
##############################################
### Filter and Classify Highways for Cars ###
##############################################
"""
filter_highways(ways::Vector{OpenStreetMapX.Way}) = [way for way in ways if OpenStreetMapX.visible(way) && !OpenStreetMapX.services(way)]

###
## Filter and Classify Highways for Cars
###
"""
valid_roadway(way, levels::Set{Int}, classes::Dict{String, Int} = OpenStreetMapX.ROAD_CLASSES)
"""
function valid_roadway(way, levels::Set{Int}, classes::Dict{String, Int} = OpenStreetMapX.ROAD_CLASSES)
highway = get(way.tags, "highway", "")
if isempty(highway) || highway == "services" || !haskey(classes, highway)
Expand All @@ -38,18 +45,15 @@ filter_roadways(ways::Vector{OpenStreetMapX.Way}, classes::Dict{String, Int} = O
classify_roadway(way::Way, classes::Dict{String, Int} = OpenStreetMapX.ROAD_CLASSES) = classes[way.tags["highway"]]
classify_roadways(ways::Vector{OpenStreetMapX.Way}, classes::Dict{String, Int} = OpenStreetMapX.ROAD_CLASSES) = Dict{Int,Int}(way.id => classify_roadway(way, classes) for way in ways if haskey(classes, way.tags["highway"]))

####################################################
### Filter and Classify Highways for Pedestrians ###
####################################################

"""
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.
is present in the specified classes dictionary and levels set.
**Arguments**
Expand All @@ -71,12 +75,12 @@ function filter_walkways(ways::Vector{OpenStreetMapX.Way},classes::Dict{String,
end
end
return walkways
end
end

"""
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
Expand All @@ -92,9 +96,9 @@ function classify_walkways(ways::Vector{OpenStreetMapX.Way},classes::Dict{String
for way in ways
sidewalk = get(way.tags, "sidewalk", "")
if sidewalk != "no"
if haskey(classes, "sidewalk:$(sidewalk)")
if haskey(classes, "sidewalk:$(sidewalk)")
walkways[way.id] = classes["sidewalk:$(sidewalk)"]
elseif haskey(classes, way.tags["highway"])
elseif haskey(classes, way.tags["highway"])
walkways[way.id] = classes[way.tags["highway"]]
end
end
Expand All @@ -110,7 +114,7 @@ end
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.
Expand All @@ -119,7 +123,7 @@ or the constructed class strings are present in the specified classes dictionary
* `ways::Vector{OpenStreetMapX.Way}` : Way's vector
* `classes` : classes dictionary
* `levels` : set of levels useful to compare with the way tags
* `levels` : set of levels useful to compare with the way tags
"""
function filter_cycleways(ways::Vector{OpenStreetMapX.Way}, classes::Dict{String, Int} = OpenStreetMapX.CYCLE_CLASSES; levels::Set{Int} = Set(1:length(OpenStreetMapX.CYCLE_CLASSES)))
Expand Down Expand Up @@ -148,7 +152,7 @@ end
"""
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.
Expand All @@ -170,11 +174,11 @@ function classify_cycleways(ways::Vector{OpenStreetMapX.Way}, classes::Dict{Stri
bikeclass = "bicycle:$(bicycle)"

if bicycle != "no"
if haskey(classes, cycleclass)
if haskey(classes, cycleclass)
cycleways[way.id] = classes[cycleclass]
elseif haskey(classes, bikeclass)
elseif haskey(classes, bikeclass)
cycleways[way.id] = classes[bikeclass]
elseif haskey(classes, highway)
elseif haskey(classes, highway)
cycleways[way.id] = classes[highway]
end
end
Expand Down Expand Up @@ -211,5 +215,5 @@ function filter_graph_features(features::Dict{Int,Tuple{String,String}}, graphFe
error("class not in classes")
end
level = classes[class]
Dict{Int,Int}(key => node for (key,node) in graphFeatures if classes[features[key][1]] == level)
Dict{Int,Int}(key => node for (key,node) in graphFeatures if classes[features[key][1]] == level)
end
54 changes: 31 additions & 23 deletions src/crop.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#######################
### Crop Single Way ###
#######################
"""
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, way::OpenStreetMapX.Way)
Crop Single Way
"""
function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, way::OpenStreetMapX.Way)
valid = falses(length(way.nodes)+2)
n = 1
Expand Down Expand Up @@ -48,21 +49,23 @@ function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, way::OpenStreetMapX.W
end
end

#################
### Crop Ways ###
#################
"""
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way})
Crop Ways
"""
function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way})
leave = ways[[!OpenStreetMapX.crop!(nodes,bounds,way) for way in ways]]
append!(empty!(ways),leave)
return nothing
end


############################
### Crop Single Relation ###
############################
"""
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way},relations::Vector{OpenStreetMapX.Relation}, relation::OpenStreetMapX.Relation)
Crop Single Relation
"""
function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way},relations::Vector{OpenStreetMapX.Relation}, relation::OpenStreetMapX.Relation)
valid = falses(length(relation.members))
for i = 1:length(relation.members)
Expand All @@ -71,10 +74,10 @@ function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStre
valid[i] = OpenStreetMapX.inbounds(nodes[ref],bounds)
elseif relation.members[i]["type"] == "way"
way_index = findfirst(way -> way.id == ref, ways)
!isa(way_index,Nothing) && (valid[i] = !OpenStreetMapX.crop!(nodes, bounds, ways[way_index]))
!isa(way_index,Nothing) && (valid[i] = !OpenStreetMapX.crop!(nodes, bounds, ways[way_index]))
else
relation_index = findfirst(relation -> relation.id == ref, relations)
!isa(relation_index,Nothing) && (valid[i] = !OpenStreetMapX.crop!(nodes,bounds, ways, relations, relations[relation_index]))
!isa(relation_index,Nothing) && (valid[i] = !OpenStreetMapX.crop!(nodes,bounds, ways, relations, relations[relation_index]))
end
end
relation.members = relation.members[valid]
Expand All @@ -85,41 +88,46 @@ function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStre
end
end

######################
### Crop Relations ###
######################
"""
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way}, relations::Vector{OpenStreetMapX.Relation})
Crop Relations
"""
function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, ways::Vector{OpenStreetMapX.Way}, relations::Vector{OpenStreetMapX.Relation})
leave = relations[[!OpenStreetMapX.crop!(nodes,bounds,ways, relations, relation) for relation in relations]]
append!(empty!(relations),leave)
return nothing
end

####################################
### Crop Single Node and Feature ###
####################################

"""
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, features::Dict, id::Int)
Crop Single Node and Feature
"""
function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, features::Dict, id::Int)
if !OpenStreetMapX.inbounds(nodes[id], bounds)
id in keys(features) && delete!(features, id)
delete!(nodes,id)
end
end

###############################
### Crop Nodes and Features ###
###############################
"""
crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, features::Dict)
Crop Nodes and Features
"""
function crop!(nodes::Dict, bounds::OpenStreetMapX.Bounds, features::Dict)
for (key, node) in nodes
OpenStreetMapX.crop!(nodes,bounds,features,key)
end
end

################
### Crop Map ###
################
"""
crop!(map::OpenStreetMapX.OSMData; crop_relations = true, crop_ways = true, crop_nodes = true)
Crop Map
"""
function crop!(map::OpenStreetMapX.OSMData; crop_relations = true, crop_ways = true, crop_nodes = true)
crop_relations && OpenStreetMapX.crop!(map.nodes, map.bounds, map.ways, map.relations)
crop_ways && OpenStreetMapX.crop!(map.nodes, map.bounds, map.ways)
Expand Down
Loading

2 comments on commit 6b37273

@pszufe
Copy link
Owner Author

@pszufe pszufe commented on 6b37273 Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/94423

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" 6b37273efd81e99d2330983099fdf9b168c85a5d
git push origin v0.4.0

Please sign in to comment.