Skip to main content Link Search Menu Expand Document (external link)

Sets of Features

A feature set represents those Feature objects that meet certain criteria.


Creates a feature set based on a Geographic Object Library.

france = Features("france")   # All features in france.gol

Filtering features

To select a subset of features, add the constraint in parentheses, or apply a filter method. This always creates a new feature set, leaving the original set unmodified.

By bounding box

Select the features whose bounding boxes intersects the given Box:

paris_bounds = Box(
    west=2.2, south=48.8,
    east=2.5, north=48.9)
features_in_paris = france(paris_bounds)

By type and tags

Apply a query written in GOQL (the Geographic Object Query Language) to select features based on their type and tags:

restaurants = features(
    # nodes and areas

fire_hydrants = features(
    # only nodes

safe_for_cycling = features(
   "w[highway][maxspeed < 30]")
   # linear ways

Using filter methods

Apply a spatial filter or topological filter:


Using set intersection

Select only features that are in both sets:

museums  = features("na[tourism=museum]")
in_paris = features.within(paris))
paris_museums = museums(in_paris)

Alternatively, you can use the & operator:

paris_museums = museums & in_paris

Obtaining Feature objects

Iterate through the feature set:

>>> for hotel in hotels:
...     print(
Hôtel du Louvre
Brit Hotel

Turn it into a list:

>>> list(hotels)
[way/112112065, relation/1575507, node/3558592188]

Check if the set is empty:

if pubs(within_dublin):
    print("Great, we can grab a beer in this town!")

if not street.nodes("[traffic_calming=bump]"):
    print("No speed bumps on this street.")

Obtaining a single Feature


The first feature of the set (or any arbitrary feature if the set is unordered).

None if the set is empty.

The one and only feature of the set.

A QueryError is raised if the set is empty or contains more than one feature.

Alternatively, use [0] to get the first Feature of a non-empty set.

A QueryError is raised if the set is empty.

first_node = way.nodes[0]

Result properties

These are read-only, and are calculated on each access.


The total number of features in this set.


The total area (in square meters) of all areas in this set.


The total length (in meters) of all features in this set. For areas, their circumference is used.


A GeometryCollection that contains the shapes of all features in this set.



Only features that are nodes.


Only features that are ways (including areas that are represented using a closed way).

If you want to restrict the subset to linear ways, use features('w').


Only features that are relations (including relations that represent areas).

If you want to restrict the subset to non-area relations, use features('r').



The set’s features represented as GeoJSON (Formatter)

A Map that displays the features in this set. Use show() to open it in a browser window, or save() to write its HTML file."hotel-map") # .html by default'red')    # map with fire hydrants marked in red


The set’s features represented as Well-Known Text (Formatter)

Spatial filters

These methods return a subset of only those features that fulfill a specific spatial relationship with another geometric object (Feature, Geometry, Box or Coordinate).


Features that lie entirely inside geom.

Features.around(geom, units=*distance*)

Features that lie within the given distance from the centroid of geom. In lieu of a geometric object, you can also specify coordinates using x and y (for Mercator-projected coordinates) or lon and lat (in degrees). Use meters, feet, yards, km, miles or mercator_units to specify the maximum distance.


# All bus stops within 500 meters of the given restaurant
features("n[highway=bus_stop]").around(restaurant, meters=500)

# All features within 3 miles of the given point
features.around(miles=3, lat=40.12, lon=-76.41)


Features whose geometry contains the given geometric object.

Note: If you want to test whether this set includes a particular feature, use feature in set.

# In which park (if any) is this statue of Claude Monet?

# The county, state and country for this point -- should return
# San Diego County, California, USA (in no particular order)
    "[admin_level <= 6]").contains(Coordinate(lon=-117.25, lat=32.99))

As of Version 0.1.0, only nodes and Coordinate objects are supported.


Features whose geometry crosses the given geometric object.

# All railway bridges across the Mississippi River


Features whose geometry is disjoint from the given geometric object.


Features whose geometry intersects the given geometric object.


Features whose geometry overlaps the given geometric object.


Features whose geometry touches the given geometric object.

Features.nearest_to(geom, units=*distance*)0.2

Features in ascending order of distance to the given geometric object.

  • To limit the search radius, specify a maximum distance in the units of your choice: meters, feet, yards, km, miles or mercator_units


features("na[amenity=hospital]").nearest_to(my_location, miles=5)

Topological filters

These methods return a subset of those features that have a specific topological relationship with another Feature.


The nodes of the given way. Returns an empty set if feature is a node or relation.


Features that are members of the given relation, or nodes of the given way. Returns an empty set if feature is a node.


Relations that have the given feature as a member, as well as ways to which the given node belongs.




All features that share a common node with feature.

Metadata 0.2


The license under which this dataset is made available.


The URL where the text of the license can be found.



Table of contents