Class OverpassMapDataApi


  • public class OverpassMapDataApi
    extends java.lang.Object
    Get map data from the overpass api. Always expects XMl output in the queries.
    • Constructor Summary

      Constructors 
      Constructor Description
      OverpassMapDataApi​(de.westnordost.osmapi.OsmConnection osm)  
      OverpassMapDataApi​(de.westnordost.osmapi.OsmConnection osm, de.westnordost.osmapi.map.MapDataFactory mapDataFactory)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      OverpassStatus getStatus()
      Get info about how many queries the user may make until reaching his quota
      void killMyQueries()
      Kills all the queries sent from this IP.
      <T> T query​(java.lang.String query, de.westnordost.osmapi.ApiResponseReader<T> reader)
      Executes the given query.
      ElementCount queryCount​(java.lang.String query)
      Executes the given query to count the elements.
      void queryElements​(java.lang.String query, de.westnordost.osmapi.map.handler.MapDataHandler handler)
      Executes the given query and expects a response that is alike a map data query on the OSM API, just returning the map data.
      void queryElementsWithGeometry​(java.lang.String query, MapDataWithGeometryHandler handler)
      Executes the given query that has the geom modificator.
      void queryTable​(java.lang.String query, de.westnordost.osmapi.common.Handler<java.lang.String[]> handler)  
      void queryTable​(java.lang.String query, de.westnordost.osmapi.common.Handler<java.lang.String[]> handler, java.lang.String separator)
      Executes the given query that has the output mode set to CSV.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OverpassMapDataApi

        public OverpassMapDataApi​(@NotNull
                                  de.westnordost.osmapi.OsmConnection osm,
                                  @NotNull
                                  de.westnordost.osmapi.map.MapDataFactory mapDataFactory)
      • OverpassMapDataApi

        public OverpassMapDataApi​(@NotNull
                                  de.westnordost.osmapi.OsmConnection osm)
    • Method Detail

      • queryElements

        public void queryElements​(@NotNull
                                  java.lang.String query,
                                  @NotNull
                                  de.westnordost.osmapi.map.handler.MapDataHandler handler)
        Executes the given query and expects a response that is alike a map data query on the OSM API, just returning the map data. For example a query with out body;.
        Parameters:
        query - Query string. Either Overpass QL or Overpass XML query string.
        handler - handler to feed the map data to
        Throws:
        OsmTooManyRequestsException - if the user is over his request quota. See getStatus, killMyQueries
        de.westnordost.osmapi.common.errors.OsmBadUserInputException - if there is an error in the query
      • queryElementsWithGeometry

        public void queryElementsWithGeometry​(@NotNull
                                              java.lang.String query,
                                              @NotNull
                                              MapDataWithGeometryHandler handler)
        Executes the given query that has the geom modificator. For example a query with out body geom;. See out statements.
        Parameters:
        query - Query string. Either Overpass QL or Overpass XML query string. The query must contain the geom modificator.
        handler - function to feed the map data and geometry to
        Throws:
        OsmTooManyRequestsException - if the user is over his request quota. See getStatus, killMyQueries
        de.westnordost.osmapi.common.errors.OsmBadUserInputException - if there is an error in the query
      • queryTable

        public void queryTable​(@NotNull
                               java.lang.String query,
                               @NotNull
                               de.westnordost.osmapi.common.Handler<java.lang.String[]> handler,
                               @NotNull
                               java.lang.String separator)
        Executes the given query that has the output mode set to CSV.
        Parameters:
        query - Query string. Either Overpass QL or Overpass XML query string. The query must use the output mode CSV.
        handler - function to feed the map data and geometry to
        separator - The separator to expect in the CSV response. The default is the tab character.
        Throws:
        OsmTooManyRequestsException - if the user is over his request quota. See getStatus, killMyQueries
        de.westnordost.osmapi.common.errors.OsmBadUserInputException - if there is an error in the query
      • queryTable

        public void queryTable​(@NotNull
                               java.lang.String query,
                               @NotNull
                               de.westnordost.osmapi.common.Handler<java.lang.String[]> handler)
        See Also:
        queryTable(String, Handler)
      • queryCount

        @NotNull
        public ElementCount queryCount​(@NotNull
                                       java.lang.String query)
        Executes the given query to count the elements. For example a query with out count;. See out statements.
        Parameters:
        query - Query string. Either Overpass QL or Overpass XML query string. The query must end with out count;
        Returns:
        the count for each element type
        Throws:
        OsmTooManyRequestsException - if the user is over his request quota. See getStatus, killMyQueries
        de.westnordost.osmapi.common.errors.OsmBadUserInputException - if there is an error in the query
      • query

        public <T> T query​(@NotNull
                           java.lang.String query,
                           de.westnordost.osmapi.ApiResponseReader<T> reader)
        Executes the given query. Since the output format and the content of the output can vary greatly depending on the type of query, you must specify yourself how you are going to parse the result.
        Type Parameters:
        T - what the type of object the reader returns
        Parameters:
        query - Query string. Either Overpass QL or Overpass XML query string
        reader - the object reading the response
        Returns:
        what the supplied reader returns
        Throws:
        OsmTooManyRequestsException - if the user is over his request quota. See getStatus, killMyQueries
        de.westnordost.osmapi.common.errors.OsmBadUserInputException - if there is an error in the query
      • killMyQueries

        public void killMyQueries()
        Kills all the queries sent from this IP. Useful if there is a runaway query that takes far too much time and blocks the user from making any more queries
      • getStatus

        public OverpassStatus getStatus()
        Get info about how many queries the user may make until reaching his quota
        Returns:
        the current quota status