2

I'm new to overpass queries. I'm trying to write a python script to pull data on the length of rail in major global cities. I am having a problem in the length of track (using osmnx.basic_stats(G)) seems abnormally large.

I have a two questions:

  1. For a line of track (running in two directions side by side), it looks like overpass returns two tracks for each direction (eg, four lines of track in total). See this screenshot below in London.

Railway Screenshot

However, for a subway, overpass returns a single line of track in each direction. See screenshot below.

Subway Screenshot

To calculate the total length of track then, is the best way to do this simply to collect these differently and account for these differences by dividing the length of rail track by 2?

  1. My second question is, what would be an appropriate query to remove disused tracks and industrial tracks. You can see the OSM Railway tag guide here.

FYI, my code to collect the data is as follows:

import osmnx as ox

# Pull multigraph using Londons lat/long
G = ox.graph_from_point((51.5073509,-0.1277583), 
                        distance = 20000, 
                        distance_type = 'bbox', 
                        infrastructure = 'way["railway"~"rail"]',
                        network_type = 'none',
                        )

# Print length of track in KM
print(ox.basic_stats(G)['edge_length_total'] / 1000)

# Visualise the data that has been pulled
ox.plot_graph_folium(G)
  • 3
    Please ask only One question per Question. – Vince Apr 5 at 20:57
3
  1. Whatever the number of tracks, it's the total length of all of them that will be given. You don't need to divide anything by any what. If there are missing data, it's an other problem. So basically, in your subway example, you have 2 separate tracks, and in the first example, there is 4. What I would suggest is that you check on an aerial image if there is any problem (missing tracks e.g.).

  2. You can add a custom_filter to filter out disused tracks:

    import osmnx as ox
    ox.config(log_console=True, use_cache=True)
    my_custom_filter = '["railway"!~"disused|abandoned"]'
    G = ox.graph_from_point((51.5073509,-0.1277583), 
                            distance = 20000,
                            distance_type = 'bbox', 
                            infrastructure = 'way["railway"~"rail"]',
                            network_type = 'none',
                            custom_filter = my_custom_filter
                            )
    
    ox.plot_graph(G)
    

Notice: it appears there is no such "disused" or "abandoned" railways in the area you defined.

Result

| improve this answer | |
  • 1
    Note that the old infrastructure parameter was deprecated in a previous release. The custom_filter parameter alone will do the job for you now. Details in docstring. – gboeing Jun 12 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.