Coder Social home page Coder Social logo

osmapi-overpass's Introduction

osmapi-overpass

osmapi-overpass is a client for the Overpass API, building on top of osmapi.

Copyright and License

© 2019-2023 Tobias Zwick. This library is released under the terms of the GNU Lesser General Public License (LGPL).

Installation

Add de.westnordost:osmapi-overpass:3.0 as a Maven dependency or download the jar from there.

Android

On Android, you need to exclude kxml2 from the dependencies in your gradle.kts since it is already built-in, like so:

configurations {
    all {
        // it's already included in Android
        exclude(group = "net.sf.kxml", module = "kxml2")
        exclude(group = "xmlpull", module = "xmlpull")
    }
}

This library uses classes from the Java 8 time API, like Instant etc., so if your app supports Android API levels below 26, you need to enable Java 8+ API desugaring support.

Example Usage

First, initialize the OverpassMapDataApi

	OsmConnection connection = new OsmConnection("https://overpass-api.de/api/", "my user agent");
	OverpassMapDataApi overpass = new OverpassMapDataApi(connection);

then...

Get all shops on Malta as OSM elements

    overpass.queryElements(
        "[bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out meta;",
        handler
    );

Get all shops on Malta as OSM elements together with their geometry

    overpass.queryElementsWithGeometry(
        "[bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out meta geom;",
        handler
    );

Get all shops on Malta and return their name plus type of shop as table rows

    overpass.queryTable(
        "[out:csv(name, shop)][bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out body;",
        handler
    );

Count the number of shops on Malta.

    ElementCount count = overpass.queryCount(
        "[bbox:13.8,35.5,14.9,36.3]; nwr[shop]; out count;"
    );

The query string is just passed through to the Overpass API. For how the query string needs to look like, consult the documentation for Overpass API Query Language.

osmapi-overpass's People

Contributors

westnordost avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

osmapi-overpass's Issues

[FeatureRequest] Add current QueryExecution status or Download status

Hey, just found you lib and really like it 👍

Request

I might use it for an university project if my prof allows it (It is his software)

Just want to ask for an additional feature. If you run a big query with a large response the program is just running the download but does not give any status information.

OverpassStatus just gives you the status of overpass. Not of the current running query. It would be great if you could add a feature that gives back the current query status or the current size of the download buffer. This basically confirms that osmapi is still working.

Implementation:

Just an idea: You can create a Status class (that runs in a separate thread) and just gives gack the size of the currently downloaded information. Since you are using typical http this should't be that complicated.

Keep on going ✌

Problem with Umlauts when querying

I'm using version 2.0 because 2.1 seems still to be missing in mvnrepository.

implementation 'de.westnordost:osmapi-overpass:2.0'

I have this code for executing a quite simple query.

OsmConnection connection = new OsmConnection("https://overpass-api.de/api/", "jmizv-DataHandler-v0.1");
OverpassMapDataApi overpass = new OverpassMapDataApi(connection);
        try {
            overpass.queryTable("""
                    [out:csv("name")][timeout:90];
                    area["name:de"="Magdeburg"]->.ar;
                    way["highway"]
                      [!"name:etymology:wikidata"]
                       (area.ar);
                    (._;>;);
                    out meta;
                    """, tea -> System.out.println(tea[0]), "\t");
        } catch (Exception ex) {
            ex.printStackTrace(System.err);
        }

But I can see on the console this output:

[..]
Walther-Rathenau-Stra�e
L�neburger Stra�e
Breiter Weg

I fail to see whether I need to set some encoding or whether this is a bug? Maybe solved in 2.1?

Executing this via https://overpass-turbo.eu/ gives the correct encoding.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.