# Examples¶

The following example walks through a sample workflow using OpenStreetMap.jl. This page does not cover all functionality available in OpenStreetMap.jl, but hopefully helps new users get started quickly. See also “test/examples.jl” for all of these examples together in a single Julia file.

Read data from an OSM XML file:

```nodesLLA, highways, buildings, features = getOSMData(MAP_FILENAME)

println("Number of nodes: \$(length(nodesLLA))")
println("Number of highways: \$(length(highways))")
println("Number of buildings: \$(length(buildings))")
println("Number of features: \$(length(features))")
```

Define map boundary:

```boundsLLA = Bounds(42.365, 42.3675, -71.1, -71.094)
```

Define reference point and convert to ENU coordinates:

```lla_reference = center(boundsLLA)
nodes = ENU(nodesLLA, lla_reference)
bounds = ENU(boundsLLA, lla_reference)
```

Crop map to boundary:

```cropMap!(nodes, bounds, highways=highways, buildings=buildings, features=features, delete_nodes=false)
```

Find highway intersections:

```inters = findIntersections(hwys)

println("Found \$(length(inters)) intersections.")
```

Extract map components and classes:

```roads = roadways(hwys)
peds = walkways(hwys)
cycles = cycleways(hwys)
bldg_classes = classify(builds)
feat_classes = classify(feats)
```

Convert map nodes to East-North-Up (ENU) coordinates:

```reference = center(bounds)
nodesENU = ENU(nodes, reference)
boundsENU = ENU(bounds, reference)
```

Extract highway classes (note that OpenStreetMap calls paths of any form “highways”):

```roads = roadways(highways)
peds = walkways(highways)
cycles = cycleways(highways)
bldg_classes = classify(buildings)
feat_classes = classify(features)
```

Find all highway intersections:

```intersections = findIntersections(highways)
```

Segment only specific levels of roadways (e.g., freeways (class 1) through residential streets (class 6)):

```segments = segmentHighways(nodes, highways, intersections, roads, Set(1:6))
```

Create transportation network from highway segments:

```network = createGraph(segments, intersections)
```

Compute the shortest and fastest routes from point A to B:

```loc_start = ENU(-5000, 5500, 0)
loc_end = ENU(5500, -4000, 0)

node0 = nearestNode(nodes, loc_start, network)
node1 = nearestNode(nodes, loc_end, network)
shortest_route, shortest_distance = shortestRoute(network, node0, node1)

fastest_route, fastest_time = fastestRoute(network, node0, node1)
fastest_distance = distance(nodes, fastest_route)

println("Shortest route: \$(shortest_distance) m  (Nodes: \$(length(shortest_route)))")
println("Fastest route: \$(fastest_distance) m  Time: \$(fastest_time/60) min  (Nodes: \$(length(fastest_route)))")
```

Display the shortest and fastest routes:

```fignum_shortest = plotMap(nodesENU, highways=hwys, bounds=boundsENU, roadways=roads, route=shortest_route)

```

Extract Nodes near to (within range) our route’s starting location:

```loc0 = nodes[node0]
local_indices = nodesWithinRange(filteredENU, loc0, 100.0)
```

Identify Driving Catchment Areas (within limit):

```start_index = nearestNode(filteredENU, loc0)
node_indices, distances = nodesWithinDrivingDistance(network, local_indices, 300.0)
```

Alternatively, switch to catchment areas based on driving time, rather than distance:

```node_indices, distances = nodesWithinDrivingTime(network, local_indices, 50.0)
```

Display classified roadways, buildings, and features:

```fignum = plotMap(nodes,
highways=highways,
buildings=buildings,
features=features,
bounds=bounds,
width=500,
feature_classes=feat_classes,
building_classes=bldg_classes,