Overpass API User's Manual

Find Objects
Counting Objects
Analysing data
More information

Bounding Boxes

The simplest way to obtain OpenStreetMap data from a small region.

Filter a Query

The simplest way to get all data from a bounding box is to explicitly state so (Link):

nwr(51.477,-0.001,51.478,0.001);
out;

Here (51.477,-0.001,51.478,0.001) represents the bounding box. The order of the edges is always the same:

The Overpass API only uses the decimal fraction notation, a notation in minutes and seconds is not supported.

The value of the southern edge must be always smaller than the value of the northern edge, because the values for degree of latitude are growing from the south pole to the north pole, from -90.0 to +90.0.

In contrast to this, the values for degree of longitude are growing from west to east almost everywhere. But at the antimeridian the values jumps from +180.0 to -180.0. The antimeridian crosses on its way from the north pole to the south pole the pacific and not much else. Thus, in almost all cases the value of the western edge is smaller than the value of the eastern edge, unless one really wants to span a bounding box across the antimeridian.

It usually is tedious to manually figure out the bounding box. For this reason, almost all of the at Downstream Tools listed tools have convenience features for this. In Overpass Turbo and also JOSM, the substring {{bbox}} is replaced by the bounding box of the viewport. Thus, one can work with a generalized query like this:

nwr({{bbox}});
out;

The query then always is executed in the then current visible bounding box.

Please note that some of the elements are presented as dashed. This is a telltale sign of a bigger phenomenon, and we will pursue that further in the next section: The objects in question have been completely delivered with regard to their syntactic structure, but they have incomplete geometry because we implicitly specified so in this query.

Crop Output

There is a second purpose that bounding boxes are used for: The output of out geom can be spatially restricted. If one wants to visualize a way or relation on a map, then one must explicitly instruct the Overpass API to add coordinates, deviating from the design of the OSM data model.

In the case of relations this can lead to big amounts of data. As a quite typical example, in this case geometry across half of England is delivered, although only a couple of hundreds of square meters had been in focus:

relation(51.477,-0.001,51.478,0.001);
out geom;

The amount of data can be reduced by explicitly stating a bounding box to apply:

relation(51.477,-0.001,51.478,0.001);
out geom(51.47,-0.01,51.49,0.01);

The bounding box must be written immediately after geom. It can be equal or different from bounding boxes in our statements of the same request. In this case we have opted for a very broad spare boundary by using a larger bounding box for the output than for the query.

For explicitly output nodes the coordinate then is exactly delivered if the node is inside the bounding box.

For ways, not only the coordinates of the nodes within the bounding box are printed, but always also the next and preceding coordinate even if the respective coordinate is already outside the bounding box. To see this in an example, please click after executing the request in the upper right corner on data. Panning the map around shows where the geometry has been cut:

way[name="Blackheath Avenue"](51.477,-0.001,51.478,0.001);
out geom(51.477,-0.002,51.479,0.002);

Only part of the nodes have coordinates in this example.

The parts that have coordinates of each single the way can be unconnected, even within a single way:

way[name="Hyde Vale"];
out geom(51.472,-0.009,51.475,-0.005);

The phenomenon already happens if a way makes a moderate curve out of the bounding box and later again into it like in this example.

For relations their members of type way are expanded if at least one of the nodes of the respective way is inside the bounding box. Other members of type way are not expanded. Within these ways, like for ways themselves, the referred nodes within the bounding box plus one extra node are amended with coordinates.

Like with the bounding box as a filter, most programs have a mechanism to automatically insert the bounding box of the viewport. In Overpass Turbo again the substring {{bbox}} is replaced by the current bounding box, e.g.:

relation({{bbox}});
out geom({{bbox}});

Filter Globally

...


next: Geometries