diff --git a/README.md b/README.md index ceb465b..ee1f279 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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") @@ -45,17 +45,16 @@ 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") ``` @@ -63,12 +62,17 @@ Conda.runconda(`install folium -c conda-forge`) ```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 @@ -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. - - diff --git a/plot_sample_with_folium.png b/plot_sample_with_folium.png new file mode 100644 index 0000000..2d50125 Binary files /dev/null and b/plot_sample_with_folium.png differ diff --git a/samples/plotting_with_folium.jl b/samples/plotting_with_folium.jl index 175419e..31fe1c4 100644 --- a/samples/plotting_with_folium.jl +++ b/samples/plotting_with_folium.jl @@ -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)
[information from the
.e
and
.w
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
Lattitude: $(lla.lat)\n
Longitude: $(lla.lon)
[information from the
.node
field] " @@ -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 \ No newline at end of file