All Projects → westnordost → osmapi

westnordost / osmapi

Licence: LGPL-3.0 License
Java client for the OSM API 0.6

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to osmapi

telegram-nearby-map
Discover the location of nearby Telegram users 📡🌍
Stars: ✭ 329 (+363.38%)
Mutual labels:  osm
ohsome-api
API for analysing OpenStreetMap history data
Stars: ✭ 25 (-64.79%)
Mutual labels:  osm
MapComplete
A small and easy OpenStreetMap editor
Stars: ✭ 101 (+42.25%)
Mutual labels:  osm
LocationMapViewer
Android App to view Locations in a map with support for gpx, kml and kmz data
Stars: ✭ 31 (-56.34%)
Mutual labels:  osm
gosmparse
Processing OpenStreetMap PBF files at speed with Go
Stars: ✭ 55 (-22.54%)
Mutual labels:  osm
osmcha
Python package to detect suspicious OSM changesets
Stars: ✭ 33 (-53.52%)
Mutual labels:  osm
Avenue-GPX-Viewer
A simple and easy GPX viewer for macOS.
Stars: ✭ 42 (-40.85%)
Mutual labels:  osm
ohsome2label
Historical OpenStreetMap Objects to Machine Learning Training Samples
Stars: ✭ 33 (-53.52%)
Mutual labels:  osm
AndroidOfflineMapLibrary
Offline OpenStreet Map Library (No Internet Required) You dont have to even one-time connect!
Stars: ✭ 16 (-77.46%)
Mutual labels:  osm
mbmatch
An MBTiles server for PBF, which is also a map matcher.
Stars: ✭ 34 (-52.11%)
Mutual labels:  osm
a11yjson
A11yJSON: A standard to describe the accessibility of the physical world.
Stars: ✭ 58 (-18.31%)
Mutual labels:  osm
osm2xodr
converter for OpenStreetMaps to OpenDrive roads - for use with Carla or other things
Stars: ✭ 90 (+26.76%)
Mutual labels:  osm
query-overpass
Query the OpenStreetMap Overpass API.
Stars: ✭ 17 (-76.06%)
Mutual labels:  osm
QuteMap
Maps using Qt WebEngine and Qt WebChannel using PyQt5/PySide2
Stars: ✭ 27 (-61.97%)
Mutual labels:  osm
bexhill-osm
A local mapping project using data from OpenStreetMap. Includes overlays, walking directions and historical information.
Stars: ✭ 16 (-77.46%)
Mutual labels:  osm
pt2matsim
Package to create a multi-modal MATSim network and schedule from public transit data (GTFS or HAFAS) and an OSM map of the area.
Stars: ✭ 29 (-59.15%)
Mutual labels:  osm
OsmToRoadGraph
OSM XML file to road graph converter
Stars: ✭ 31 (-56.34%)
Mutual labels:  osm
accessibility-cloud
👩🏽‍🦯🦮👩🏻‍🦽👩🏿‍🦼 the platform to exchange physical accessibility data in a standardized, future-proof, easy-to-use way.
Stars: ✭ 37 (-47.89%)
Mutual labels:  osm
ROS-GPS
GPS Localization with ROS, OSM and rviz
Stars: ✭ 19 (-73.24%)
Mutual labels:  osm
o.map
Open Street Map app - KaiOS
Stars: ✭ 51 (-28.17%)
Mutual labels:  osm

osmapi

osmapi is a client for the OSM API 0.6.

It is well tested (test coverage over 90%) and being used by StreetComplete, thus actively maintained.

Note, the OSM API, particularly the part to download the map data, is intended only for editing the map. It's not made for pulling larger amounts of data or data analysis of certain map features. If this is what you intend to do, the Overpass API is what you will want to use. I created a basic Java client for the Overpass API here, it builts upon this library: osmapi-overpass.

Copyright and License

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

Installation

Depending on which part of the API you use, you can only include what you need:

ClassDependencyDescription
CapabilitiesApi
de.westnordost:osmapi-core:2.0
Getting server capabilities
PermissionsApi
de.westnordost:osmapi-core:2.0
Getting user permissions
MapDataApi
de.westnordost:osmapi-map:2.0
Getting map data, querying single elements and their relations toward each other and uploading changes in changesets
MapDataHistoryApi
de.westnordost:osmapi-map:2.0
Getting the history and specific versions of elements
NotesApi
de.westnordost:osmapi-notes:2.0
Getting finding, creating, commenting on and solving notes
GpsTracesApi
de.westnordost:osmapi-traces:2.0
Getting, uploading, updating and deleting GPS traces and trackpoints
ChangesetsApi
de.westnordost:osmapi-changesets:2.0
Finding changesets, changeset discussion, subscription and data
UserApi
de.westnordost:osmapi-user:2.0
Getting user information
UserPreferencesApi
de.westnordost:osmapi-user:2.0
Managing user preferences

To include everything, add de.westnordost:osmapi:4.0 as a Maven dependency or download the jar from there.

Android

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

dependencies {
    implementation 'de.westnordost:osmapi:4.0'
}

configurations {
    // already included in Android
    all*.exclude group: 'net.sf.kxml', module: 'kxml2'
    
    // @NonNull etc annotations are also already included in Android
    cleanedAnnotations
    compile.exclude group: 'org.jetbrains', module:'annotations'
    compile.exclude group: 'com.intellij', module:'annotations'
    compile.exclude group: 'org.intellij', module:'annotations'
}

Also, starting with v4.0 (or v2.0 of the modularized version respectively), this library uses the classes from the Java 8 time API, like Instant etc. instead of Date which leads to about 50% faster parsing times when receiving a result.

If your app supports Android API levels below 26, you have two options:

  1. Either stick to using version 3.x (or v1.x of the modularized version respectively) of this library...
  2. ...or enable Java 8+ API desugaring support for your app

Basic Usage

Everything revolves around the OsmConnection, this is the class that talks to the Api. Specify where to reach the Api, how the client should identify itself towards the server etc. If you plan to make calls that can only be made by a logged in user, such as uploading map data, an OAuthConsumer (third parameter) needs to be specified.

    OsmConnection osm = new OsmConnection(
        "https://api.openstreetmap.org/api/0.6/",
        "my user agent", null
    );

You can call osm.makeRequest(...) yourself to talk with the RESTful Api and write your own ApiRequestWriter and ApiResponseReader to write/read the request. It is more convenient however to use the appropriate class to do that for you and return the data you are interested in. See the table above for which classes are available.

For example...

Create a note

    Note myNote = new NotesApi(osm).create(position, "My first note");

Comment a changeset

    ChangesetInfo changeset = new ChangesetsApi(osm).comment(id, "Nice work!");

Get user info

    UserInfo user = new UserApi(osm).get(id);

Download map data

    MapDataApi mapApi = new MapDataApi(osm);
    mapApi.getMap(boundingBox, myMapDataHandler);

myMapDataHandler implements MapDataHandler whose methods are called as the elements are parsed, think SAX parser. I.e. if you download 10MB of data, then the elements start arriving at the handler as the data comes in so that you can process them on the fly.

    /** This class is fed the map data. */
    public interface MapDataHandler
    {
        void handle(Bounds bounds);

        void handle(Node node);
        void handle(Way way);
        void handle(Relation relation);
    }

Combine with data processing library

Read this if you want to use this library in conjunction with a data processing library like Osmosis, osm4j or have your own map data structures already.

Troubleshooting

If you are getting the exception

sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.

, try updating your Java SDK. Openstreetmap.org uses Let's Encrypt certificates which are not trusted in earlier versions of Java by default. Read more here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].