Interface Feature

All Known Subinterfaces:
Node, Relation, Way

public interface 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.
    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 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.
    Returns all relations to which this Feature belongs.
    If this Feature was returned by a call to Relation.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.
    Returns the feature's type.
    int
    x()
    Returns the X coordinate of this feature.
    int
    y()
    Returns the Y coordinate of this feature.
  • 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`
    • 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 BoundingBox
    • 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 Relation.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
    • 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
    • parentRelations

      Features<Relation> parentRelations()
      Returns all relations to which this Feature belongs.
      Returns:
      a collection of relations (may be empty)
    • 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
    • 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.