public class Feature extends Object implements Cloneable
The Feature class is a binding for the C++ OGRFeature class.
Constructor and Description |
---|
Feature(FeatureDefn feature_def)
Constructor.
|
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) |
FeatureDefn |
GetDefnRef()
Fetch feature definition.
|
int |
GetFID()
Get feature identifier.
|
void |
GetFieldAsDateTime(int ifield,
int[] pnYear,
int[] pnMonth,
int[] pnDay,
int[] pnHour,
int[] pnMinute,
int[] pnSecond,
int[] pnTZFlag)
Fetch field value as date and time.
|
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.
|
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 |
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(int 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 ifield,
int year,
int month,
int day,
int hour,
int minute,
int second,
int tzflag)
Set field to date.
|
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,
int second,
int tzflag)
Set field to date.
|
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 |
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 |
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.
|
public Feature(FeatureDefn feature_def)
Note that the Feature will increment the reference count of its defining FeatureDefn.
feature_def
- feature class (layer) definition to which the feature will
adhere.public void delete()
Calling this method is not required as normal garbage collection will reclaim associated resources when the object goes out of scope. Otherwise calling delete() explicitely will help release resources sooner. Don't call any method on a deleted object !
public FeatureDefn GetDefnRef()
public int SetGeometry(Geometry geom)
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.
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.public int SetGeometryDirectly(Geometry geom)
This method updates the features geometry, and operate exactly as SetGeometry(), except that this method assumes ownership of the passed geometry.
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.public Geometry GetGeometryRef()
public int SetGeomField(int iField, Geometry geom)
public int SetGeomFieldDirectly(int iField, Geometry geom)
public Geometry GetGeomFieldRef(int iField)
public Feature Clone()
The newly created feature is owned by the caller, and will have its own reference to the FeatureDefn.
public boolean Equal(Feature feature)
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.
feature
- the other feature to test this one against.public int GetFieldCount()
public FieldDefn GetFieldDefnRef(int ifield)
ifield
- the field to fetch, from 0 to GetFieldCount()-1.public FieldDefn GetFieldDefnRef(String name)
name
- the name of the field to fetch.public int GetGeomFieldCount()
public GeomFieldDefn GetGeomFieldDefnRef(int id)
public GeomFieldDefn GetGeomFieldDefnRef(String name)
public String GetFieldAsString(int ifield)
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.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.public String GetFieldAsString(String name)
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.
name
- the name of the field to fetch.public int GetFieldAsInteger(int ifield)
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.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.public int GetFieldAsInteger(String name)
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.
name
- the name of the field to fetch.public double GetFieldAsDouble(int ifield)
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.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.public double GetFieldAsDouble(String name)
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.
name
- the name of the field to fetch.public void GetFieldAsDateTime(int ifield, int[] pnYear, int[] pnMonth, int[] pnDay, int[] pnHour, int[] pnMinute, int[] pnSecond, int[] pnTZFlag)
Currently this method only works for OFTDate, OFTTime and OFTDateTime fields.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.pnYear
- an allocated array of 1 integer to put the year (including century)pnMonth
- an allocated array of 1 integer to put the month (1-12)pnDay
- an allocated array of 1 integer to put the day (1-31)pnHour
- an allocated array of 1 integer to put the hour (0-23)pnMinute
- an allocated array of 1 integer to put the minute (0-59)pnSecond
- an allocated array of 1 integer to put the second (0-59)pnTZFlag
- an allocated array of 1 integer to put the time zone flag (0=unknown, 1=localtime, 100=GMT, see data model for details)public int[] GetFieldAsIntegerList(int ifield)
Currently this method only works for OFTIntegerList fields.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.public double[] GetFieldAsDoubleList(int ifield)
Currently this method only works for OFTRealList fields.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.public String[] GetFieldAsStringList(int ifield)
Currently this method only works for OFTStringList fields.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.public boolean IsFieldSet(int ifield)
ifield
- the field to test.public boolean IsFieldSet(String name)
name
- the name of the field to test.public int GetFieldIndex(String name)
name
- the name of the field to search for.public int GetGeomFieldIndex(String name)
public int GetFID()
public int SetFID(int fid)
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.
fid
- the new feature identifier value to assign.public void DumpReadable()
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.
public void UnsetField(int ifield)
ifield
- the field to unset, from 0 to GetFieldCount()-1.public void UnsetField(String name)
name
- the name of the field to unset.public void SetField(int ifield, String val)
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.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.val
- the value to assign.public void SetField(String name, String val)
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.
name
- the name of the field to set.val
- the value to assign.public void SetField(int ifield, int val)
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.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.val
- the value to assign.public void SetField(String name, int val)
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.
name
- the name of the field to set.val
- the value to assign.public void SetField(int ifield, double val)
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.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.val
- the value to assign.public void SetField(String name, double val)
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.
name
- the name of the field to set.val
- the value to assign.public void SetField(int ifield, int year, int month, int day, int hour, int minute, int second, int tzflag)
This method currently only has an effect for OFTDate, OFTTime and OFTDateTime fields.
ifield
- the field to set, from 0 to GetFieldCount()-1.year
- (including century)month
- (1-12)day
- (1-31)hour
- (0-23)minute
- (0-59)second
- (0-59)tzflag
- (0=unknown, 1=localtime, 100=GMT, see data model for details)public void SetField(String name, int year, int month, int day, int hour, int minute, int second, int tzflag)
This method currently only has an effect for OFTDate, OFTTime and OFTDateTime fields.
name
- the name of the field to set.year
- (including century)month
- (1-12)day
- (1-31)hour
- (0-23)minute
- (0-59)second
- (0-59)tzflag
- (0=unknown, 1=localtime, 100=GMT, see data model for details)public void SetFieldIntegerList(int ifield, int[] values)
This method currently on has an effect of OFTIntegerList fields.
ifield
- the field to set, from 0 to GetFieldCount()-1.values
- the values to assign.public void SetFieldDoubleList(int ifield, double[] values)
This method currently on has an effect of OFTRealList fields.
ifield
- the field to set, from 0 to GetFieldCount()-1.values
- the values to assign.public void SetFieldStringList(int ifield, Vector values)
This method currently on has an effect of OFTStringList fields.
ifield
- the field to set, from 0 to GetFieldCount()-1.values
- the values to assign (vector of strings).public void SetFieldBinaryFromHexString(int id, String pszValue)
public int SetFrom(Feature srcFeature, int forgiving)
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.
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.SetFromWithMap(org.gdal.ogr.Feature srcFeature, int forgiving, int[] map)
public int SetFrom(Feature srcFeature)
Same as below with forgiving == 1
SetFrom(Feature srcFeature, int forgiving)
public int SetFromWithMap(Feature srcFeature, int forgiving, int[] map)
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.
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.SetFrom(org.gdal.ogr.Feature srcFeature, int forgiving)
public String GetStyleString()
Set the OGR Feature Style Specification for details on the format of this string, and ogr_featurestyle.h for services available to parse it.
public void SetStyleString(String style_string)
style_string
- the style string to apply to this feature, cannot be null.public int GetFieldType(int ifield)
This is a cover for the FeatureDefn.GetFieldType() method.
ifield
- the field to fetch, from 0 to GetFieldCount()-1.public int GetFieldType(String name)
This is a cover for the FeatureDefn.GetFieldType() method.
name
- the name of the field to fetch.