4
import osmnx as ox
ox.__version__ # '0.13.0'

I would like to show the subway in Hannover as known in the German subway OSM data on a map using the great OSMNX module. But unlike the New York example no results are returned for:

G = ox.graph_from_place('Hannover, Germany',
                        retain_all=False, truncate_by_edge=True, simplify=True,
                        network_type='none', custom_filter='["railway"~"subway"]')

# EmptyOverpassResponse: There are no data elements in the response JSON

I do get results for other similar queries using 'Hannover, Germany' as region. I also do not get subway results for Paris or London. And I do not get results for similar queries like custom_filter='["railway"~"tram"]' or '["railway"~"s-bahn"]' or '["network"~"metro"]'.

Also, if I use the infrastructure keyword argument to select "railway", an extensive gdf is returned:

G = ox.graph_from_place('Hannover, Germany', retain_all=False, truncate_by_edge=True, simplify=True,
                        network_type='none', infrastructure='way["railway"]')
gdfox = ox.graph_to_gdfs(G, nodes=False, edges=True, node_geometry=True, fill_edge_geometry=True)
gdfox.shape # (4422, 14)

But I cannot identify the subway using the columns returned?:

['u', 'v', 'key', 'osmid', 'service', 'oneway', 'length',
   'geometry', 'name', 'maxspeed', 'ref', 'bridge', 'tunnel',
   'access']

What I also find strange is that there are only 2 LINESTRINGS returned if I (try to) retrieve all railways using the custom_filter:

G = ox.graph_from_place('Hannover, Germany', retain_all=False, truncate_by_edge=True,
                        simplify=True, network_type=None, custom_filter='["railway"~""]')
gdfox = ox.graph_to_gdfs(G, nodes=False, edges=True, node_geometry=True, fill_edge_geometry=True)
gdfox.shape # (2, 10) # returns only 2 LINESTRINGS: Altenbekener Damm
Wouter
  • 1,296
  • 2
  • 14
  • 32

1 Answers1

5

I am in the process of removing the infrastructure parameter in favor of a more consistent custom_filter parameter. Will be done in a couple days: https://github.com/gboeing/osmnx/pull/477 (EDIT: done and released in v0.14.0; code snippet below edited accordingly.)

In the meantime, I am not familiar with Hannover but it appears that its passenger rail system is tagged as "tram" and "rail" rather than "subway". Something like this seems to capture it:

import osmnx as ox
ox.config(use_cache=False,
          log_console=True,
          useful_tags_way=ox.settings.useful_tags_way + ['railway'])

G = ox.graph_from_place('Hannover, Germany',
                        retain_all=False, truncate_by_edge=True, simplify=True,
                        custom_filter='["railway"~"tram|rail"]')
len(G) #1776
gboeing
  • 5,691
  • 2
  • 15
  • 41
  • 1
    This has been merged into the OSMnx master branch and will be released soon. – gboeing Jun 03 '20 at 16:34
  • This works, I use cf='["railway"~"tram|rail"]' & custom_filter=cf (so I removed the 'way' used with the old infrastructure kwarg). FYI numbers match: cf='["railway"~"tram"]' # len(G) == 677 / cf='["railway"~"rail"]' # len(G) == 1099. Many thanks for your excellent work and even finding the time to answer questions! – Wouter Jun 04 '20 at 09:33
  • About the "useful_tags_path": I read that this is "a list of useful OSM tags to attempt to save from path elements" but do not understand. The result is the same with and without setting this config. And leaving "railway" out of the custom_filter (cf='["tram|rail"]') when setting it as useful_tags_path returns an EmptyOverpassResponse (experiment to check if it is set as default). – Wouter Jun 04 '20 at 09:43
  • 1
    You need "railway" in your `custom_filter` to retrieve ways with that tag. The `useful_tags_path` documentation could be improved. OSMnx uses the attributes in the `useful_tags_path` list as graph edge attributes. By default, they are road-network specific. I added "railway" to the list so that the value of the railway tag would appear as a graph edge attribute (e.g., values would include "tram" or "rail" in the edge railway attributes). – gboeing Jun 04 '20 at 16:03
  • 1
    Note that the old useful_tags_path setting has been renamed to the more appropriate `useful_tags_way` and given a clearer docstring to make it more comprehensible. See [the docs](https://osmnx.readthedocs.io/en/latest/osmnx.html#osmnx.utils.config). – gboeing Jun 07 '20 at 00:14
  • Thank you! So this is used when an OSM way element is converted into the format of a networkx graph path when parsing the OSM data. – Wouter Jun 07 '20 at 06:36
  • 1
    Correct: the items in `useful_tags_way` determine which OSM way tags to retain as networkx graph edge attributes. – gboeing Jun 07 '20 at 18:33