From de294408a0096e39bc11050f391eeb1e0283294b Mon Sep 17 00:00:00 2001 From: yeesian Date: Sat, 20 Dec 2014 17:26:00 -0500 Subject: [PATCH] support streaming osm files through libexpat --- README.md | 1 + REQUIRE | 1 + docs/data.rst | 13 +-- docs/examples.rst | 2 +- docs/types.rst | 28 +++--- src/OpenStreetMap.jl | 1 + src/buildings.jl | 82 ----------------- src/features.jl | 70 -------------- src/highways.jl | 160 -------------------------------- src/nodes.jl | 26 ------ src/parseMap.jl | 215 +++++++++++++++++++++++++++++++++++++++---- src/types.jl | 40 ++++---- test/classes.jl | 2 +- test/crop_map.jl | 4 +- test/plots.jl | 2 +- test/read_data.jl | 2 +- test/routes.jl | 2 +- 17 files changed, 242 insertions(+), 409 deletions(-) diff --git a/README.md b/README.md index 53b7a0e..b2f05dd 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ Pkg.add("OpenStreetMap") ##### Dependencies The following packages should automatically be added as "additional packages", if you do not already have them: * LightXML.jl: parsing OpenStreetMap datafiles +* LibExpat.jl: streaming OpenStreetMap datafiles * Winston.jl: map plotting * Graphs.jl: map routing diff --git a/REQUIRE b/REQUIRE index 37fdbf4..2b19ef4 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,6 @@ julia 0.3- Compat LightXML +LibExpat Winston Graphs diff --git a/docs/data.rst b/docs/data.rst index 5a4e17f..a351225 100644 --- a/docs/data.rst +++ b/docs/data.rst @@ -4,18 +4,12 @@ Reading OSM Data OpenStreetMap data is available in a variety of formats. However, the easiest and most common to work with is the OSM XML format. OpenStreetMap.jl makes reading data from these files easy and straightforward: -.. py:function:: getOSMData(filename::String [, nodes=false, highways=false, buildings=false, features=false]) +.. py:function:: getOSMData(filename::String) Inputs: * Required: * ``filename`` [``String``]: Filename of OSM datafile. - * Optional: - - * ``nodes`` [``Bool``]: ``true`` to read node data - * ``highways`` [``Bool``]: ``true`` to read highway data - * ``buildings`` [``Bool``]: ``true`` to read building data - * ``features`` [``Bool``]: ``true`` to read feature data Outputs: * ``nodes`` [``false`` or ``Dict{Int,LLA}``]: Dictionary of node locations @@ -29,10 +23,7 @@ These four outputs store all data from the file. ``highways``, ``buildings``, an .. code-block:: python - nodes, hwys, builds, feats = getOSMData(MAP_FILENAME, nodes=true, highways=true, buildings=true, features=true)`` - -**Usage Notes:** -Reading data is generally very fast unless your system runs out of memory. This is because LightXML.jl loads the entire xml file into memory as a tree rather than streaming it. A 150 MB OSM file seems to take up about 2-3 GB of RAM on my machine, so load large files with caution. + nodes, hwys, builds, feats = getOSMData(MAP_FILENAME) Extracting Intersections ------------------------ diff --git a/docs/examples.rst b/docs/examples.rst index c14f8f8..34a2eb5 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -5,7 +5,7 @@ Read data from an OSM XML file: .. code-block:: python - nodes, hwys, builds, feats = getOSMData(MAP_FILENAME, nodes=true, highways=true, buildings=true, features=true) + nodes, hwys, builds, feats = getOSMData(MAP_FILENAME) println("Number of nodes: $(length(nodes))") println("Number of highways: $(length(hwys))") diff --git a/docs/types.rst b/docs/types.rst index 2b03784..2c8ebed 100644 --- a/docs/types.rst +++ b/docs/types.rst @@ -92,10 +92,10 @@ Region boundaries include the minimum and maximum latitude and longitude of a re .. code-block:: python type Bounds - min_y # min_lat or min_north - max_y # max_lat or max_north - min_x # min_lon or min_east - max_x # max_lon or max_east + min_y::Float64 # min_lat or min_north + max_y::Float64 # max_lat or max_north + min_x::Float64 # min_lon or min_east + max_x::Float64 # max_lon or max_east end Point Types @@ -110,13 +110,13 @@ Used to store node data in OpenStreetMap XML files. .. code-block:: python type LLA - lat - lon - alt + lat::Float64 + lon::Float64 + alt::Float64 end Because OpenStreetMap typically does not store altitude data, the following alias is available for convenience: -``LLA(lat, lon) = LLA(lat, lon, 0)`` +``LLA(lat, lon) = LLA(lat, lon, 0.0)`` Earth-Centered-Earth-Fixed (ECEF) Coordinates ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -126,9 +126,9 @@ Global cartesian coordinate system rotating with the Earth. .. code-block:: python type ECEF - x - y - z + x::Float64 + y::Float64 + z::Float64 end East-North-Up (ENU) Coordinates @@ -139,9 +139,9 @@ Local cartesian coordinate system, centered on a reference point. .. code-block:: python type ENU - east - north - up + east::Float64 + north::Float64 + up::Float64 end Additional Types diff --git a/src/OpenStreetMap.jl b/src/OpenStreetMap.jl index f8e9f9d..d641bc7 100644 --- a/src/OpenStreetMap.jl +++ b/src/OpenStreetMap.jl @@ -7,6 +7,7 @@ module OpenStreetMap import LightXML +import LibExpat import Winston import Graphs import Compat diff --git a/src/buildings.jl b/src/buildings.jl index 1cbfc25..b669bff 100644 --- a/src/buildings.jl +++ b/src/buildings.jl @@ -2,88 +2,6 @@ ### MIT License ### ### Copyright 2014 ### -### Create list of all buildings in OSM file ### -function getBuildings(street_map::LightXML.XMLDocument) - - xroot = LightXML.root(street_map) - ways = LightXML.get_elements_by_tagname(xroot, "way") - - buildings = Dict{Int,Building}() - - for way in ways - - if LightXML.has_attribute(way, "visible") - if LightXML.attribute(way, "visible") == "false" - # Visible=false indicates historic data, which we will ignore - continue - end - end - - # Search for tag with k="building" - for tag in LightXML.child_elements(way) - if LightXML.name(tag) == "tag" - if LightXML.has_attribute(tag, "k") - k = LightXML.attribute(tag, "k") - if k == "building" - class = "" - if LightXML.has_attribute(tag, "v") - class = LightXML.attribute(tag, "v") - end - - id = int(LightXML.attribute(way, "id")) - buildings[id] = getBuildingData(way, class) - break - end - end - end - end - end - - return buildings -end - -### Gather highway data from OSM element ### -function getBuildingData(building::LightXML.XMLElement, class::String="") - nodes = Int[] - class = "" - building_name = "" - - # Get way ID - # id = int64(LightXML.attribute(building, "id")) - - # Iterate over all "label" fields - for label in LightXML.child_elements(building) - - if LightXML.name(label) == "tag" && LightXML.has_attribute(label, "k") - k = LightXML.attribute(label, "k") - - # If not yet set, find the class type - if isempty(class) && k == "building" - if LightXML.has_attribute(label, "v") - class = LightXML.attribute(label, "v") - continue - end - end - - # Check if building has a name - if isempty(building_name) && k == "name" - if LightXML.has_attribute(label, "v") - building_name = LightXML.attribute(label, "v") - continue - end - end - end - - # Collect associated nodes - if LightXML.name(label) == "nd" && LightXML.has_attribute(label, "ref") - push!(nodes, int64(LightXML.attribute(label, "ref"))) - continue - end - end - - return Building(class, building_name, nodes) -end - ### Classify buildings ### function classify(buildings::Dict{Int,Building}) bdgs = Dict{Int,Int}() diff --git a/src/features.jl b/src/features.jl index 9c55338..9ded828 100644 --- a/src/features.jl +++ b/src/features.jl @@ -2,76 +2,6 @@ ### MIT License ### ### Copyright 2014 ### -### Create list of all features in OSM file ### -function getFeatures(street_map::LightXML.XMLDocument) - - xroot = LightXML.root(street_map) - nodes = LightXML.get_elements_by_tagname(xroot, "node") - features = Dict{Int,Feature}() - - for node in nodes - - if LightXML.has_attribute(node, "visible") && - LightXML.attribute(node, "visible") == "false" - # Visible=false indicates historic data, which we will ignore - continue - end - - # Search for tag giving feature information - for tag in LightXML.child_elements(node) - if LightXML.name(tag) == "tag" && LightXML.has_attribute(tag, "k") - k = LightXML.attribute(tag, "k") - if haskey(FEATURE_CLASSES, k) - id = int(LightXML.attribute(node, "id")) - features[id] = getFeatureData(node) - break - end - end - end - end - - return features -end - -### Gather feature data from OSM element ### -function getFeatureData(node::LightXML.XMLElement) - - class = "" - detail = "" - feature_name = "" - - # Get node ID - # id = int64(LightXML.attribute(node, "id")) - - # Iterate over all "label" fields - for label in LightXML.child_elements(node) - - if LightXML.name(label) == "tag" && LightXML.has_attribute(label, "k") - k = LightXML.attribute(label, "k") - - # If empty, find the class type - if isempty(class) && LightXML.has_attribute(label, "v") - v = LightXML.attribute(label, "v") - if haskey(FEATURE_CLASSES, k) - class = k - detail = v - continue - end - end - - # Check if feature has a name - if isempty(feature_name) && k == "name" - if LightXML.has_attribute(label, "v") - feature_name = LightXML.attribute(label, "v") - continue - end - end - end - end - - return Feature(class, detail, feature_name) -end - ### Classify features ### function classify(features::Dict{Int,Feature}) feats = Dict{Int,Int}() diff --git a/src/highways.jl b/src/highways.jl index 561ee6b..cccb6a1 100644 --- a/src/highways.jl +++ b/src/highways.jl @@ -2,166 +2,6 @@ ### MIT License ### ### Copyright 2014 ### -### Create list of all highways in OSM file ### -function getHighways(street_map::LightXML.XMLDocument) - - xroot = LightXML.root(street_map) - ways = LightXML.get_elements_by_tagname(xroot, "way") - - highways = Dict{Int,Highway}() - - for way in ways - - if LightXML.has_attribute(way, "visible") - if LightXML.attribute(way, "visible") == "false" - # Visible=false indicates historic data, which we will ignore - continue - end - end - - # Search for tag with k="highway" - for tag in LightXML.child_elements(way) - if LightXML.name(tag) == "tag" - if LightXML.has_attribute(tag, "k") - k = LightXML.attribute(tag, "k") - if k == "highway" - if LightXML.has_attribute(tag, "v") - class = LightXML.attribute(tag, "v") - - # Note: Highways marked "services" are not traversable - if class != "services" - id = int(LightXML.attribute(way, "id")) - highways[id] = getHighwayData(way, class) - end - end - break - end - end - end - end - - end - - return highways -end - -### Gather highway data from OSM element ### -function getHighwayData(highway::LightXML.XMLElement, class::String="") - oneway = false - oneway_override = false # Flag to indicate if oneway is forced to false - oneway_reverse = false # Flag to indicate nodes need to be reversed - nodes = Int[] - road_name = "" - cycleway = "" - sidewalk = "" - bicycle = "" - lanes = 1 - - # Get way ID - # id = int(LightXML.attribute(highway, "id")) - - # Iterate over all "label" fields - for label in LightXML.child_elements(highway) - - if LightXML.name(label) == "tag" && LightXML.has_attribute(label, "k") - k = LightXML.attribute(label, "k") - - # If empty, find the class type - if isempty(class) && k == "highway" - if LightXML.has_attribute(label, "v") - class = LightXML.attribute(label, "v") - if !oneway_override - if class == "motorway" || class == "motorway_link" - # Motorways default to oneway - oneway = true - end - end - continue - end - end - - # Check if street is oneway - if k == "oneway" - if LightXML.has_attribute(label, "v") - v = LightXML.attribute(label, "v") - if v == "yes" || v == "true" || v == "1" - if !oneway_override - oneway = true - end - elseif v == "no" || v == "false" || v == "0" - oneway = false - oneway_override = true - elseif v == "-1" - oneway = true - oneway_reverse = true - end - continue - end - end - - # Roundabouts are oneway - if k == "junction" - if LightXML.has_attribute(label, "v") - v = LightXML.attribute(label, "v") - if v == "roundabout" && !oneway_override - oneway = true - end - continue - end - end - - # Check if street has a name - if isempty(road_name) && k == "name" - if LightXML.has_attribute(label, "v") - road_name = LightXML.attribute(label, "v") - continue - end - end - - # Check for cycleway - if isempty(cycleway) && k == "cycleway" - if LightXML.has_attribute(label, "v") - cycleway = LightXML.attribute(label, "v") - continue - end - end - - # Check for sidewalk - if isempty(sidewalk) && k == "sidewalk" - if LightXML.has_attribute(label, "v") - sidewalk = LightXML.attribute(label, "v") - continue - end - end - - # Check for number of lanes - if lanes == 1 && k == "lanes" - if LightXML.has_attribute(label, "v") - lane_str = LightXML.attribute(label, "v") - if length(lane_str) == 1 && '1' <= lane_str[1] <= '9' - lanes = int(lane_str) - end - continue - end - end - end - - # Collect associated nodes - if LightXML.name(label) == "nd" && LightXML.has_attribute(label, "ref") - push!(nodes, int64(LightXML.attribute(label, "ref"))) - continue - end - end - - # If road is marked as backwards (should be rare), reverse the node order - if oneway_reverse - reverse!(nodes) - end - - - return Highway(class, lanes, oneway, sidewalk, cycleway, bicycle, road_name, nodes) -end - ### Classify highways for cars ### function roadways(highways::Dict{Int,Highway}) roads = Dict{Int,Int}() diff --git a/src/nodes.jl b/src/nodes.jl index 4a4e2b9..7b4c3f3 100644 --- a/src/nodes.jl +++ b/src/nodes.jl @@ -2,32 +2,6 @@ ### MIT License ### ### Copyright 2014 ### -### Get dictionary of all nodes from an OSM XML file ### -function getNodes(street_map::LightXML.XMLDocument) - - xroot = LightXML.root(street_map) - all_nodes = LightXML.get_elements_by_tagname(xroot, "node") - nodes = Dict{Int,LLA}() - - for node in all_nodes - - if LightXML.has_attribute(node, "visible") - if LightXML.attribute(node, "visible") == "false" - # Visible=false indicates historic data, which we will ignore - continue - end - end - - id = int(LightXML.attribute(node, "id")) - lat = float(LightXML.attribute(node, "lat")) - lon = float(LightXML.attribute(node, "lon")) - - nodes[id] = LLA(lat, lon) - end - - return nodes -end - ### Find the nearest node to a given location ### function nearestNode{T<:Union(ENU,ECEF)}(nodes::Dict{Int,T}, loc::T) min_dist = Inf diff --git a/src/parseMap.jl b/src/parseMap.jl index e6e0678..ae4b1c4 100644 --- a/src/parseMap.jl +++ b/src/parseMap.jl @@ -2,37 +2,216 @@ ### MIT License ### ### Copyright 2014 ### -### Parse the data from an openStreetMap XML file ### -function parseMapXML(filename::String) +type OSMattributes + oneway::Bool + oneway_override::Bool + oneway_reverse::Bool + visible::Bool + lanes::Int - # Parse the file - street_map = LightXML.parse_file(filename) + name::UTF8String + class::UTF8String + detail::UTF8String + cycleway::UTF8String + sidewalk::UTF8String + bicycle::UTF8String - if LightXML.name(LightXML.root(street_map)) != "osm" - throw(ArgumentError("Not an OpenStreetMap datafile.")) + # XML elements + element::Symbol # :None, :Node, :Way, :Tag[, :Relation] + parent::Symbol # :Building, :Feature, :Highway + way_nodes::Vector{Int} # for buildings and highways + + id::Int # Uninitialized + lat::Float64 # Uninitialized + lon::Float64 # Uninitialized + + OSMattributes() = new(false,false,false,false,1, + "","","","","","",:None,:None,[]) +end + +type OSMdata + nodes::Dict{Int,LLA} + highways::Dict{Int,Highway} + buildings::Dict{Int,Building} + features::Dict{Int,Feature} + attr::OSMattributes + OSMdata() = new(Dict(),Dict(),Dict(),Dict(),OSMattributes()) +end + +function reset_attributes!(osm::OSMattributes) + osm.oneway = osm.oneway_override = osm.oneway_reverse = osm.visible = false + osm.lanes = 1 + osm.name = osm.class = osm.detail = osm.cycleway = osm.sidewalk = osm.bicycle = "" + osm.element = osm.parent = :None + empty!(osm.way_nodes) +end + +### PARSE XML ELEMENTS ### + +function parse_node(attr::OSMattributes, attrs_in::Dict{String,String}) + attr.visible = true + attr.element = :Node + if haskey(attrs_in, "id") + attr.id = int(attrs_in["id"]) + attr.lat = float(attrs_in["lat"]) + attr.lon = float(attrs_in["lon"]) end +end - return street_map +function parse_way(attr::OSMattributes, attrs_in::Dict{String,String}) + attr.visible = true + attr.element = :Way + if haskey(attrs_in, "id") + attr.id = int(attrs_in["id"]) + end +end + +function parse_nd(attr::OSMattributes, attrs_in::Dict{String,String}) + if haskey(attrs_in, "ref") + push!(attr.way_nodes, int64(attrs_in["ref"])) + end +end + +function parse_tag(attr::OSMattributes, attrs_in::Dict{String,String}) + if haskey(attrs_in, "k") && haskey(attrs_in, "v") + k, v = attrs_in["k"], attrs_in["v"] + if k == "name" + if isempty(attr.name) + attr.name = v # applicable to roads (highways), buildings, features + end + elseif attr.element == :Way + if k == "building" + parse_building(attr, v) + else + parse_highway(attr, k, v) # for other highway tags + end + elseif attr.element == :Node + if haskey(FEATURE_CLASSES, k) + parse_feature(attr, k, v) + end + end + else + # Nothing to be done here? + end end -function getOSMData(filename::String; nodes=false, highways=false, buildings=false, features=false) - street_map = parseMapXML(filename) +### PARSE OSM ENTITIES ### - if nodes - nodes = getNodes(street_map) +function parse_highway(attr::OSMattributes, k::String, v::String) + if k == "highway" + attr.class = v + if v == "services" # Highways marked "services" are not traversable + attr.visible = false + return + end + if v == "motorway" || v == "motorway_link" + attr.oneway = true # motorways default to oneway + end + elseif k == "oneway" + if v == "-1" + attr.oneway = true + attr.oneway_reverse = true + elseif v == "false" || v == "no" || v == "0" + attr.oneway = false + attr.oneway_override = true + elseif v == "true" || v == "yes" || v == "1" + attr.oneway = true + end + elseif k == "junction" && v == "roundabout" + attr.oneway = true + elseif k == "cycleway" + attr.cycleway = v + elseif k == "sidewalk" + attr.sidewalk = v + elseif k == "bicycle" + attr.bicycle = v + elseif k == "lanes" && length(v)==1 && '1' <= v[1] <= '9' + attr.lanes = int(v) + else + return end + attr.parent = :Highway +end - if highways - highways = getHighways(street_map) +function parse_building(attr::OSMattributes, v::String) + attr.parent = :Building + if isempty(attr.class) + attr.class = v end +end + +function parse_feature(attr::OSMattributes, k::String, v::String) + attr.parent = :Feature + attr.class = k + attr.detail = v +end - if buildings - buildings = getBuildings(street_map) +### LibExpat.XPStreamHandlers ### + +function parseElement(handler::LibExpat.XPStreamHandler, name::String, attrs_in::Dict{String,String}) + attr = handler.data.attr::OSMattributes + if attr.visible + if name == "nd" + parse_nd(attr, attrs_in) + elseif name == "tag" + parse_tag(attr, attrs_in) + end + elseif !(haskey(attrs_in, "visible") && attrs_in["visible"] == "false") + if name == "node" + parse_node(attr, attrs_in) + elseif name == "way" + parse_way(attr, attrs_in) + end + end # no work done for "relations" yet +end + +function collectValues(handler::LibExpat.XPStreamHandler, name::String) + # println(typeof(name)) + osm = handler.data::OSMdata + attr = osm.attr::OSMattributes + if name == "node" + osm.nodes[attr.id] = LLA(attr.lat, attr.lon) + if attr.parent == :Feature + osm.features[attr.id] = Feature(attr.class, attr.detail, attr.name) + end + elseif name == "way" + if attr.parent == :Building + osm.buildings[attr.id] = Building(attr.class, attr.name, copy(attr.way_nodes)) + elseif attr.parent == :Highway + if attr.oneway_reverse + reverse!(attr.way_nodes) + end + osm.highways[attr.id] = Highway(attr.class, attr.lanes, + (attr.oneway && !attr.oneway_override), + attr.sidewalk, attr.cycleway, attr.bicycle, + attr.name, copy(attr.way_nodes)) + end + else # :Tag or :Nd (don't reset values!) + return end + reset_attributes!(osm.attr) +end + +### Parse the data from an openStreetMap XML file ### +function parseMapXML(filename::String) + + # Parse the file + street_map = LightXML.parse_file(filename) - if features - features = getFeatures(street_map) + if LightXML.name(LightXML.root(street_map)) != "osm" + throw(ArgumentError("Not an OpenStreetMap datafile.")) end - return nodes, highways, buildings, features + return street_map +end + +function getOSMData(filename::String; args...) + osm = OSMdata() + + callbacks = LibExpat.XPCallbacks() + callbacks.start_element = parseElement + callbacks.end_element = collectValues + + LibExpat.parsefile(filename, callbacks, data=osm; args...) + osm.nodes, osm.highways, osm.buildings, osm.features end diff --git a/src/types.jl b/src/types.jl index a85b6e6..1c41a36 100644 --- a/src/types.jl +++ b/src/types.jl @@ -69,37 +69,37 @@ end ### Point in Latitude-Longitude-Altitude (LLA) coordinates # Used to store node data in OpenStreetMap XML files type LLA - lat - lon - alt + lat::Float64 + lon::Float64 + alt::Float64 end -LLA(lat, lon) = LLA(lat, lon, 0) +LLA(lat, lon) = LLA(lat, lon, 0.0) ### Point in Earth-Centered-Earth-Fixed (ECEF) coordinates # Global cartesian coordinate system rotating with the Earth type ECEF - x - y - z + x::Float64 + y::Float64 + z::Float64 end ### Point in East-North-Up (ENU) coordinates # Local cartesian coordinate system # Linearized about a reference point type ENU - east - north - up + east::Float64 + north::Float64 + up::Float64 end -ENU(x, y) = ENU(x, y, 0) +ENU(x, y) = ENU(x, y, 0.0) ### Helper for creating other point types type XYZ - x - y - z + x::Float64 + y::Float64 + z::Float64 end -XY(x, y) = XYZ(x, y, 0) +XY(x, y) = XYZ(x, y, 0.0) LLA(xyz::XYZ) = LLA(xyz.y, xyz.x, xyz.z) ENU(xyz::XYZ) = ENU(xyz.x, xyz.y, xyz.z) @@ -115,14 +115,14 @@ getY(enu::ENU) = enu.north # Standardized coordinate system for Earth # Global ellipsoidal reference surface type WGS84 - a - b - e - e_prime + a::Float64 + b::Float64 + e::Float64 + e_prime::Float64 N function WGS84() - a = 6378137 # Semi-major axis + a = 6378137.0 # Semi-major axis b = 6356752.31424518 # Semi-minor axis e = sqrt((a*a - b*b) / (a*a)) # Eccentricity e_prime = sqrt((a*a - b*b) / (b*b)) # Second eccentricity diff --git a/test/classes.jl b/test/classes.jl index 6a895d7..7bba277 100644 --- a/test/classes.jl +++ b/test/classes.jl @@ -7,7 +7,7 @@ using Base.Test MAP_FILENAME = "tech_square.osm" # Load and crop map to file bounds -nodes, hwys, builds, feats = getOSMData(MAP_FILENAME, nodes=true, highways=true, buildings=true, features=true) +nodes, hwys, builds, feats = getOSMData(MAP_FILENAME) bounds = getBounds(parseMapXML(MAP_FILENAME)) cropMap!(nodes, bounds, highways=hwys, buildings=builds, features=feats, delete_nodes=true) diff --git a/test/crop_map.jl b/test/crop_map.jl index 36a61ac..c4a94f2 100644 --- a/test/crop_map.jl +++ b/test/crop_map.jl @@ -9,15 +9,13 @@ import OpenStreetMap: Bounds, LLA, aspectRatio, getX, getY, inBounds MAP_FILENAME = "tech_square.osm" -nodes, hwys, builds, feats = getOSMData(MAP_FILENAME, nodes=true, highways=true, buildings=true, features=true) - bounds = Bounds(42.3637, 42.3655, -71.0919, -71.0893) bounds_ENU = lla2enu(bounds) @test_approx_eq_eps aspectRatio(bounds) aspectRatio(bounds_ENU) 5e-3 +nodes, hwys, builds, feats = getOSMData(MAP_FILENAME) cropMap!(nodes, bounds, highways=hwys, buildings=builds, features=feats, delete_nodes=true) - @test length(nodes) == 198 @test length(hwys) == 16 @test length(builds) == 1 diff --git a/test/plots.jl b/test/plots.jl index 1000cc6..ee3917c 100644 --- a/test/plots.jl +++ b/test/plots.jl @@ -8,7 +8,7 @@ import Winston MAP_FILENAME = "tech_square.osm" # Load and crop map to file bounds -nodesLLA, hwys, builds, feats = getOSMData(MAP_FILENAME, nodes=true, highways=true, buildings=true, features=true) +nodesLLA, hwys, builds, feats = getOSMData(MAP_FILENAME) boundsLLA = getBounds(parseMapXML(MAP_FILENAME)) cropMap!(nodesLLA, boundsLLA, highways=hwys, buildings=builds, features=feats, delete_nodes=true) diff --git a/test/read_data.jl b/test/read_data.jl index 440c27e..09549ed 100644 --- a/test/read_data.jl +++ b/test/read_data.jl @@ -11,7 +11,7 @@ if !isfile(MAP_FILENAME) download(url, MAP_FILENAME) end -nodes, hwys, builds, feats = getOSMData(MAP_FILENAME, nodes=true, highways=true, buildings=true, features=true) +nodes, hwys, builds, feats = getOSMData(MAP_FILENAME) @test length(nodes) == 1410 @test length(hwys) == 55 diff --git a/test/routes.jl b/test/routes.jl index 3efea7b..4414629 100644 --- a/test/routes.jl +++ b/test/routes.jl @@ -8,7 +8,7 @@ using Graphs MAP_FILENAME = "tech_square.osm" # Load and crop map to file bounds -nodes, hwys, builds, feats = getOSMData(MAP_FILENAME, nodes=true, highways=true, buildings=true, features=true) +nodes, hwys, builds, feats = getOSMData(MAP_FILENAME) bounds = getBounds(parseMapXML(MAP_FILENAME)) cropMap!(nodes, bounds, highways=hwys, buildings=builds, features=feats, delete_nodes=true)