Can we create a query that shows up all the schools that are near - in other words - (it is a anra search) how to perform a search

hello

this question is one of a Neaby-search:

can we create a quewry that shows up all the schools that are in the near - in other words - (it is a area search) how to perform a search - for http://www.overpass-turbo.eu :

example: what i am after. how to create a request to find all the schools - in the area of - let us say munich - in a radius of 10 km for example!?

how can we find all the schools around a certain point - or in other words; all in Munich - in a area /(radius) of let us say 10 kilometers can we create a query that works on Overpass-turbo.eu

approach: well, as far i know: OpenStreetMap data consists of three basic elements: nodes, ways and relations.
A generall query searches for (only) for nodes. Some schools will be mapped as ways and a few others as relations. we have to change your query in order to search for all three elements:

area[name = "Council of the City of Ryde"];
(
node(area)[amenity = school];
way(area)[amenity = school];
relation(area)[amenity = school];
);
out;

Alternatively we just use the keyword nwr to search for all three elements:


area[name = "Council of the City of Ryde"];
nwr(area)[amenity = school];
out;

but what i am after. how to create a request to find all the schools - in the area of - let us say munich - in a radius of 10 km for example!?

well could this be an approach to solve the problem!?


[out:json];
// Define the area of Munich
area[name="Munich"]->.searchArea;
// Search for schools within a 10-kilometer radius of Munich
(
  node(around.searchArea:10000)["amenity"="school"];
  way(around.searchArea:10000)["amenity"="school"];
  relation(around.searchArea:10000)["amenity"="school"];
);
// Output the results
out body;
>;
out skel qt;

As a first tip: You can use the abbreviation nwr to combine nodes, ways and relations. This will save you two lines and therefore potential customization effort when changing the query.

If you now search for Munich using area, the entire city area of Munich will be searched for. And the entire area of Munich is larger than a 10km radius from the center. Now it depends on what result you want to achieve.

If you simply want to know all schools within the city area of Munich, then that would be your query:

[out:json];
{{geocodeArea:Munich}}->.searchArea;
nwr["amenity"="school"](area.searchArea);
out geom;

But if you want to search from a very specific point, exactly 10km around, I would switch to a single coordinate. (The coordinates are from Marienplatz.) Query:

[out:json];
(
  nwr[amenity=school](around:10000, 48.13714, 11.57539);
);
out geom;

Simply an alternative search method is to search for specific named properties within a certain region and then within a radius of 10km. This saves the conversion to coordinates.
We first search for a region with the name “Munich”, within this we search for all properties with the name “Marienplatz” and from this named property “Marienplatz” we search for all schools within a radius of 10km. Query:

area[name="München"];
nwr(area)[name="Marienplatz"];
nwr["amenity"="school"](around:10000);
out geom;
2 Likes

hello -

first of all many thanks !

thank you - this is just perfect

have a great day :wink:

1 Like

good day dear Mcliquid,

again many many thanks for the awesome help one additoinal question.

Now that we have such an awesome solution - i want to go one tiny step further.

well do you think that it is possible to integrate a nearby search functionality into my GitHub project page, Okay - that said: GitHub Pages, which hosts project pages, primarily serves static content, so we won’t be able to directly run server-side code like PHP (eg. as we have it in a WordPress for example) to interact with APIs.

However, there is hope:

we can still achieve a similar functionality by using client-side languages like JavaScript to make requests to the Overpass API and display the results on our GitHub project page.

Dear MCliquid - well i guess that there some options would be like so: could this be a high-level overview of how we could approach it:

HTML/CSS: Create a structure and styling for our project page, including any elements needed for displaying the search results.

JavaScript: now we would have to write JavaScript code to handle user interactions, make requests to the Overpass API, and dynamically update the page with the retrieved data. we can use libraries like Leaflet.js for mapping functionalities if needed.

GitHub Pages Integration: we ought to add the HTML, CSS, and JavaScript files to our GitHub repository and configure GitHub Pages to serve them as our project page.

Here’s a simplified example of how we might implement the JavaScript part to perform a nearby search using Overpass API:

html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nearby Schools Search</title>
    <!-- Include any CSS files here -->
</head>
<body>
    <h1>Nearby Schools</h1>
    <div id="schoolList"></div>

    <script>
        // Function to perform nearby search
        function nearbySchoolsSearch() {
            var url = 'http://overpass-api.de/api/interpreter';
            var data = '[out:json][timeout:25];(node["amenity"="school"](around:10000,48.1351,11.5820););out;';

            fetch(url, {
                method: 'POST',
                body: data
            })
            .then(response => response.json())
            .then(data => {
                // Display search results
                var schools = data.elements;
                var schoolList = document.getElementById('schoolList');
                schoolList.innerHTML = '<ul>';
                schools.forEach(school => {
                    schoolList.innerHTML += '<li>' + school.tags.name + '</li>';
                });
                schoolList.innerHTML += '</ul>';
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }

        // Call the nearbySchoolsSearch function when the page loads
        window.onload = nearbySchoolsSearch;
    </script>
</body>
</html>

Well McLiquid, This code should just create a very very simple HTML page with a heading and a

element where the search results will be displayed. And i think that the JavaScript code uses the Fetch API to make a request to the Overpass API, retrieves the nearby schools, and dynamically updates the page with the results

What do you think - can we go like so…!?
Look forward to hear from you

Overall, your AI generated approach seems to be a good starting point, and with some refinement and testing, you should be able to successfully integrate the nearby search functionality into your GitHub project page. Good luck with your project!

1 Like

Did you check mapcomplete.org (select “Onderwijs” as theme) and Munich as city (zoom in to avoid long delays)

hello dear NivaOne
many many thanks for the reply - and the hint - this is just awesome: i am glad to hear from you
i will check out this right now
many thanks

greetings

And there is also OpenStreetBrowser.
Change the language at the bottom left.
Then select Dienste → Bildungseinrichtungen.
Use the magnifying glass to select München.