Skip to content

Commit

Permalink
add custom_filter union example
Browse files Browse the repository at this point in the history
  • Loading branch information
gboeing committed Dec 18, 2024
1 parent 9d0a978 commit 9fab273
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions notebooks/08-custom-filters-infrastructure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,42 @@
"fig, ax = ox.plot.plot_graph(G, node_size=0, edge_color=\"w\", edge_linewidth=0.2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Unions in custom filters\n",
"\n",
"You can pass a list via `custom_filter` to perform a union of multiple queries (i.e., an \"or\" operation)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# add useful OSM tags to the default list, to retain them\n",
"ox.settings.useful_tags_way.extend([\"cycleway\", \"cycleway:left\", \"cycleway:right\"])\n",
"place = \"Bologna, Italia\"\n",
"\n",
"# get all ways with a 'cycleway:left'\n",
"cf1 = '[\"cycleway:left\"]'\n",
"G1 = ox.graph.graph_from_place(place, custom_filter=cf1, retain_all=True)\n",
"print(len(G1))\n",
"\n",
"# get all ways with a 'cycleway:right' tag\n",
"cf2 = '[\"cycleway:right\"]'\n",
"G2 = ox.graph.graph_from_place(place, custom_filter=cf2, retain_all=True)\n",
"print(len(G2))\n",
"\n",
"# union: get all ways with either a 'cycleway:right' or 'cycleway:left' tag\n",
"cf = [cf1, cf2]\n",
"ox.settings.useful_tags_way.extend([cf1, cf2])\n",
"G = ox.graph.graph_from_place(place, custom_filter=cf, retain_all=True)\n",
"print(len(G))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 9fab273

Please sign in to comment.