query to overpass api in java … i want to specify the zoom in the query for the draw the response .. what i must add in my code for doing that?

与世无争的帅哥 提交于 2021-01-29 09:19:59

问题


I work in a project in java .. i want to specify the zoom in the overpass query ? because i want to draw the response (xml file) ??

public static Document getNodesViaOverpass(String query) throws IOException, ParserConfigurationException, SAXException {
    String hostname = OVERPASS_API;

    URL osm = new URL(hostname);
    HttpURLConnection connection = (HttpURLConnection) osm.openConnection();
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

    DataOutputStream printout = new DataOutputStream(connection.getOutputStream());
    printout.writeBytes("data=" + URLEncoder.encode(query, "utf-8"));
    printout.flush();
    printout.close();

    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    return docBuilder.parse(connection.getInputStream());
}

回答1:


You cannot specify a zoom level but you can specify a bounding box. A bounding box defines the minimum and maximum latitude and longitude for your query, i.e. a rectangle. See bounding box in the Overpass Query Language documentation.

The bounding box parameters consist of southern-most latitude, western-most longitude, northern-most latitude, eastern-most longitude.

This is a simple example for an Overpass query with a bounding box:

node(50.745,7.17,50.75,7.18)[highway=bus_stop];
out;

If a simple rectangle doesn't fit your needs you can also specify a polygon.



来源:https://stackoverflow.com/questions/58421286/query-to-overpass-api-in-java-i-want-to-specify-the-zoom-in-the-query-for-th

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!