org.gdal.ogr

## Class Feature

- java.lang.Object
- - org.gdal.ogr.Feature

- All Implemented Interfaces:
    Cloneable

      public class Feature
      extends Object
      implements Cloneable

  A simple feature, including geometry and attributes.

  The Feature class is a binding for the C++ OGRFeature class.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Feature(FeatureDefn feature_def)` Constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `Object` | `clone()`
    `Feature` | `Clone()` Duplicate feature.
    `void` | `delete()` Delete (in memory) a feature.
    `void` | `DumpReadable()` Dump this feature in a human readable form.
    `boolean` | `Equal(Feature feature)` Test if two features are the same.
    `boolean` | `equals(Object obj)`
    `void` | `FillUnsetWithDefault()`
    `void` | `FillUnsetWithDefault(int bNotNullableOnly)`
    `void` | `FillUnsetWithDefault(int bNotNullableOnly, Vector options)`
    `FeatureDefn` | `GetDefnRef()` Fetch feature definition.
    `long` | `GetFID()` Get feature identifier.
    `byte[]` | `GetFieldAsBinary(int id)`
    `byte[]` | `GetFieldAsBinary(String name)`
    `void` | `GetFieldAsDateTime(int id, int[] pnYear, int[] pnMonth, int[] pnDay, int[] pnHour, int[] pnMinute, float[] pfSecond, int[] pnTZFlag)`
    `void` | `GetFieldAsDateTime(String name, int[] pnYear, int[] pnMonth, int[] pnDay, int[] pnHour, int[] pnMinute, float[] pfSecond, int[] pnTZFlag)`
    `double` | `GetFieldAsDouble(int ifield)` Fetch field value as a double.
    `double` | `GetFieldAsDouble(String name)` Fetch field value as a double.
    `double[]` | `GetFieldAsDoubleList(int ifield)` Fetch field value as a list of doubles.
    `int` | `GetFieldAsInteger(int ifield)` Fetch field value as integer.
    `int` | `GetFieldAsInteger(String name)` Fetch field value as integer.
    `long` | `GetFieldAsInteger64(int id)`
    `long` | `GetFieldAsInteger64(String name)`
    `int[]` | `GetFieldAsIntegerList(int ifield)` Fetch field value as a list of integers.
    `String` | `GetFieldAsString(int ifield)` Fetch field value as a string.
    `String` | `GetFieldAsString(String name)` Fetch field value as a string.
    `String[]` | `GetFieldAsStringList(int ifield)` Fetch field value as a list of strings.
    `int` | `GetFieldCount()` Fetch number of fields on this feature.
    `FieldDefn` | `GetFieldDefnRef(int ifield)` Fetch definition for this field.
    `FieldDefn` | `GetFieldDefnRef(String name)` Fetch definition for this field.
    `int` | `GetFieldIndex(String name)` Fetch the field index given field name.
    `int` | `GetFieldType(int ifield)` Fetch the field type.
    `int` | `GetFieldType(String name)` Fetch the field type.
    `Geometry` | `GetGeometryRef()` Fetch pointer to feature geometry.
    `int` | `GetGeomFieldCount()`
    `GeomFieldDefn` | `GetGeomFieldDefnRef(int id)`
    `GeomFieldDefn` | `GetGeomFieldDefnRef(String name)`
    `int` | `GetGeomFieldIndex(String name)`
    `Geometry` | `GetGeomFieldRef(int iField)`
    `Geometry` | `GetGeomFieldRef(String name)`
    `String` | `GetNativeData()`
    `String` | `GetNativeMediaType()`
    `String` | `GetStyleString()` Fetch style string for this feature.
    `int` | `hashCode()`
    `boolean` | `IsFieldSet(int ifield)` Test if a field has ever been assigned a value or not.
    `boolean` | `IsFieldSet(String name)` Test if a field has ever been assigned a value or not.
    `int` | `SetFID(long fid)` Set the feature identifier.
    `void` | `SetField(int ifield, double val)` Set field to double value.
    `void` | `SetField(int ifield, int val)` Set field to integer value.
    `void` | `SetField(int id, int year, int month, int day, int hour, int minute, float second, int tzflag)`
    `void` | `SetField(int ifield, String val)` Set field to string value.
    `void` | `SetField(String name, double val)` Set field to double value.
    `void` | `SetField(String name, int val)` Set field to integer value.
    `void` | `SetField(String name, int year, int month, int day, int hour, int minute, float second, int tzflag)`
    `void` | `SetField(String name, String val)` Set field to string value.
    `void` | `SetFieldBinaryFromHexString(int id, String pszValue)`
    `void` | `SetFieldBinaryFromHexString(String name, String pszValue)`
    `void` | `SetFieldDoubleList(int ifield, double[] values)` Set field to list of doubles value.
    `void` | `SetFieldInteger64(int id, long value)`
    `void` | `SetFieldIntegerList(int ifield, int[] values)` Set field to list of integers value.
    `void` | `SetFieldStringList(int ifield, Vector values)` Set field to list of strings value.
    `int` | `SetFrom(Feature srcFeature)` Set one feature from another.
    `int` | `SetFrom(Feature srcFeature, int forgiving)` Set one feature from another.
    `int` | `SetFromWithMap(Feature srcFeature, int forgiving, int[] map)` Set one feature from another.
    `int` | `SetGeometry(Geometry geom)` Set feature geometry.
    `int` | `SetGeometryDirectly(Geometry geom)` Set feature geometry.
    `int` | `SetGeomField(int iField, Geometry geom)`
    `int` | `SetGeomField(String name, Geometry geom)`
    `int` | `SetGeomFieldDirectly(int iField, Geometry geom)`
    `int` | `SetGeomFieldDirectly(String name, Geometry geom)`
    `void` | `SetNativeData(String nativeData)`
    `void` | `SetNativeMediaType(String nativeMediaType)`
    `void` | `SetStyleString(String style_string)` Set feature style string.
    `void` | `UnsetField(int ifield)` Clear a field, marking it as unset.
    `void` | `UnsetField(String name)` Clear a field, marking it as unset.
    `int` | `Validate()`
    `int` | `Validate(int flags)`
    `int` | `Validate(int flags, int bEmitError)`

    - ### Methods inherited from class java.lang.Object

      `getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Feature

          public Feature(FeatureDefn feature_def)

      Constructor.

      Note that the Feature will increment the reference count of its defining FeatureDefn.

      Parameters:
        `feature_def` - feature class (layer) definition to which the feature will adhere.

  - ### Method Detail

    - #### delete

          public void delete()

      Delete (in memory) a feature.

      Calling this method is not required as normal garbage collection will reclaim associated resources when the object goes out of scope. Otherwise calling delete() explicitly will help release resources sooner. Don't call any method on a deleted object !

    - #### equals

          public boolean equals(Object obj)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### clone

          public Object clone()

      Overrides:
        `clone` in class `Object`

    - #### GetDefnRef

          public FeatureDefn GetDefnRef()

      Fetch feature definition.
      Returns:
        a reference to the feature definition object.

    - #### SetGeometry

          public int SetGeometry(Geometry geom)

      Set feature geometry.

      This method updates the features geometry, and operate exactly as SetGeometryDirectly(), except that this method does not assume ownership of the passed geometry, but instead makes a copy of it.

      Parameters:
        `geom` - new geometry to apply to feature. Passing null value here is correct and it will result in deallocation of currently assigned geometry without assigning new one.
      Returns:
        0 if successful, or throws a RuntimeException (or an error code if DontUseExceptions() has been called) if the geometry type is illegal for the FeatureDefn (checking not yet implemented).

    - #### SetGeometryDirectly

          public int SetGeometryDirectly(Geometry geom)

      Set feature geometry.

      This method updates the features geometry, and operate exactly as SetGeometry(), except that this method assumes ownership of the passed geometry.

      Parameters:
        `geom` - new geometry to apply to feature. Passing null value here is correct and it will result in deallocation of currently assigned geometry without assigning new one.
      Returns:
        0 if successful, or throws a RuntimeException (or an error code if DontUseExceptions() has been called) if the geometry type is illegal for the FeatureDefn (checking not yet implemented).

    - #### GetGeometryRef

          public Geometry GetGeometryRef()

      Fetch pointer to feature geometry.
      Returns:
        internal feature geometry (or null if no geometry). This object should not be modified.

    - #### SetGeomField

          public int SetGeomField(int iField,
                         Geometry geom)

    - #### SetGeomField

          public int SetGeomField(String name,
                         Geometry geom)

    - #### SetGeomFieldDirectly

          public int SetGeomFieldDirectly(int iField,
                                 Geometry geom)

    - #### SetGeomFieldDirectly

          public int SetGeomFieldDirectly(String name,
                                 Geometry geom)

    - #### GetGeomFieldRef

          public Geometry GetGeomFieldRef(int iField)

    - #### GetGeomFieldRef

          public Geometry GetGeomFieldRef(String name)

    - #### Clone

          public Feature Clone()

      Duplicate feature.

      The newly created feature is owned by the caller, and will have its own reference to the FeatureDefn.

      Returns:
        new feature, exactly matching this feature.

    - #### Equal

          public boolean Equal(Feature feature)

      Test if two features are the same.

      Two features are considered equal if they share the (pointer equality) same FeatureDefn, have the same field values, and the same geometry (as tested by Geometry.Equal()) as well as the same feature id.

      Parameters:
        `feature` - the other feature to test this one against.
      Returns:
        true if they are equal, otherwise false.

    - #### GetFieldCount

          public int GetFieldCount()

      Fetch number of fields on this feature. This will always be the same as the field count for the FeatureDefn.
      Returns:
        count of fields.

    - #### GetFieldDefnRef

          public FieldDefn GetFieldDefnRef(int ifield)

      Fetch definition for this field.
      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
      Returns:
        the field definition (from the FeatureDefn).

    - #### GetFieldDefnRef

          public FieldDefn GetFieldDefnRef(String name)

      Fetch definition for this field.
      Parameters:
        `name` - the name of the field to fetch.
      Returns:
        the field definition (from the FeatureDefn).

    - #### GetGeomFieldCount

          public int GetGeomFieldCount()

    - #### GetGeomFieldDefnRef

          public GeomFieldDefn GetGeomFieldDefnRef(int id)

    - #### GetGeomFieldDefnRef

          public GeomFieldDefn GetGeomFieldDefnRef(String name)

    - #### GetFieldAsString

          public String GetFieldAsString(int ifield)

      Fetch field value as a string.

      OFTReal and OFTInteger fields will be translated to string using sprintf(), but not necessarily using the established formatting rules. Other field types, or errors will result in a return value of zero.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
      Returns:
        the field value.

    - #### GetFieldAsString

          public String GetFieldAsString(String name)

      Fetch field value as a string.

      OFTReal and OFTInteger fields will be translated to string using sprintf(), but not necessarily using the established formatting rules. Other field types, or errors will result in a return value of zero.

      Parameters:
        `name` - the name of the field to fetch.
      Returns:
        the field value.

    - #### GetFieldAsInteger

          public int GetFieldAsInteger(int ifield)

      Fetch field value as integer.

      OFTString features will be translated using atoi(). OFTReal fields will be cast to integer. Other field types, or errors will result in a return value of zero.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
      Returns:
        the field value.

    - #### GetFieldAsInteger

          public int GetFieldAsInteger(String name)

      Fetch field value as integer.

      OFTString features will be translated using atoi(). OFTReal fields will be cast to integer. Other field types, or errors will result in a return value of zero.

      Parameters:
        `name` - the name of the field to fetch.
      Returns:
        the field value.

    - #### GetFieldAsInteger64

          public long GetFieldAsInteger64(int id)

    - #### GetFieldAsInteger64

          public long GetFieldAsInteger64(String name)

    - #### GetFieldAsDouble

          public double GetFieldAsDouble(int ifield)

      Fetch field value as a double.

      OFTString features will be translated using atof(). OFTInteger fields will be cast to double. Other field types, or errors will result in a return value of zero.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
      Returns:
        the field value.

    - #### GetFieldAsDouble

          public double GetFieldAsDouble(String name)

      Fetch field value as a double.

      OFTString features will be translated using atof(). OFTInteger fields will be cast to double. Other field types, or errors will result in a return value of zero.

      Parameters:
        `name` - the name of the field to fetch.
      Returns:
        the field value.

    - #### GetFieldAsDateTime

          public void GetFieldAsDateTime(int id,
                                int[] pnYear,
                                int[] pnMonth,
                                int[] pnDay,
                                int[] pnHour,
                                int[] pnMinute,
                                float[] pfSecond,
                                int[] pnTZFlag)

    - #### GetFieldAsDateTime

          public void GetFieldAsDateTime(String name,
                                int[] pnYear,
                                int[] pnMonth,
                                int[] pnDay,
                                int[] pnHour,
                                int[] pnMinute,
                                float[] pfSecond,
                                int[] pnTZFlag)

    - #### GetFieldAsIntegerList

          public int[] GetFieldAsIntegerList(int ifield)

      Fetch field value as a list of integers.

      Currently this method only works for OFTIntegerList fields.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
      Returns:
        the field value. The returned value may be null.
      Since:
        Java bindings 1.7.0

    - #### GetFieldAsDoubleList

          public double[] GetFieldAsDoubleList(int ifield)

      Fetch field value as a list of doubles.

      Currently this method only works for OFTRealList fields.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
      Returns:
        the field value. The returned value may be null.
      Since:
        Java bindings 1.7.0

    - #### GetFieldAsStringList

          public String[] GetFieldAsStringList(int ifield)

      Fetch field value as a list of strings.

      Currently this method only works for OFTStringList fields.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
      Returns:
        the field value. The returned value may be null.
      Since:
        Java bindings 1.7.0

    - #### GetFieldAsBinary

          public byte[] GetFieldAsBinary(int id)

    - #### GetFieldAsBinary

          public byte[] GetFieldAsBinary(String name)

    - #### IsFieldSet

          public boolean IsFieldSet(int ifield)

      Test if a field has ever been assigned a value or not.
      Parameters:
        `ifield` - the field to test.
      Returns:
        true if the field has been set, otherwise false.

    - #### IsFieldSet

          public boolean IsFieldSet(String name)

      Test if a field has ever been assigned a value or not.
      Parameters:
        `name` - the name of the field to test.
      Returns:
        true if the field has been set, otherwise false.

    - #### GetFieldIndex

          public int GetFieldIndex(String name)

      Fetch the field index given field name. This is a cover for the FeatureDefn.GetFieldIndex() method.
      Parameters:
        `name` - the name of the field to search for.
      Returns:
        the field index, or -1 if no matching field is found.

    - #### GetGeomFieldIndex

          public int GetGeomFieldIndex(String name)

    - #### GetFID

          public long GetFID()

      Get feature identifier.
      Returns:
        feature id or OGRNullFID if none has been assigned.

    - #### SetFID

          public int SetFID(long fid)

      Set the feature identifier.

      For specific types of features this operation may fail on illegal features ids. Generally it always succeeds. Feature ids should be greater than or equal to zero, with the exception of OGRNullFID (-1) indicating that the feature id is unknown.

      Parameters:
        `fid` - the new feature identifier value to assign.
      Returns:
        0 on success. Otherwise throws a RuntimeException (or an error code if DontUseExceptions() has been called).

    - #### DumpReadable

          public void DumpReadable()

      Dump this feature in a human readable form.

      This dumps the attributes, and geometry; however, it doesn't definition information (other than field types and names), nor does it report the geometry spatial reference system. The standard output will be used.

    - #### UnsetField

          public void UnsetField(int ifield)

      Clear a field, marking it as unset.
      Parameters:
        `ifield` - the field to unset, from 0 to GetFieldCount()-1.

    - #### UnsetField

          public void UnsetField(String name)

      Clear a field, marking it as unset.
      Parameters:
        `name` - the name of the field to unset.

    - #### SetField

          public void SetField(int ifield,
                      String val)

      Set field to string value.

      OFTInteger fields will be set based on an atoi() conversion of the string. OFTReal fields will be set based on an atof() conversion of the string. Other field types may be unaffected.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
        `val` - the value to assign.

    - #### SetField

          public void SetField(String name,
                      String val)

      Set field to string value.

      OFTInteger fields will be set based on an atoi() conversion of the string. OFTReal fields will be set based on an atof() conversion of the string. Other field types may be unaffected.

      Parameters:
        `name` - the name of the field to set.
        `val` - the value to assign.

    - #### SetFieldInteger64

          public void SetFieldInteger64(int id,
                               long value)

    - #### SetField

          public void SetField(int ifield,
                      int val)

      Set field to integer value.

      OFTInteger and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
        `val` - the value to assign.

    - #### SetField

          public void SetField(String name,
                      int val)

      Set field to integer value.

      OFTInteger and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

      Parameters:
        `name` - the name of the field to set.
        `val` - the value to assign.

    - #### SetField

          public void SetField(int ifield,
                      double val)

      Set field to double value.

      OFTInteger and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
        `val` - the value to assign.

    - #### SetField

          public void SetField(String name,
                      double val)

      Set field to double value.

      OFTInteger and OFTReal fields will be set directly. OFTString fields will be assigned a string representation of the value, but not necessarily taking into account formatting constraints on this field. Other field types may be unaffected.

      Parameters:
        `name` - the name of the field to set.
        `val` - the value to assign.

    - #### SetField

          public void SetField(int id,
                      int year,
                      int month,
                      int day,
                      int hour,
                      int minute,
                      float second,
                      int tzflag)

    - #### SetField

          public void SetField(String name,
                      int year,
                      int month,
                      int day,
                      int hour,
                      int minute,
                      float second,
                      int tzflag)

    - #### SetFieldIntegerList

          public void SetFieldIntegerList(int ifield,
                                 int[] values)

      Set field to list of integers value.

      This method currently on has an effect of OFTIntegerList fields.

      Parameters:
        `ifield` - the field to set, from 0 to GetFieldCount()-1.
        `values` - the values to assign.

    - #### SetFieldDoubleList

          public void SetFieldDoubleList(int ifield,
                                double[] values)

      Set field to list of doubles value.

      This method currently on has an effect of OFTRealList fields.

      Parameters:
        `ifield` - the field to set, from 0 to GetFieldCount()-1.
        `values` - the values to assign.

    - #### SetFieldStringList

          public void SetFieldStringList(int ifield,
                                Vector values)

      Set field to list of strings value.

      This method currently on has an effect of OFTStringList fields.

      Parameters:
        `ifield` - the field to set, from 0 to GetFieldCount()-1.
        `values` - the values to assign (vector of strings).
      Since:
        Java bindings 1.7.0

    - #### SetFieldBinaryFromHexString

          public void SetFieldBinaryFromHexString(int id,
                                         String pszValue)

    - #### SetFieldBinaryFromHexString

          public void SetFieldBinaryFromHexString(String name,
                                         String pszValue)

    - #### SetFrom

          public int SetFrom(Feature srcFeature,
                    int forgiving)

      Set one feature from another.

      Overwrite the contents of this feature from the geometry and attributes of another. The srcFeature does not need to have the same FeatureDefn. Field values are copied by corresponding field names. Field types do not have to exactly match. SetField() method conversion rules will be applied as needed.

      Parameters:
        `srcFeature` - the feature from which geometry, and field values will be copied.
        `forgiving` - 1 if the operation should continue despite lacking output fields matching some of the source fields.
      Returns:
        0 if the operation succeeds, even if some values are not transferred, otherwise throws a RuntimeException (or an error code if DontUseExceptions() has been called).
      See Also:
        `SetFromWithMap(org.gdal.ogr.Feature srcFeature, int forgiving, int[] map)`

    - #### SetFrom

          public int SetFrom(Feature srcFeature)

      Set one feature from another.

      Same as below with forgiving == 1

      Since:
        Java bindings 1.7.0
      See Also:
        `SetFrom(Feature srcFeature, int forgiving)`

    - #### SetFromWithMap

          public int SetFromWithMap(Feature srcFeature,
                           int forgiving,
                           int[] map)

      Set one feature from another.

      Overwrite the contents of this feature from the geometry and attributes of another. The hOtherFeature does not need to have the same OGRFeatureDefn. Field values are copied according to the provided indices map. Field types do not have to exactly match. SetField() function conversion rules will be applied as needed. This is more efficient than SetFrom(Feature, int) in that this doesn't lookup the fields by their names. Particularly useful when the field names don't match.

      Parameters:
        `srcFeature` - the feature from which geometry, and field values will be copied.
        `forgiving` - 1 if the operation should continue despite lacking output fields matching some of the source fields.
        `map` - Array of the indices of the destination feature's fields stored at the corresponding index of the source feature's fields. A value of -1 should be used to ignore the source's field. The array should not be null and be as long as the number of fields in the source feature.
      Returns:
        0 if the operation succeeds, even if some values are not transferred, otherwise throws a RuntimeException (or an error code if DontUseExceptions() has been called).
      Since:
        OGR 1.8.0
      See Also:
        `SetFrom(org.gdal.ogr.Feature srcFeature, int forgiving)`

    - #### GetStyleString

          public String GetStyleString()

      Fetch style string for this feature.

      Set the OGR Feature Style Specification for details on the format of this string, and ogr_featurestyle.h for services available to parse it.

      Returns:
        a reference to a representation in string format, or null if there isn't one.

    - #### SetStyleString

          public void SetStyleString(String style_string)

      Set feature style string.
      Parameters:
        `style_string` - the style string to apply to this feature, cannot be null.

    - #### GetFieldType

          public int GetFieldType(int ifield)

      Fetch the field type.

      This is a cover for the FeatureDefn.GetFieldType() method.

      Parameters:
        `ifield` - the field to fetch, from 0 to GetFieldCount()-1.
      Returns:
        the field type (like ogr.OFTInteger, etc.)

    - #### GetFieldType

          public int GetFieldType(String name)

      Fetch the field type.

      This is a cover for the FeatureDefn.GetFieldType() method.

      Parameters:
        `name` - the name of the field to fetch.
      Returns:
        the field type (like ogr.OFTInteger, etc.)

    - #### Validate

          public int Validate(int flags,
                     int bEmitError)

    - #### Validate

          public int Validate(int flags)

    - #### Validate

          public int Validate()

    - #### FillUnsetWithDefault

          public void FillUnsetWithDefault(int bNotNullableOnly,
                                  Vector options)

    - #### FillUnsetWithDefault

          public void FillUnsetWithDefault(int bNotNullableOnly)

    - #### FillUnsetWithDefault

          public void FillUnsetWithDefault()

    - #### GetNativeData

          public String GetNativeData()

    - #### GetNativeMediaType

          public String GetNativeMediaType()

    - #### SetNativeData

          public void SetNativeData(String nativeData)

    - #### SetNativeMediaType

          public void SetNativeMediaType(String nativeMediaType)