Skip to content

Commit

Permalink
upds
Browse files Browse the repository at this point in the history
  • Loading branch information
pszufe committed Mar 8, 2024
1 parent c064469 commit 1f87fe5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
32 changes: 17 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# OpenStreetMapX.jl

* Package for spatial analysis, simulation and visualization of Open Street Map data
* Package for spatial analysis, simulation and visualization of Open Street Map data
* The plotting functionality is provided via a separate package [`OpenStreetMapXPlot.jl`](https://github.com/pszufe/OpenStreetMapXPlot.jl)
* OSM file manipulation, POI extraction functionality and support for walkability indexes is provided by a package [`OSMToolset.jl`](https://github.com/pszufe/OSMToolset.jl)
* OSM file manipulation, point-of-interest (POI) extraction functionality and support for walkability indexes is provided by a package [`OSMToolset.jl`](https://github.com/pszufe/OSMToolset.jl)

The goal of this package is to provide a backbone for multi-agent modelling and simulation of cities.
The goal of this package is to provide a backbone for multi-agent modelling and simulation of cities.

The package can parse `*.osm` and `*.pbf` (contributed by [@blegat](https://github.com/blegat/)) files and generate a Graphs.jl representation along the metadata.

Expand Down Expand Up @@ -36,7 +36,7 @@ The package can parse `*.osm` and `*.pbf` (contributed by [@blegat](https://git

## Installation

The current version uses at least Julia 1.6. However older versions will work with Julia 1.0.
The current version uses at least Julia 1.6.

```julia
using Pkg; Pkg.add("OpenStreetMapX")
Expand All @@ -45,30 +45,34 @@ using Pkg; Pkg.add("OpenStreetMapX")
In order to plot the maps we recommend two tools:

- rendering the maps yourself with PyPlot or Plots.jl with backend - use the [`OpenStreetMapXPlot.jl`](https://github.com/pszufe/OpenStreetMapXPlot.jl) package
- extracting points-of-interests (POIs) from maps (such as restaurants, parks, schools, hospitals, grocery stores) - use the [`OSMToolset.jl`](https://github.com/pszufe/OSMToolset.jl) package
- rendering the maps with Leaflet.jl - use the Python folium package (examples can be found in the [tutorial](https://pszufe.github.io/OpenStreetMapX_Tutorial/) and the [manual](https://pszufe.github.io/OpenStreetMapX.jl/stable))

In order to install all plotting backends please run the commands below:
```julia
using Pkg
pkg"add Plots"
pkg"add PyPlot"
pkg"add OpenStreetMapXPlot"
pkg"add Conda"
using Conda
Conda.runconda(`install folium -c conda-forge`)
Pkg.add(["Plots", "OpenStreetMapXPlot", "CondaPkg"])
using CondaPkg
CondaPkg.add_channel("conda-forge")
CondaPkg.add("folium")
```


## Usage

```julia
using OpenStreetMapX
map_data = get_map_data("/home/ubuntu/mymap.osm");
filename = OpenStreetMapX.sample_map_path()
map_data = get_map_data(filename);

println("The map contains $(length(map_data.nodes)) nodes")
```

See the [samples](https://github.com/pszufe/OpenStreetMapX.jl/tree/master/samples) directory for a more complete example and have a look at [`OpenStreetMapXPlot.jl`](https://github.com/pszufe/OpenStreetMapXPlot.jl) for a route plotting.

![Sample plot](plot_sample_with_folium.png)

The picture above has been generated with `folium` - for source code see the [samples](https://github.com/pszufe/OpenStreetMapX.jl/tree/master/samples) directory for a more complete example and have a look at [`OpenStreetMapXPlot.jl`](https://github.com/pszufe/OpenStreetMapXPlot.jl) for a route plotting.


## Obtaining map data

Expand All @@ -93,9 +97,7 @@ Compared to the original package major changes include among many others:
- New `Graphs.jl` is used for map data storage
- Several changes with routing algorithm (currently finding a route in a 1 million people city takes around 150ms)
- Added support for using Google Maps API for routing
- Data structure adjustment to make the library more suitable to run simulations of cities.
- Data structure adjustment to make the library more suitable to run simulations of cities.
- `Plots.jl` with GR is used as backend for map vizualization (via a separate package [`OpenStreetMapXPlot.jl`](https://github.com/pszufe/OpenStreetMapXPlot.jl))

The creation of some parts of this source code was partially financed by research project supported by the Ontario Centres of Excellence ("OCE") under Voucher for Innovation and Productivity (VIP) program, OCE Project Number: 30293, project name: "Agent-based simulation modelling of out-of-home advertising viewing opportunity conducted in cooperation with Environics Analytics of Toronto, Canada. </sup>


Binary file added plot_sample_with_folium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 16 additions & 9 deletions samples/plotting_with_folium.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
using OpenStreetMapX, Graphs, PyCall
using OpenStreetMapX, Graphs, PythonCall

# This code assumes that folium has benn installed
# using CondaPkg
# CondaPkg.add_channel("conda-forge")
# CondaPkg.add("folium")

using OpenStreetMapX, Graphs, PythonCall

function plot_map(m::MapData, filename::AbstractString; tiles="Stamen Toner" )
function plot_map(m::MapData; tiles="Cartodb Positron")
MAP_BOUNDS = [ ( m.bounds.min_y, m.bounds.min_x), ( m.bounds.max_y, m.bounds.max_x) ]
flm = pyimport("folium")
m_plot = flm.Map(tiles=tiles)
flm = PythonCall.pyimport("folium")
m_plot = flm.Map(;tiles)
for e in edges(m.g)
info = "Edge from: $(e.src) to $(e.dst)<br>[information from the <pre>.e</pre> and <pre>.w</pre> fields] "
flm.PolyLine( (latlon(m,e.src), latlon(m,e.dst)),
color="brown", weight=4, opacity=1).add_to(m_plot)
end



for n in keys(m.nodes)
lla = LLA(m.nodes[n],m.bounds)
info = "Node: $(n)\n<br>Lattitude: $(lla.lat)\n<br>Longitude: $(lla.lon)<br>[information from the <pre>.node</pre> field] "
Expand Down Expand Up @@ -45,15 +51,16 @@ function plot_map(m::MapData, filename::AbstractString; tiles="Stamen Toner" )
).add_to(m_plot)
end


MAP_BOUNDS = [( m.bounds.min_y, m.bounds.min_x),( m.bounds.max_y, m.bounds.max_x)]
MAP_BOUNDS = (( m.bounds.min_y, m.bounds.min_x),( m.bounds.max_y, m.bounds.max_x))
flm.Rectangle(MAP_BOUNDS, color="black",weight=4).add_to(m_plot)
m_plot.fit_bounds(MAP_BOUNDS)
m_plot.save(filename)
m_plot
end

pth = joinpath(dirname(pathof(OpenStreetMapX)),"..","test","data","reno_east3.osm")
pth = OpenStreetMapX.sample_map_path()

m2 = OpenStreetMapX.get_map_data(pth,use_cache = false, trim_to_connected_graph=true);

plot_map(m2, "mymap.html")
m_p = plot_map(m2) # this can be displayed in a Jupyter Notebook

m_p.save("mymap.html") # or saved to a file

0 comments on commit 1f87fe5

Please sign in to comment.