diff --git a/notebooks/08-custom-filters-infrastructure.ipynb b/notebooks/08-custom-filters-infrastructure.ipynb index a316a8c..576530c 100644 --- a/notebooks/08-custom-filters-infrastructure.ipynb +++ b/notebooks/08-custom-filters-infrastructure.ipynb @@ -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,