Correct OSMnx Custom Filter Syntax

Viewed 946

I have just updated to a newer version of OSMnx (0.16) and one of my scripts no longer works.

  G = ox.graph_from_point(yx, 
                    dist = 5000,
                    dist_type = 'bbox', 
                    infrastructure = 'way["railway"]',
                    network_type = 'none',
                    custom_filter = '["service"!~"yard|siding"]["railway"~"%s"],
                    truncate_by_edge = True,
                    retain_all = True
                     )

This was designed to pull all subways but exclude all sidings. However, the infrastructure parameter is no longer available in the latest version.

Apparently, I need to incorporate the infrastructure information within the custom query, however, I am not sure how to do so. I am not sure what the correct syntax of a customer filter ought to be.

Any ideas would be a huge help!

1 Answers

Read through the OSMnx documentation and usage examples. They explain how to use the custom filter. And read through the Overpass query language wiki, which explains the syntax itself in great detail.

import osmnx as ox
point = 40.750972, -73.992778
G = ox.graph_from_point(point,
                        custom_filter = '["railway"~"subway"]["service"!~"yard|siding"]',
                        truncate_by_edge = True,
                        retain_all = True)
len(G) #79
Related