public class FeatureCollectionTools extends ToolToMakeYourLifeEasier
Modifier and Type | Field and Description |
---|---|
protected FeatureCollection |
fc |
protected java.util.List<Feature> |
featureList |
protected static PersonalLogger |
logger |
Constructor and Description |
---|
FeatureCollectionTools(FeatureCollection fc) |
FeatureCollectionTools(java.util.List<Feature> fcl) |
Modifier and Type | Method and Description |
---|---|
static PirolFeatureCollection |
addAttributesToFeatureCollection(FeatureCollection fc,
AttributeInfo[] attributeInfos) |
static PirolFeatureCollection |
addAttributesToFeatureCollection(FeatureCollection fc,
AttributeInfo[] attributeInfos,
boolean clearOriginalFeatureCollection)
Adds multiple attributes to a FeatureCollection
|
static PirolFeatureCollection |
addAttributesToFeatureCollection(FeatureCollection fc,
java.util.List<AttributeInfo> attributeInfos)
Adds multiple attributes to a FeatureCollection
|
PirolFeatureCollection |
addAttributesToFeatureCollection(java.util.List attributeInfos)
Adds multiple attributes to the FeatureCollection
|
static PirolFeatureCollection |
addAttributeToFeatureCollection(FeatureCollection fc,
AttributeInfo attrInfo) |
static PirolFeatureCollection |
addAttributeToFeatureCollection(FeatureCollection fc,
AttributeInfo attrInfo,
boolean clearOldFeatureCollection) |
static PirolFeatureCollection |
addAttributeToFeatureCollection(FeatureCollection fc,
java.lang.String attr,
AttributeType at,
java.lang.Object defaultVal)
Method to add a new attribute to an existing FeatureCollection.
|
static PirolFeatureCollection |
addAttributeToFeatureCollection(FeatureCollection fc,
java.lang.String attr,
AttributeType at,
java.lang.Object defaultVal,
boolean clearOldFeatureCollection)
Method to add a new attribute to an existing FeatureCollection.
|
PirolFeatureCollection |
addAttributeToFeatureCollection(java.lang.String attr,
AttributeType at,
java.lang.Object defaultVal) |
static PirolFeatureCollection |
applyFormulaToFeatureCollection(FeatureCollection oldFc,
AttributeInfo attrInfo,
FormulaValue formula,
boolean clearOldFeatureCollection)
Method to apply a given formula to the given, new attribute of the given featureCollection
|
protected static boolean |
attributeExistsInSchema(FeatureSchema fs,
java.lang.String attr) |
static PirolFeatureCollection |
cloneFeatureCollection(FeatureCollection fc)
deep copies a the FeatureSchema, the Features and their Geometries
|
static java.util.ArrayList<Feature> |
convertToPointFeature(Feature f,
boolean accountForRings)
Extracts all points from an input feature and returns them as list of point features.
|
static Feature |
copyFeature(Feature feat)
"deep copys" the given Feature
|
static Feature |
copyFeatureAndSetFeatureSchema(Feature feat,
FeatureSchema newFs)
"deep copys" the given Feature and thereby sets the given feature schema.
|
static void |
deleteFeatures(java.util.List<Feature> features,
PlugInContext context)
deletes the given features from the map.
|
static Feature[] |
FeatureCollection2FeatureArray(FeatureCollection fc)
Converts a given FeatureCollection into an array of Feature, that can - by far - be faster iterated.
|
static Feature[] |
FeatureCollection2FeatureArray(java.util.List<Feature> features)
Converts a given list of features into an array of Feature, that can - by far - be faster iterated.
|
static double |
getAritmeticMiddleForAttribute(Feature[] featArray,
int attr) |
static double |
getAritmeticMiddleForAttribute(Feature[] features,
java.lang.String attr) |
static double |
getAritmeticMiddleForAttribute(java.util.List<Feature> features,
int attr) |
static com.vividsolutions.jts.geom.Geometry |
getCenterOfMass(Feature[] features)
Calculates the center of mass for the gives features' geometries.
|
static com.vividsolutions.jts.geom.Envelope |
getEnvelopeForFeatures(Feature[] features)
Creates an envelope object for the features in the given array.
|
Feature |
getFeature(int fid)
gets the Feature with the given FID.
|
static Feature |
getFeatureFromCollection(Feature[] features,
int fid)
Get the feature with the specified ID from the array
|
static Feature |
getFeatureFromCollection(FeatureCollection features,
int fid)
Get the feature with the specified ID from the FeatureCollection
|
static Feature |
getFeatureFromCollection(java.util.List<Feature> features,
int fid)
Get the feature with the specified ID from the List
|
static java.lang.Object[] |
getMeanOrModeForAttributes(Feature[] features,
java.lang.String[] attrs)
Method to calculate means (or modes) for the attributes given.
|
static double[] |
getMinMaxAttributeValue(Feature[] featArray,
FeatureSchema fs,
java.lang.String attr) |
static double[] |
getMinMaxAttributeValue(FeatureCollection features,
java.lang.String attr) |
static java.lang.Object |
getModusForAttribute(Feature[] features,
int attr) |
static java.lang.Object |
getModusForAttribute(Feature[] features,
java.lang.String attr) |
static double |
getNumericalAttributeValue(Feature f,
java.lang.String attributeName)
gets the value of an attribute; it checks if the attribute is of double or int type, otherwise NaN is returned.
|
static int |
getNumOfDifferentAttributeValues(Feature[] features,
int attr) |
static int |
getNumOfDifferentAttributeValues(Feature[] features,
java.lang.String attr) |
static java.util.Set<java.lang.Object> |
getSetOfDifferentAttributeValues(Feature[] features,
int attr) |
static java.util.Set |
getSetOfDifferentAttributeValues(Feature[] features,
java.lang.String attr) |
static double |
getSumAttributeValue(Feature[] featArray,
FeatureSchema fs,
java.lang.String attr) |
static java.lang.String |
getUniqueAttributeName(FeatureCollection fc,
java.lang.String attr) |
java.lang.String |
getUniqueAttributeName(java.lang.String attr) |
static java.util.HashMap<java.lang.Object,java.lang.Integer>[] |
getValueAppearancesCount(Feature[] features,
int[] attrs)
Counts the number of appearances of each value of the given attributes within the given features.
|
static boolean |
isAttributeTypeNumeric(AttributeType at) |
static java.lang.Object |
resizeArray(java.lang.Object oldArray,
int newSize)
Reallocates an array with a new size, and copies the contents
of the old array to the new array.
|
static java.util.ArrayList<Feature> |
sortFeatureListByAttributeBeginWithSmallest(java.util.List<Feature> features,
java.lang.String attributeNameForSorting)
Sorts a list of features according to the values of a attribute.
|
static java.lang.Object[] |
sortFeaturesIntoListsByAttributeValue(FeatureCollection features,
java.lang.String idAttribute)
Sorts features according to unique attribute values into different lists (on list for each unique attribute).
|
protected FeatureCollection fc
protected java.util.List<Feature> featureList
protected static PersonalLogger logger
public FeatureCollectionTools(FeatureCollection fc)
public FeatureCollectionTools(java.util.List<Feature> fcl)
public Feature getFeature(int fid)
fid
- FID to look forpublic static Feature getFeatureFromCollection(java.util.List<Feature> features, int fid)
features
- array with Feature objectsfid
- the feature ID we are looking forpublic static Feature getFeatureFromCollection(Feature[] features, int fid)
features
- array with Feature objectsfid
- the feature ID we are looking forpublic static final PirolFeatureCollection cloneFeatureCollection(FeatureCollection fc)
fc
- the FeatureCollection to copypublic static Feature getFeatureFromCollection(FeatureCollection features, int fid)
features
- array with Feature objectsfid
- the feature ID we are looking forpublic static double getAritmeticMiddleForAttribute(Feature[] features, java.lang.String attr)
features
- list of features to calculate the mean forattr
- name of attribute to calculate the mean forpublic static java.lang.Object[] getMeanOrModeForAttributes(Feature[] features, java.lang.String[] attrs)
features
- list of features to calculate mean/modes forattrs
- array of attribute names to calculate mean/modes forpublic static com.vividsolutions.jts.geom.Envelope getEnvelopeForFeatures(Feature[] features)
features
- array of Feature object to create an envelope forpublic static double getAritmeticMiddleForAttribute(java.util.List<Feature> features, int attr)
features
- list of features to calculate the mean forattr
- index of attribute to calculate the mean forpublic static double getAritmeticMiddleForAttribute(Feature[] featArray, int attr)
featArray
- array of features to calculate the mean forattr
- index of attribute to calculate the mean forpublic static com.vividsolutions.jts.geom.Geometry getCenterOfMass(Feature[] features)
features
- the featurespublic static java.util.Set getSetOfDifferentAttributeValues(Feature[] features, java.lang.String attr)
features
- list of featuresattr
- name of attributepublic static java.util.Set<java.lang.Object> getSetOfDifferentAttributeValues(Feature[] features, int attr)
features
- list of featuresattr
- index of attributepublic static int getNumOfDifferentAttributeValues(Feature[] features, java.lang.String attr)
features
- list of featuresattr
- name of attributepublic static int getNumOfDifferentAttributeValues(Feature[] features, int attr)
features
- list of featuresattr
- index of attributepublic static java.lang.Object getModusForAttribute(Feature[] features, java.lang.String attr)
features
- list of features to calculate the mode forattr
- name of attribute to calculate the mode forpublic static final java.util.HashMap<java.lang.Object,java.lang.Integer>[] getValueAppearancesCount(Feature[] features, int[] attrs)
features
- array of Features to count value appearances forattrs
- array of attribute indices of attributes to count value appearances forpublic static java.lang.Object getModusForAttribute(Feature[] features, int attr)
features
- list of features to calculate the mode forattr
- index of attribute to calculate the mode forpublic static void deleteFeatures(java.util.List<Feature> features, PlugInContext context)
features
- features to be deletedcontext
- curr. PlugIn contextpublic static Feature copyFeature(Feature feat)
feat
- the feature to be copiedpublic static Feature copyFeatureAndSetFeatureSchema(Feature feat, FeatureSchema newFs)
feat
- the feature to be copiednewFs
- the new feature schemapublic java.lang.String getUniqueAttributeName(java.lang.String attr)
public static java.lang.String getUniqueAttributeName(FeatureCollection fc, java.lang.String attr)
protected static boolean attributeExistsInSchema(FeatureSchema fs, java.lang.String attr)
public PirolFeatureCollection addAttributeToFeatureCollection(java.lang.String attr, AttributeType at, java.lang.Object defaultVal)
public static boolean isAttributeTypeNumeric(AttributeType at)
public static PirolFeatureCollection applyFormulaToFeatureCollection(FeatureCollection oldFc, AttributeInfo attrInfo, FormulaValue formula, boolean clearOldFeatureCollection)
oldFc
- old FeatureCollection that will be replaced by the new oneattrInfo
- information for the new attributeformula
- the parsed formulapublic static PirolFeatureCollection addAttributeToFeatureCollection(FeatureCollection fc, AttributeInfo attrInfo)
public static PirolFeatureCollection addAttributeToFeatureCollection(FeatureCollection fc, AttributeInfo attrInfo, boolean clearOldFeatureCollection)
public static PirolFeatureCollection addAttributeToFeatureCollection(FeatureCollection fc, java.lang.String attr, AttributeType at, java.lang.Object defaultVal, boolean clearOldFeatureCollection)
fc
- the old feature collectionattr
- name of the new attributeat
- type of the new attributedefaultVal
- the initial value for the attribute, since we do not want NULL values in the attribute tableclearOldFeatureCollection
- if true the old feature collection will be erased to save RAMpublic static PirolFeatureCollection addAttributeToFeatureCollection(FeatureCollection fc, java.lang.String attr, AttributeType at, java.lang.Object defaultVal)
fc
- the old feature collectionattr
- name of the new attributeat
- type of the new attributedefaultVal
- the initial value for the attribute, since we do not want NULL values in the attribute tablepublic PirolFeatureCollection addAttributesToFeatureCollection(java.util.List attributeInfos)
attributeInfos
- list containing the attributes (as AttributeInfo objects) to be addedAttributeInfo
public static PirolFeatureCollection addAttributesToFeatureCollection(FeatureCollection fc, java.util.List<AttributeInfo> attributeInfos)
fc
- the source feature collectionattributeInfos
- list containing the attributes (as AttributeInfo objects) to be addedAttributeInfo
public static PirolFeatureCollection addAttributesToFeatureCollection(FeatureCollection fc, AttributeInfo[] attributeInfos)
public static PirolFeatureCollection addAttributesToFeatureCollection(FeatureCollection fc, AttributeInfo[] attributeInfos, boolean clearOriginalFeatureCollection)
fc
- the source feature collectionattributeInfos
- array containing the attributes to be addedclearOriginalFeatureCollection
- set true, if you want to save RAM by
clearing the original FeatureCollection, false if you still want to use it.public static java.lang.Object resizeArray(java.lang.Object oldArray, int newSize)
oldArray
- the old array, to be reallocated.newSize
- the new array size.public static double[] getMinMaxAttributeValue(Feature[] featArray, FeatureSchema fs, java.lang.String attr)
public static double getSumAttributeValue(Feature[] featArray, FeatureSchema fs, java.lang.String attr)
public static double[] getMinMaxAttributeValue(FeatureCollection features, java.lang.String attr)
public static Feature[] FeatureCollection2FeatureArray(FeatureCollection fc)
fc
- the feature Collectionpublic static Feature[] FeatureCollection2FeatureArray(java.util.List<Feature> features)
features
- list of featurespublic static java.util.ArrayList<Feature> convertToPointFeature(Feature f, boolean accountForRings)
f
- accountForRings
- doesn't add a point for the last coordinate if the geometry is a ring (i.e. first point equals last point)public static java.lang.Object[] sortFeaturesIntoListsByAttributeValue(FeatureCollection features, java.lang.String idAttribute)
features
- idAttribute
- (must be Double or Integer)public static double getNumericalAttributeValue(Feature f, java.lang.String attributeName)
f
- attributeName
- public static java.util.ArrayList<Feature> sortFeatureListByAttributeBeginWithSmallest(java.util.List<Feature> features, java.lang.String attributeNameForSorting)
features
- attributeNameForSorting
- attribute needs to be either Integer or Double