westnordost / osmapi Goto Github PK
View Code? Open in Web Editor NEWJava client for the OSM API 0.6
License: GNU Lesser General Public License v3.0
Java client for the OSM API 0.6
License: GNU Lesser General Public License v3.0
In case of 400 error (malformed query) it is usually useful to have text of executed query
I think that osmapi should add query text to exception data on encountering 400 code in Overpass response
In streetcomplete/StreetComplete#954 I tried adding it to StreetComplete, but I think that it would be better to add it here.
Please deploy version 1.1 to maven central repository:
https://mvnrepository.com/artifact/de.westnordost/osmapi
Hello
On the comment below the link is no more ok
Is it possible to update it with this link : https://github.com/openstreetmap/openstreetmap-website/blob/master/db/structure.sql#L1108
I have a
MapDataHandler mapDataHandler = new MapDataHandler() {
public void handle(BoundingBox boundingBox) {
}
public void handle(Node node) {
if (node.getTags().get("highway").equals("bus_stop")) {
// System.out.println(node.getTags().get("name"));
// System.out.println(node.getTags().get("name:tt"));
// System.out.println(node.getTags().get("name:ru"));
// System.out.println(node.getTags().get("name:en"));
}
}
public void handle(Way way) {
}
public void handle(Relation relation) {
if (relation.getTags().get("type").equals("route")) {
if (relation.getTags().get("route").equals("bus")) {
System.out.println(relation.getTags().get("name"));
busRoutes.put(relation.getTags().get("name"), relation);
}
}
}
};
When the osm data is processed whti this particular handler I'm getting the following error:
de.westnordost.osmapi.common.errors.OsmApiReadResponseException: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at END_TAG @4:164 in java.io.InputStreamReader@1a160b5e
)Hi, I have the code below, with a query that returns nodes and ways.
In order to place those ways in the map I need at least one coordinate of the nodes that compose the way.
But querying the service for getting those nodes, if I query only a value I get a null, and querying for a collection it raises an error, probably I'm doing something wrong but couldn't find an answer for the problem.
Please could you explain how to get coordinates of the way objects?
public static void main(String[] args) {
String qry = "[bbox:40.20,-3.5,40.60,-2.5];(node[tourism=attraction];node[tourism=museum];node[historic];way[amenity=place_of_worship];); out;";
OsmConnection connection = new OsmConnection("https://overpass-api.de/api/", null);
OverpassMapDataApi overpass = new OverpassMapDataApi(connection);
HashMap<Long, Way> ways = new HashMap<>();
System.err.println("Running QUERY");
overpass.queryElements(qry, new MapDataHandler() {
public void handle(Relation relation) {
}
public void handle(Way n) {
System.err.println(">>>>>> WAY " + n.getId());
System.err.println(">>>>>> FIRST NODE ID " + n.getNodeIds().iterator().next());
ways.put( n.getNodeIds().iterator().next(), n);
}
public void handle(Node n) {
System.err.println(n.getId());
}
public void handle(BoundingBox bounds) {
}
});
MapDataApi api = new MapDataApi(connection);
System.err.println("Getting FIRST WAY NODE " + ways.keySet().iterator().next());
Node node = api.getNode(ways.keySet().iterator().next());
System.err.println("NODE: " + node); // It returns null always
System.err.println("Getting WAY NODES"); // This throws an Exception
api.getNodes(ways.keySet());
}
Exception message is:
Exception in thread "main" de.westnordost.osmapi.common.errors.OsmNotFoundException: Not Found (404) - <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.18 (Ubuntu) Server at overpass-api.de Port 443</address>
</body></html>
at de.westnordost.osmapi.OsmApiErrorFactory.createError(OsmApiErrorFactory.java:28)
at de.westnordost.osmapi.OsmConnection.handleResponseCode(OsmConnection.java:349)
at de.westnordost.osmapi.OsmConnection.makeRequest(OsmConnection.java:195)
at de.westnordost.osmapi.OsmConnection.makeRequest(OsmConnection.java:148)
at de.westnordost.osmapi.map.MapDataApi.getSomeElements(MapDataApi.java:386)
at de.westnordost.osmapi.map.MapDataApi.getNodes(MapDataApi.java:306
...
Hi,
I'd like to fix broken links to the source files in https://github.com/westnordost/osmapi/wiki/Combine-With-Data-Processing-Libraries however I can't seem to edit the wiki page. Do you mind enabling that somehow or giving me (temporary) permission to edit the wiki?
...because the BoundingBox creates "anonymous" LatLons which are not serializable.
BoundingBox(final double latMin, final double lonMin, final double latMax, final double lonMax)
I would like to use this awesome library in OSMTracker App (I'm in the process of giving love to the App). For this purpose, I'll require a method to upload a trace given a GPX File.
I played a little with the library code to explore how to implement this method. My implementation proposal is:
(a) add a new APIRequestWriter
implementation, GpxFileWriter
that writes the content of the Gpx File to be uploaded
(b) add a new create
method in GpsTracesApi
with a File as param, instead of the Points.
I could provide a PR (once I fixed some issues with Gradle in my repo), but I already have the code running, including a JUnit test.
Users might want to serialize the data somewhere.
I've tried it on my Moscow's PC and found test issue.
Fix is attached.
It is possible to get a picture of the map?
Hello Westnordost,
are you aware that there is already a project listet in the OSM wiki at
http://wiki.openstreetmap.org/wiki/Osmapi ?
It seems to be a different and older project then yours, or am I wrong?
When renaming is a better way, maybe you can add a "J" letter in your project name? ;-)
Seems like oracle wasn't compatible with let's encrypt certs until Java 7 >= 7u111 and Java 8 >= 8u101. I was on jdk 8_92 and I got:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.
It would be nice to specify in the README or Wiki to verify either you have added lets encrypt certs to your ${JAVA_HOME}/jre/lib/security/cacerts file or that you have the most recent jdk version which will contain support for lets encrypt ca certs.
Thanks for writing this lib. Very helpful!
Not sure whatever it is test bug, missing setup, inverted test (exception is excepted), gradlew test
being unsupported or something else.
de.westnordost.osmapi.notes.NotesDaoTest.testCommentNoteInsufficientPrivileges(NotesDaoTest.java:106)
is also failing.
I am just happy that I finally managed to run tests (for some reason I failed to get tests to run using GUIs, it went well with command line), I have not investigated what is exactly going on (I should go to sleep).
junit.framework.AssertionFailedError
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.fail(Assert.java:53)
at de.westnordost.osmapi.notes.NotesDaoTest.testCreateNoteInsufficientPrivileges(NotesDaoTest.java:95)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:106)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy1.processTestClass(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.lang.Thread.run(Thread.java:748)
mapDataDao.updateMap(...) fails with:
java.lang.IllegalStateException: unsupported feature http://xmlpull.org/v1/doc/features.html#indent-output
running the code on glassfish.
I think the error is in line 113 in mapDataParser. some times when it is a custom map or it is not a reviewed version, the nodes (for example) may not have version attribute. Version is a int variable so it is failing there when it returns null.
version = getIntAttribute("version");
OpenStreetMap suppors OAuth 2.0 now. The OAuth 1.0a implementation should be switched out.
Hi!
Please take a look at my programm and the exception:
import de.westnordost.osmapi.OsmConnection;
import de.westnordost.osmapi.map.MapDataDao;
import de.westnordost.osmapi.map.data.*;
import de.westnordost.osmapi.map.handler.MapDataHandler;
/**
Created by eljah32 on 9/21/2017.
*/
public class ConnectionTester {
public static void main(String[] args) {
OsmConnection osm = new OsmConnection(
"http://api.openstreetmap.org/api/0.6/",
"BusRouteDataExtractor 1.0", null);
MapDataDao mapDao = new MapDataDao(osm);
double LONGITUDE_START = 48.833744;
double LATITUDE_START = 55.693307;
double LONGITUDE_STOP = 49.261698;
double LATITUDE_STOP = 55.897801;
double currentLong = LONGITUDE_START;
double currentLat = LATITUDE_START;
MapDataHandler mapDataHandler = new MapDataHandler() {
public void handle(BoundingBox boundingBox) {
}
public void handle(Node node) {
}
public void handle(Way way) {
}
public void handle(Relation relation) {
if (relation.getTags().get("type").equals("route"))
{
System.out.println(relation.getTags().get("name"));
}
}
};
OsmLatLon min = null;
OsmLatLon max = null;
while (currentLat < LATITUDE_STOP) {
while (currentLong < LONGITUDE_STOP) {
//System.out.println(currentLat+", "+currentLong);
min = new OsmLatLon(currentLat, currentLong);
max = new OsmLatLon(currentLat+0.01, currentLong+0.01);
BoundingBox kazanBuses = new BoundingBox(min, max);
mapDao.getMap(kazanBuses, mapDataHandler);
currentLong=currentLong+0.01;
}
currentLong=LONGITUDE_START;
currentLat=currentLat+0.01;
}
//osm.
}
}
Exception in thread "main" de.westnordost.osmapi.common.errors.OsmApiReadResponseException: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at END_TAG @3997:13 in java.io.InputStreamReader@4079d7b3
at de.westnordost.osmapi.OsmConnection.handleResponse(OsmConnection.java:322)
А77 пер. Дуслык – Нефтебаза
at de.westnordost.osmapi.OsmConnection.makeRequest(OsmConnection.java:191)
at de.westnordost.osmapi.OsmConnection.makeRequest(OsmConnection.java:142)
at de.westnordost.osmapi.map.MapDataDao.getMap(MapDataDao.java:194)
at ConnectionTester.main(ConnectionTester.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at END_TAG @3997:13 in java.io.InputStreamReader@4079d7b3
at de.westnordost.osmapi.common.XmlParser.doParse(XmlParser.java:64)
at de.westnordost.osmapi.map.MapDataParser.parse(MapDataParser.java:58)
at de.westnordost.osmapi.map.MapDataParser.parse(MapDataParser.java:20)
at de.westnordost.osmapi.OsmConnection.handleResponse(OsmConnection.java:314)
... 9 more
Caused by: java.lang.NullPointerException
at ConnectionTester$1.handle(ConnectionTester.java:38)
at de.westnordost.osmapi.map.MapDataParser.onEndElement(MapDataParser.java:164)
at de.westnordost.osmapi.common.XmlParser.doParse(XmlParser.java:49)
... 12 more
Hi I am trying to implement
OsmConnection osm = new OsmConnection(
"https://api.openstreetmap.org/api/0.6/",
"myappname");
but there is problem as Cannot Resolve the Constructor OSMConnection
The result of the nodes endpoint can contain deleted nodes. These nodes does not have lat and lon properties since they are invisible. In the case when there are at least one deleted node in the result, the parser throws a NullPointerException.
Here is an example response:
http://api.openstreetmap.org/api/0.6/nodes?nodes=5
<osm version="0.6" generator="CGImap 0.4.0 (6509 thorn-04.openstreetmap.org)" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/">
<node id="5" visible="false" version="4" changeset="9249514" timestamp="2011-09-08T21:13:24Z" user="mattfromderby" uid="15867"/>
</osm>
Here is the relevant part of the stacktrace:
Caused by: de.westnordost.osmapi.common.errors.XmlParserException: Error parsing XML at START_TAG (empty) @3:115 in java.io.InputStreamReader@28416773 at de.westnordost.osmapi.common.XmlParser.doParse(XmlParser.java:59) at de.westnordost.osmapi.map.MapDataParser.parse(MapDataParser.java:62) at de.westnordost.osmapi.map.MapDataParser.parse(MapDataParser.java:25) at de.westnordost.osmapi.OsmConnection.handleResponse(OsmConnection.java:271) ... 36 more Caused by: java.lang.NullPointerException at de.westnordost.osmapi.map.MapDataParser.onStartElement(MapDataParser.java:127) at de.westnordost.osmapi.common.XmlParser.doParse(XmlParser.java:40) ... 39 more
Is there any methods to listen for map data request complete? I need to display data only after everything is loaded (very small part of data, few mb)
Hey
shouldn't the "configuration" in the readme be "configurations" because I can't get it to work otherwise? And after changing that, I get the following error:
* What went wrong:
Script compilation errors:
Line 08: all*.exclude group: 'net.sf.kxml', module: 'kxml2'
^ Expecting an element
Line 08: all*.exclude group: 'net.sf.kxml', module: 'kxml2'
^ Unexpected tokens (use ';' to separate expressions on the same line)
Line 12: compile.exclude group: 'org.jetbrains', module:'annotations'
^ Expecting an element
Line 12: compile.exclude group: 'org.jetbrains', module:'annotations'
^ Unexpected tokens (use ';' to separate expressions on the same line)
Line 13: compile.exclude group: 'com.intellij', module:'annotations'
^ Expecting an element
Line 13: compile.exclude group: 'com.intellij', module:'annotations'
^ Unexpected tokens (use ';' to separate expressions on the same line)
Line 14: compile.exclude group: 'org.intellij', module:'annotations'
^ Expecting an element
Line 14: compile.exclude group: 'org.intellij', module:'annotations'
^ Unexpected tokens (use ';' to separate expressions on the same line)
The code snippet is the configurations from the readme i.e:
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'
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.