openstreetmapoverpass-api

Is this Overpass query correctly finding a way given two nodes? Can anyone find a counterexample?


I'm using OverpassQL to find a "way" that passes through two consecutive nodes. Here's my query:

[out:json];
(
    way(around:1,x1, y1);
    -
    (
         way(around:1, x1, y1);
         -
         way(around:1, x2, y2);
    );
);
out geom;

I thought of making the intersection between the ways around two points. Since the intersection operation does not exist in OverpassQL I used the subtraction. I'm trying to determine if this query will always return a unique "way" that intersects both of these points. If not, can anyone provide a counterexample where more than one "way" would be returned?


Solution

  • To get the intersection, you can simply combine multiple filters in one query statement:

    [out:json];
    way(around:1,48.8677584, 2.3139659)
       (around:1,48.8670861, 2.3160717);
    out geom;
    

    If you need more control which ways to use for an intersection, you can also have different queries, and intersect the results in a separate step:

    [out:json];
    way(around:1,48.8677584, 2.3139659) -> .ways1;
    way(around:1,48.8670861, 2.3160717) -> .ways2;
    
    // get intersection
    // way.ways1.ways2;      // this is original answer
    node(w.ways1)(w.ways2);  // this is more reliable  ref https://gis.stackexchange.com/a/296404
    
    out geom;
    

    I'm trying to determine if this query will always return a unique "way" that intersects both of these points.

    No, this will not get you a unique way. Think about a roundabout which has been split into two ways. If you query with both lat/lon values, where the two ways connect, the query will return both ways.

    Example returning two ways:

    [out:json][date:"2023-10-01T00:00:00Z"];
    way(around:1,50.1281949, 1.7851947)
       (around:1,50.1281638, 1.7851656);
    out geom;
    

    List item