Search code examples
openstreetmapoverpass-api

Why can I find a relation by tag but not by ID in overpass Turbo?


I'm trying to get a specific relation in overpass turbo and then do stuff with it.

When I try getting it like this


/*
This has been generated by the overpass-turbo wizard.
The original search was:
“id=2704286 in briancon”
*/
[out:json][timeout:25];
// fetch area “briancon” to search in
{{geocodeArea:briancon}}->.searchArea;
// gather results
(
  // query part for: “id=2704286”
  relation["id"="2704286"](area.searchArea);
);
// print results
out body;
>;
out skel qt;

I get an empty response. But when I query the same area by a tag, which the relation I want fulfills, like in this query, it's in the response data (among others) how can that be?

This has been generated by the overpass-turbo wizard.
The original search was:
“route=hiking in briancon”
*/
[out:json][timeout:25];
// fetch area “briancon” to search in
{{geocodeArea:briancon}}->.searchArea;
// gather results
(
  relation["route"="hiking"](area.searchArea);
);
// print results
out body;
>;
out skel qt;

Solution

  • Use

      relation(2704286)(area.searchArea);
    

    instead of

      relation["id"="2704286"](area.searchArea);
    

    See also: https://wiki.openstreetmap.org/wiki/Overpass_API/Language_Guide#Query_by_element_id