Not sure if this is even possible but I am trying to find all lean-tos (shelter=lean_to) that are NOT within or close (<50 meters) to a backcountry campsite (tourism=camp_site, backcountry=yes).
Despite being very confident that it can be done the query chatgpt gave me doesn’t work. However, I am not sure why other than it seems to be the final subtraction that gives an error. Maybe this function is not supported?:
[out:json];
// Find all tourism=camp_site with backcountry=yes in the current map view
(
node["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
way["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
relation["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
)->.campsites;
// Find all shelter=lean-to within 50 meters of the campsites in the current map view
(
node["shelter"="lean-to"](around.campsites:50);
way["shelter"="lean-to"](around.campsites:50);
relation["shelter"="lean-to"](around.campsites:50);
)->.nearby_shelters;
// Find all shelter=lean-to in the current map view
(
node["shelter"="lean-to"]({{bbox}});
way["shelter"="lean-to"]({{bbox}});
relation["shelter"="lean-to"]({{bbox}});
) - .nearby_shelters;
out body;
>;
out skel qt;
There are three issues to fix. First: Syntax. The minus operator needs parentheses and there is a colon missing.
(
node["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
way["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
relation["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
)->.campsites;
// Find all shelter=lean-to within 50 meters of the campsites in the current map view
(
node["shelter"="lean-to"](around.campsites:50);
way["shelter"="lean-to"](around.campsites:50);
relation["shelter"="lean-to"](around.campsites:50);
)->.nearby_shelters;
// Find all shelter=lean-to in the current map view
( (
node["shelter"="lean-to"]({{bbox}});
way["shelter"="lean-to"]({{bbox}});
relation["shelter"="lean-to"]({{bbox}});
); - .nearby_shelters; );
out body;
>;
out skel qt;
Second: A quick recherche on taginfo shows that it is rather shelter_type than shelter that has a value that is similar to lean-to.
Third, it is rather lean_to than lean_to.
[out:json];
// Find all tourism=camp_site with backcountry=yes in the current map view
(
node["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
way["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
relation["tourism"="camp_site"]["backcountry"="yes"]({{bbox}});
)->.campsites;
// Find all shelter=lean-to within 50 meters of the campsites in the current map view
(
node["shelter_type"="lean_to"](around.campsites:50);
way["shelter_type"="lean_to"](around.campsites:50);
relation["shelter_type"="lean_to"](around.campsites:50);
)->.nearby_shelters;
// Find all shelter=lean-to in the current map view
( (
node["shelter_type"="lean_to"]({{bbox}});
way["shelter_type"="lean_to"]({{bbox}});
relation["shelter_type"="lean_to"]({{bbox}});
); - .nearby_shelters; );
out body;
>;
out skel qt;
Finally, let’s clean up the query to get it shorter and faster. Use nwr:
[out:json];
// Find all tourism=camp_site with backcountry=yes in the current map view
nwr["tourism"="camp_site"]["backcountry"="yes"]({{bbox}})->.campsites;
// Find all shelter=lean-to within 50 meters of the campsites in the current map view
nwr["shelter_type"="lean_to"](around.campsites:50)->.nearby_shelters;
// Find all shelter=lean-to in the current map view
( nwr["shelter_type"="lean_to"]({{bbox}}); - .nearby_shelters; );
out body;
>;
out skel qt;
Then, get the query more optimized towards actual data structures:
nwr["shelter_type"="lean_to"]({{bbox}})->.all;
nwr["tourism"="camp_site"]["backcountry"="yes"]({{bbox}})->.campsites;
( .all; - nwr.all(around.campsites:50); );
out center;
This fetches all shelters early and reuses them to compute the ones to skip.
Finally, there is a full manual, so no need for mostly guessing AI ersatz.