Class FeatureUtilities
- java.lang.Object
-
- org.hortonmachine.gears.utils.features.FeatureUtilities
-
public class FeatureUtilities extends Object
-
-
Constructor Summary
Constructors Constructor Description FeatureUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleavg(List<org.opengis.feature.simple.SimpleFeature> features, String field)Calculate the avg of a value in a list ofSimpleFeatures.static booleancollectionToShapeFile(String shapeFilePath, org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.geotools.data.simple.SimpleFeatureCollection fet)The easy way to create a shapefile from attributes and geometriesstatic org.geotools.data.simple.SimpleFeatureCollectioncreateFeatureCollection(org.opengis.feature.simple.SimpleFeature... features)Create a featurecollection from a vector of featuresstatic org.geotools.data.shapefile.ShapefileDataStorecreateShapeFileDatastore(String name, String fieldsSpec, org.opengis.referencing.crs.CoordinateReferenceSystem crs)static org.geotools.data.simple.SimpleFeatureCollectioncsvFileToFeatureCollection(File csvFile, org.opengis.referencing.crs.CoordinateReferenceSystem crs, LinkedHashMap<String,Integer> fieldsAndTypesIndex, String separator, IHMProgressMonitor pm)Convert a csv file to a FeatureCollection.static Collection<org.locationtech.jts.geom.Polygon>doVectorize(org.geotools.coverage.grid.GridCoverage2D src, Map<String,Object> args)Helper function to run the Vectorize operation with given parameters and retrieve the vectors.static org.locationtech.jts.geom.PolygonenvelopeToPolygon(org.geotools.geometry.Envelope2D envelope)Create aPolygonfrom anEnvelope.static org.locationtech.jts.geom.PolygonenvelopeToPolygon(org.locationtech.jts.geom.Envelope envelope)Create aPolygonfrom anEnvelope.static LinkedHashMap<String,String>feature2AlphanumericToHashmap(org.opengis.feature.simple.SimpleFeature feature)static QueryResultfeatureCollection2QueryResult(org.geotools.data.simple.SimpleFeatureCollection featureCollection)Utility to convert a featurecollection to a queryresult format.static String[]featureCollectionFieldNames(org.geotools.data.simple.SimpleFeatureCollection feature)static org.geotools.data.simple.SimpleFeatureCollectionfeatureCollectionFromGeometry(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Geometry... geometries)Make aSimpleFeatureCollectionfrom a set ofGeometry.static List<org.geotools.data.simple.SimpleFeatureCollection>featureCollectionsFromGeometry(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Geometry... geometries)Make a set ofSimpleFeatureCollectionfrom a set ofGeometry, based on the geometry type.static List<org.locationtech.jts.geom.Geometry>featureCollectionToGeometriesList(org.geotools.data.simple.SimpleFeatureCollection collection, boolean doSubGeoms, String userDataField)Extracts features from aFeatureCollectioninto anArrayListof its geometries.static List<org.opengis.feature.simple.SimpleFeature>featureCollectionToList(org.geotools.data.simple.SimpleFeatureCollection collection)Extracts features from aFeatureCollectioninto anArrayList.static List<FeatureMate>featureCollectionToMatesList(org.geotools.data.simple.SimpleFeatureCollection collection)static org.locationtech.jts.index.strtree.STRtreefeatureCollectionToSTRtree(org.geotools.data.simple.SimpleFeatureCollection collection)Extracts features from aFeatureCollectioninto anSTRtree.static StringfindAttributeName(org.opengis.feature.simple.SimpleFeatureType featureType, String field)Find the name of an attribute, case insensitive.static ObjectgetAttributeCaseChecked(org.opengis.feature.simple.SimpleFeature feature, String field)Getter for attributes of a feature.static longgetFeatureId(org.opengis.feature.simple.SimpleFeature feature)Extract the numeric feature id from a feature.static double[][]histogram(List<org.opengis.feature.simple.SimpleFeature> features, String field, int bins)Calculate the histogram of a list ofSimpleFeatures.static org.locationtech.jts.geom.CoordinateListorderLineGeometries(List<org.locationtech.jts.geom.Geometry> geometryList, double thresHold)Order the geometries of a list to be all directed in the same directionstatic org.opengis.feature.simple.SimpleFeaturetoDummyFeature(org.locationtech.jts.geom.Geometry geom, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
-
-
-
Method Detail
-
orderLineGeometries
public static org.locationtech.jts.geom.CoordinateList orderLineGeometries(List<org.locationtech.jts.geom.Geometry> geometryList, double thresHold)
Order the geometries of a list to be all directed in the same direction- Parameters:
geometryList- the list of geometries to be orderedthresHold- a scalar value that defines the max distance between two points to be the same- Returns:
- a list of ordered coordinates
-
createFeatureCollection
public static org.geotools.data.simple.SimpleFeatureCollection createFeatureCollection(org.opengis.feature.simple.SimpleFeature... features)
Create a featurecollection from a vector of features- Parameters:
features- - the vectore of features- Returns:
- the created featurecollection
-
csvFileToFeatureCollection
public static org.geotools.data.simple.SimpleFeatureCollection csvFileToFeatureCollection(File csvFile, org.opengis.referencing.crs.CoordinateReferenceSystem crs, LinkedHashMap<String,Integer> fieldsAndTypesIndex, String separator, IHMProgressMonitor pm) throws Exception
Convert a csv file to a FeatureCollection. This for now supports only point geometries.
For different crs it also performs coor transformation.NOTE: this doesn't support date attributes
-
collectionToShapeFile
public static boolean collectionToShapeFile(String shapeFilePath, org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.geotools.data.simple.SimpleFeatureCollection fet) throws IOException
The easy way to create a shapefile from attributes and geometries
NOTE: this doesn't support date attributes
- Parameters:
shapeFilePath- the shapefile namecrs- the destination crsfet- the featurecollection- Throws:
IOException
-
createShapeFileDatastore
public static org.geotools.data.shapefile.ShapefileDataStore createShapeFileDatastore(String name, String fieldsSpec, org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws Exception
- Parameters:
name- the shapefile namefieldsSpec- to create other fields you can use a string like :
"geom:MultiLineString,FieldName:java.lang.Integer"
field name can not be over 10 characters use a ',' between each field
field types can be : java.lang.Integer, java.lang.Long, // java.lang.Double, java.lang.String or java.util.Date- Returns:
- Throws:
Exception
-
featureCollectionToList
public static List<org.opengis.feature.simple.SimpleFeature> featureCollectionToList(org.geotools.data.simple.SimpleFeatureCollection collection)
Extracts features from aFeatureCollectioninto anArrayList.- Parameters:
collection- the feature collection.- Returns:
- the list with the features or an empty list if no features present.
-
featureCollectionToSTRtree
public static org.locationtech.jts.index.strtree.STRtree featureCollectionToSTRtree(org.geotools.data.simple.SimpleFeatureCollection collection)
Extracts features from aFeatureCollectioninto anSTRtree.- Parameters:
collection- the feature collection.- Returns:
- the tree containing the features.
-
featureCollectionToMatesList
public static List<FeatureMate> featureCollectionToMatesList(org.geotools.data.simple.SimpleFeatureCollection collection)
- Parameters:
collection- the feature collection.- Returns:
- the list with the features or an empty list if no features present.
-
featureCollectionToGeometriesList
public static List<org.locationtech.jts.geom.Geometry> featureCollectionToGeometriesList(org.geotools.data.simple.SimpleFeatureCollection collection, boolean doSubGeoms, String userDataField)
Extracts features from aFeatureCollectioninto anArrayListof its geometries.- Parameters:
collection- the feature collection.doSubGeoms- split the geometries in single geometries (ex. MultiLines in Lines).userDataField- if notnull, the data in the field are put in the userData field of the geometry.- Returns:
- the list with the geometries or an empty list if no features present.
-
featureCollectionFromGeometry
public static org.geotools.data.simple.SimpleFeatureCollection featureCollectionFromGeometry(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Geometry... geometries)Make aSimpleFeatureCollectionfrom a set ofGeometry.This is a fast utility and adds no attributes.
- Parameters:
crs- TheCoordinateReferenceSystem.geometries- the set ofGeometryto add.- Returns:
- the features wrapping the geoms.
-
featureCollectionsFromGeometry
public static List<org.geotools.data.simple.SimpleFeatureCollection> featureCollectionsFromGeometry(org.opengis.referencing.crs.CoordinateReferenceSystem crs, org.locationtech.jts.geom.Geometry... geometries)
Make a set ofSimpleFeatureCollectionfrom a set ofGeometry, based on the geometry type.This is a fast utility and adds no attributes.
- Parameters:
crs- TheCoordinateReferenceSystem.geometries- the set ofGeometryto add.- Returns:
- the features wrapping the geoms.
-
getAttributeCaseChecked
public static Object getAttributeCaseChecked(org.opengis.feature.simple.SimpleFeature feature, String field)
Getter for attributes of a feature.If the attribute is not found, checks are done in non case sensitive mode.
- Parameters:
feature- the feature from which to get the attribute.field- the name of the field.- Returns:
- the attribute or null if none found.
-
findAttributeName
public static String findAttributeName(org.opengis.feature.simple.SimpleFeatureType featureType, String field)
Find the name of an attribute, case insensitive.- Parameters:
featureType- the feature type to check.field- the case insensitive field name.- Returns:
- the real name of the field, or
null, if none found.
-
envelopeToPolygon
public static org.locationtech.jts.geom.Polygon envelopeToPolygon(org.geotools.geometry.Envelope2D envelope)
Create aPolygonfrom anEnvelope.- Parameters:
envelope- the envelope to convert.- Returns:
- the created polygon.
-
envelopeToPolygon
public static org.locationtech.jts.geom.Polygon envelopeToPolygon(org.locationtech.jts.geom.Envelope envelope)
Create aPolygonfrom anEnvelope.- Parameters:
envelope- the envelope to convert.- Returns:
- the created polygon.
-
doVectorize
public static Collection<org.locationtech.jts.geom.Polygon> doVectorize(org.geotools.coverage.grid.GridCoverage2D src, Map<String,Object> args)
Helper function to run the Vectorize operation with given parameters and retrieve the vectors.- Parameters:
src- the sourceGridCoverage2D.args- aMapof parameter names and values ornull.- Returns:
- the generated vectors as JTS Polygons
-
toDummyFeature
public static org.opengis.feature.simple.SimpleFeature toDummyFeature(org.locationtech.jts.geom.Geometry geom, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
-
avg
public static double avg(List<org.opengis.feature.simple.SimpleFeature> features, String field)
Calculate the avg of a value in a list ofSimpleFeatures.Empty records are ignored.
- Parameters:
features- the features.field- the field to consider.- Returns:
- the avg.
-
histogram
public static double[][] histogram(List<org.opengis.feature.simple.SimpleFeature> features, String field, int bins)
Calculate the histogram of a list ofSimpleFeatures.- Parameters:
features- the list of features.field- the field to consider.bins- the number of bins.- Returns:
- the histogram as matrix of rows num like bins and 3 columns for [binCenter, count, cumulated-normalize-count].
-
feature2AlphanumericToHashmap
public static LinkedHashMap<String,String> feature2AlphanumericToHashmap(org.opengis.feature.simple.SimpleFeature feature)
-
featureCollectionFieldNames
public static String[] featureCollectionFieldNames(org.geotools.data.simple.SimpleFeatureCollection feature)
-
getFeatureId
public static long getFeatureId(org.opengis.feature.simple.SimpleFeature feature)
Extract the numeric feature id from a feature.- Parameters:
feature- the feature to check.- Returns:
- the id as long.
-
featureCollection2QueryResult
public static QueryResult featureCollection2QueryResult(org.geotools.data.simple.SimpleFeatureCollection featureCollection)
Utility to convert a featurecollection to a queryresult format.- Parameters:
featureCollection- the collection to convert.- Returns:
- the queryresult object.
-
-