Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/westnordost/osmapi-overpass
Java client for the Overpass API
https://github.com/westnordost/osmapi-overpass
java osm overpass-api
Last synced: 2 months ago
JSON representation
Java client for the Overpass API
- Host: GitHub
- URL: https://github.com/westnordost/osmapi-overpass
- Owner: westnordost
- License: lgpl-3.0
- Created: 2019-12-04T18:19:03.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-24T22:22:53.000Z (about 1 year ago)
- Last Synced: 2024-05-02T04:35:45.006Z (8 months ago)
- Topics: java, osm, overpass-api
- Language: Java
- Size: 88.9 KB
- Stars: 16
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# osmapi-overpass
osmapi-overpass is a client for the [Overpass API](https://wiki.openstreetmap.org/wiki/Overpass_API), building on top of [osmapi](https://github.com/westnordost/osmapi).
## Copyright and License
© 2019-2023 Tobias Zwick. This library is released under the terms of the [GNU Lesser General Public License](http://www.gnu.org/licenses/lgpl-3.0.html) (LGPL).
## Installation
Add [`de.westnordost:osmapi-overpass:3.0`](https://mavenrepository.com/artifact/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:
```kotlin
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`](https://developer.android.com/reference/java/time/Instant) etc., so if your app supports Android API levels below 26, you need to enable [Java 8+ API desugaring support](https://developer.android.com/studio/write/java8-support#library-desugaring).
## Example Usage
First, initialize the `OverpassMapDataApi`
```java
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
```java
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
```java
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
```java
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.
```java
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](https://wiki.openstreetmap.org/wiki/Overpass_API/Overpass_QL).