Interface Feature

All Superinterfaces:
Iterable<Feature>
All Known Subinterfaces:
Node, Relation, Way

public interface Feature extends Iterable<Feature>
A geographic feature.
  • Method Summary

    Modifier and Type
    Method
    Description
    default double
    Measures the area of a feature.
    boolean
    Checks whether this feature is a member of the given Relation, or a node in the given Way.
    boolean
    Checks whether this Feature is a member of a Relation.
    boolean
     
    Retrieves the bounding box of the feature.
    double
    Returns the value of the given key as a double.
    boolean
    Checks whether this feature has a tag with the given key.
    boolean
    hasTag(String key, String value)
    Checks whether this feature has a tag with the given key and value.
    long
    id()
    Returns the OSM ID of the feature.
    int
    Returns the value of a tag as an integer.
    boolean
    Checks whether this Feature represents an area.
    default boolean
    Checks if this Feature is an OSM node.
    boolean
    Checks whether this feature is a *placeholder*.
    default boolean
    Checks if this Feature is an OSM relation.
    default boolean
    Checks if this Feature is an OSM way.
    default double
    lat()
    Returns the latitude of this feature.
    default double
    Measures the length of a feature.
    default double
    lon()
    Returns the longitude of this feature.
    default Features
    Returns the members of this `Relation`.
    default Features
    members(String query)
    Returns the members of this `Relation` that match the given query.
    default Features
    Returns the way's nodes.
    default Features
    nodes(String query)
    Returns the way's nodes that match the given query.
    Returns all ways and relations to which this Feature belongs.
    parents(String query)
    Returns all ways and relations to which this Feature belongs that match the given query.
    If this Feature was returned by a call to members() (or its variants) of a Relation, returns this Feature's role in that Relation.
    Returns the value of a tag as a String.
    tag(String key)
    Returns the string value of the given key.
    Returns the tags of this feature.
    Creates a JTS Geometry object for this feature.
    int[]
    Returns the way's coordinates as an array of integers.
    Returns the feature's type.
    int
    x()
    Returns the X coordinate of this feature.
    int
    y()
    Returns the Y coordinate of this feature.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • id

      long id()
      Returns the OSM ID of the feature. For nodes that have no tags and are not member of any relation, the ID may be 0.
      Returns:
      the feature's OSM ID
    • type

      FeatureType type()
      Returns the feature's type.
      Returns:
      `NODE`, `WAY` or `RELATION`
    • isNode

      default boolean isNode()
      Checks if this Feature is an OSM node.
    • isWay

      default boolean isWay()
      Checks if this Feature is an OSM way.
    • isRelation

      default boolean isRelation()
      Checks if this Feature is an OSM relation.
    • x

      int x()
      Returns the X coordinate of this feature. For a `Way` or `Relation`, this is the horizontal midpoint of its bounding box.
      Returns:
      X coordinate in Mercator projection
    • y

      int y()
      Returns the Y coordinate of this feature. For a `Way` or `Relation`, this is the vertical midpoint of its bounding box.
      Returns:
      Y coordinate in Mercator projection
    • lon

      default double lon()
      Returns the longitude of this feature. For a Way or Relation, this is the horizontal midpoint of its bounding box.
      Returns:
      longitude as degrees
    • lat

      default double lat()
      Returns the latitude of this feature. For a Way or Relation, this is the vertical midpoint of its bounding box.
      Returns:
      longitude as degrees
    • bounds

      Box bounds()
      Retrieves the bounding box of the feature.
      Returns:
      a copy of the Feature's bounding box
    • toXY

      int[] toXY()
      Returns the way's coordinates as an array of integers. X coordinates are stored at even index positions, Y at odd.
      Returns:
      an array of coordinate pairs
    • tags

      Tags tags()
      Returns the tags of this feature.
      Returns:
      the feature's tags
    • tag

      String tag(String key)
      Returns the string value of the given key.
      Parameters:
      key - the tag's key
      Returns:
      the string value of the tag, or an empty string if this feature does not have the requested tag
    • hasTag

      boolean hasTag(String key)
      Checks whether this feature has a tag with the given key.
      Parameters:
      key - the key (e.g. highway)
      Returns:
      true if feature is tagged with this key, otherwise false
    • hasTag

      boolean hasTag(String key, String value)
      Checks whether this feature has a tag with the given key and value.
      Parameters:
      key - the key (e.g. highway)
      value - the value (e.g. residential)
      Returns:
      true if the feature is tagged with this key/value, otherwise false
    • belongsTo

      boolean belongsTo(Feature parent)
      Checks whether this feature is a member of the given Relation, or a node in the given Way.
      Parameters:
      parent - `Way` or `Relation`
      Returns:
      `true` if this Feature belongs to the given `Way` or `Relation` (always `false` if `parent` is a `Node`)
    • role

      String role()
      If this Feature was returned by a call to members() (or its variants) of a Relation, returns this Feature's role in that Relation.
      Returns:
      the feature's role, or an empty String (if the feature is a member without an assigned role), or `null` if it was obtained via another kind of query
    • stringValue

      String stringValue(String key)
      Returns the value of a tag as a String.
      Parameters:
      key - the key of the tag
      Returns:
      the tag's value, or an empty String if the tag does not exist
    • intValue

      int intValue(String key)
      Returns the value of a tag as an integer.
      Parameters:
      key - the key of the tag
      Returns:
      the tag's value, or `0` if the tag does not exist or has a value that cannot be converted to an integer
    • doubleValue

      double doubleValue(String key)
      Returns the value of the given key as a double.
      Parameters:
      key -
      Returns:
      the key's value, or 0 if the key does not exist, or its value is not a valid number
    • booleanValue

      boolean booleanValue(String key)
    • belongsToRelation

      boolean belongsToRelation()
      Checks whether this Feature is a member of a Relation.
      Returns:
      `true` if this Feature belongs to at least one Relation
    • isArea

      boolean isArea()
      Checks whether this Feature represents an area. Areas are closed ways that have certain tags (e.g. landuse), or are explicitly tagged with area=yes; or relations that represent (multi-) polygons.
      Returns:
      true if this feature is an area, otherwise false
    • isPlaceholder

      boolean isPlaceholder()
      Checks whether this feature is a *placeholder*. A placeholder is a feature that is referenced by a relation, but is not actually present in a dataset.
      Returns:
    • length

      default double length()
      Measures the length of a feature.
      Returns:
      length (in meters), or 0 if the feature is not lineal. TODO: should return circumference for areas
    • area

      default double area()
      Measures the area of a feature.
      Returns:
      area (in square meters), or 0 if the feature is not polygonal
    • toGeometry

      Geometry toGeometry()
      Creates a JTS Geometry object for this feature. The returned following types of geometries are created: - For a `Node`: Point - For a non-closed `Way`: LineString - For a closed `Way`: Polygon if it represents an area, otherwise LinearRing - For a `Relation` that is an area: Polygon - For a non-area `Relation`: GeometryCollection
      Returns:
      a newly created Geometry.
    • nodes

      default Features nodes()
      Returns the way's nodes.
      Returns:
      an ordered collection of Feature objects
    • nodes

      default Features nodes(String query)
      Returns the way's nodes that match the given query.
      Parameters:
      query - a query in GOQL format
      Returns:
      an ordered collection of Feature objects that match the given query (may be empty)
    • members

      default Features members()
      Returns the members of this `Relation`.
      Returns:
      a collection of features that belong to this relation, or an empty collection if this relation has no members
    • members

      default Features members(String query)
      Returns the members of this `Relation` that match the given query.
      Parameters:
      query - a query in GOQL format
      Returns:
      a collection of member features that match the given query (may be empty)
    • parents

      Features parents()
      Returns all ways and relations to which this Feature belongs.
      Returns:
      a collection of ways and/or relations (may be empty)
    • parents

      Features parents(String query)
      Returns all ways and relations to which this Feature belongs that match the given query.
      Parameters:
      query - a query in GOQL format
      Returns:
      a collection of ways and/or relations (may be empty)