Class Feature

java.lang.Object
dev.avelar.mapnik.Feature

public final class Feature extends Object
One feature: an id, named attributes and a geometry. A feature is a plain snapshot. It holds no native memory, so there is nothing to close and it stays valid after the Featureset that produced it is closed. Features come out of queries, or you build them with create(long, dev.avelar.mapnik.Geometry, java.util.Map<java.lang.String, ?>) and add them to a MemoryDatasource.
  • Method Details

    • create

      public static Feature create(long id, Geometry geometry, Map<String,?> attributes)
      Build a feature. Attribute values may be null, String, Boolean, Integer, Long, Short, Byte, Double or Float; whole numbers become Long and floats become Double. Attributes are kept in name order, as features read from a datasource are.
    • create

      public static Feature create(long id, Geometry geometry)
    • reproject

      public Feature reproject(CoordinateTransform transform)
      A copy of this feature with its geometry reprojected. The id and attributes are unchanged.
    • fromGeoJson

      public static Feature fromGeoJson(String json, long defaultId)
      Read a GeoJSON Feature. Its properties become attributes: strings, booleans and null as they are, numbers as Long if they are whole and Double otherwise, and nested objects or arrays as their JSON text. The id is used if it is a whole number, else defaultId.
    • fromGeoJson

      public static Feature fromGeoJson(String json)
      As fromGeoJson(String, long), with id 1 if the feature has none.
    • listFromGeoJson

      public static List<Feature> listFromGeoJson(String json)
      Read every feature of a GeoJSON FeatureCollection, or the single feature of a Feature. Features without a whole-number id are numbered from 1 by their position.
    • id

      public long id()
    • attributes

      public Map<String,Object> attributes()
      Attributes by name, in name order. Values are null, Boolean, Long, Double or String.
    • attribute

      public Object attribute(String name)
      One attribute, or null if it is missing or null.
    • geometryKind

      public GeometryKind geometryKind()
      GeometryKind.UNKNOWN if the feature has no geometry.
    • envelope

      public Box2d envelope()
      Bounding box of the geometry, in the datasource's projection. Null for an empty geometry.
    • geometry

      public Geometry geometry()
      The geometry as an object you can inspect, reproject and so on. Empty if the feature has none.
    • geometryWkt

      public String geometryWkt()
      The geometry as WKT, for example POINT(1 2). Mapnik normalises polygon ring orientation.
    • geometryGeoJson

      public String geometryGeoJson()
      The geometry as a GeoJSON geometry object. The text null for an empty geometry.
    • toGeoJson

      public String toGeoJson()
      The whole feature as a GeoJSON Feature.
    • toString

      public String toString()
      Overrides:
      toString in class Object