Class Feature

java.lang.Object
com.luciad.models.features.Feature
All Implemented Interfaces:
AutoCloseable

public final class Feature extends Object implements AutoCloseable
A Feature is a (partial) copy of a domain object.

It allows the rest of the API to easily access the domain object's properties, including any geometry. If you do a query on the model, and retrieve a Feature from it, the caller of the query receives ownership of the Feature. I.e. the caller can decide what to do with it, and when to dispose it.

This means that the Map and Layer API's are allowed to keep references to a Feature and have unrestricted lock-less access to its properties. The caller of the IFeatureModel#query method is responsible for managing the lifetime of a Feature.

To make Feature instances easy to use in a multi-threaded environment, they are

  • immutable
  • thread safe for reading

See article for more details on this class.

  • Method Details

    • finalize

      protected void finalize()
      Overrides:
      finalize in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • newBuilder

      @NotNull public static Feature.Builder newBuilder()
      Returns a new Feature Builder.
      Returns:
      a new Feature Builder.
    • asBuilder

      @NotNull public Feature.Builder asBuilder()
      Returns this Feature as a Feature.Builder.

      This makes it possible to copy a Feature, and modify values. Note that when using this builder, it is not possible to change the datatype. Only the values and the id of the Feature. Otherwise a java.lang.IllegalStateException will be thrown.

      Returns:
      this Feature as a Feature.Builder.
    • hasId

      public boolean hasId()
      Returns if this Feature has an id.

      If this method returns false, it is not allowed to call Feature#getId.

      Returns:
      if this Feature has an id.
      See Also:
    • getId

      public long getId() throws IllegalStateException
      Returns the id of this feature.

      A feature id should be unique across a model.

      When no id is set, this method will throw an exception.

      Returns:
      the id of this feature.
      Throws:
      IllegalStateException - when the feature has no id.
    • getDataType

      @NotNull public DataType getDataType()
      Returns the data type describing the feature properties.
      Returns:
      the data type describing the feature properties.
    • findGeometry

      @Nullable public Geometry findGeometry()
      Tries to find a geometry for this feature.

      If this feature's data type is annotated with GeometryDataAnnotation, the value of the corresponding property is returned. Otherwise, the result will be null.

      Returns:
      the annotated geometry, if any, else null.
      See Also:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • getValue

      @Nullable public <T> T getValue(@NotNull DataPropertyPath propertyPath) throws IllegalArgumentException
      Accesses the value for the given property.

      Example

          Boolean optBoolean = feature.<Boolean>getValue(booleanPropertyPath);
          Integer optInteger = feature.<Integer>getValue(intPropertyPath);
          Long optLong = feature.<Long>getValue(longPropertyPath);
          Float optFloat = feature.<Float>getValue(floatPropertyPath);
          Double optDouble = feature.<Double>getValue(doublePropertyPath);
          String optString = feature.<String>getValue(stringPropertyPath);
          Geometry optGeometry = feature.<Geometry>getValue(geometryPropertyPath);
          String unsetValue = feature.<String>getValue(unsetPropertyPath); // Unset property -> null
      

      Note: a ClassCastException may be thrown when trying to retrieve a geometry property value using a Geometry sub-type parameter that doesn't correspond with the actual type of the geometry property value.

      Type Parameters:
      T - the supported types are java.lang.Boolean, java.lang.Integer, java.lang.Long, java.lang.Float, java.lang.Double, java.lang.String, Geometry or a subtype of Geometry.
      Parameters:
      propertyPath - the property for which to return a value
      Returns:
      the value for the given property. If the property does exist in the DataType, but is not set for this particular feature, null is returned.
      Throws:
      IllegalArgumentException - when the property is not of a known type, if it doesn't exist in the DataType, or when the type of the value doesn't correspond with the provided type parameter (for example when the property value is a Point geometry, but it is requested using ArcBand as type parameter).