Skip to content

Commit

Permalink
update all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gboeing committed May 26, 2020
1 parent c41bf0f commit 3788c44
Show file tree
Hide file tree
Showing 27 changed files with 3,045 additions and 3,866 deletions.
477 changes: 390 additions & 87 deletions notebooks/00-osmnx-features-demo.ipynb

Large diffs are not rendered by default.

310 changes: 123 additions & 187 deletions notebooks/01-overview-osmnx.ipynb

Large diffs are not rendered by default.

716 changes: 0 additions & 716 deletions notebooks/02-example-osm-to-shapefile.ipynb

This file was deleted.

444 changes: 444 additions & 0 deletions notebooks/02-routing-speed-time.ipynb

Large diffs are not rendered by default.

312 changes: 0 additions & 312 deletions notebooks/03-example-osm-place-network.ipynb

This file was deleted.

389 changes: 389 additions & 0 deletions notebooks/03-graph-place-queries.ipynb

Large diffs are not rendered by default.

577 changes: 0 additions & 577 deletions notebooks/04-example-simplify-network.ipynb

This file was deleted.

501 changes: 501 additions & 0 deletions notebooks/04-simplify-graph-consolidate-nodes.ipynb

Large diffs are not rendered by default.

228 changes: 0 additions & 228 deletions notebooks/05-example-save-load-networks-shapes.ipynb

This file was deleted.

204 changes: 204 additions & 0 deletions notebooks/05-save-load-networks.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Save/load street network models to/from disk\n",
"\n",
"Author: [Geoff Boeing](https://geoffboeing.com/)\n",
"\n",
" - [Overview of OSMnx](http://geoffboeing.com/2016/11/osmnx-python-street-networks/)\n",
" - [GitHub repo](https://github.com/gboeing/osmnx)\n",
" - [Examples, demos, tutorials](https://github.com/gboeing/osmnx-examples)\n",
" - [Documentation](https://osmnx.readthedocs.io/en/stable/)\n",
" - [Journal article/citation](http://geoffboeing.com/publications/osmnx-complex-street-networks/)\n",
" \n",
"This notebook demonstrates how to save networks to disk as shapefiles, geopackages, graphml, and xml, and how to load an OSMnx-created network from a graphml file."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'0.13.0'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import osmnx as ox\n",
"%matplotlib inline\n",
"ox.config(log_console=True, use_cache=True)\n",
"ox.__version__"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# get a network\n",
"place = 'Piedmont, California, USA'\n",
"G = ox.graph_from_place(place, network_type='drive')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Shapefiles and GeoPackages for GIS"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# save graph as a shapefile\n",
"ox.save_graph_shapefile(G, filepath='./data/piedmont')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# save graph as a geopackage\n",
"ox.save_graph_geopackage(G, filepath='./data/piedmont.gpkg')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## GraphML files for saving network and preserving topological detail"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# save/load graph as a graphml file: this is the best way to save your model\n",
"# for subsequent work later\n",
"filepath = './data/piedmont.graphml'\n",
"ox.save_graphml(G, filepath)\n",
"G = ox.load_graphml(filepath)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# if you want to work with your model in gephi, use gephi compatibility mode\n",
"ox.save_graphml(G, filepath=filepath, gephi=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## SVG file to work with in Adobe Illustrator"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# save street network as SVG\n",
"fig, ax = ox.plot_graph(G, show=False, save=True, \n",
" filename='piedmont', file_format='svg')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save points of interest or building footprints"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# get all amenities and save as a geopackage via geopandas\n",
"gdf = ox.pois_from_place(place, tags={'amenity':True})\n",
"gdf = gdf.apply(lambda c: c.astype(str) if c.name != 'geometry' else c, axis=0)\n",
"gdf.to_file('./data/pois.gpkg', driver='GPKG')"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# get all building footprints and save as a geopackage via geopandas\n",
"gdf = ox.footprints_from_place(place)\n",
"gdf = gdf.apply(lambda c: c.astype(str) if c.name != 'geometry' else c, axis=0)\n",
"gdf.to_file('./data/building_footprints.gpkg', driver='GPKG')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Save .osm XML files\n",
"\n",
"To save your graph to disk as a .osm formatted xml file, ensure that you created the graph with `ox.settings.all_oneway=True` for `save_graph_xml` to work properly."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# save graph to disk as .osm xml file\n",
"ox.config(all_oneway=True, log_console=True, use_cache=True)\n",
"G = ox.graph_from_place('Piedmont, California, USA', network_type='drive')\n",
"ox.save_graph_xml(G, filepath='./data/piedmont.osm')"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python (ox)",
"language": "python",
"name": "ox"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 3788c44

Please sign in to comment.