Class VectorLayer

java.lang.Object
com.eco.bio7.gdal.VectorLayer
All Implemented Interfaces:
AutoCloseable

public final class VectorLayer extends Object implements AutoCloseable
A vector layer of a dataset (OGRLayer): its fields, features, extent and coordinate system; filters (attributes, extent); new fields and features (a layer of a dataset created or opened for writing). The result of SQL (GdalDataset.executeSql(String)) must be closed.
  • Method Details

    • close

      public void close()
      Releases the result of SQL (nothing to do for the other layers: they belong to their dataset).
      Specified by:
      close in interface AutoCloseable
    • setAttributeFilter

      public void setAttributeFilter(String where)
      Only the features of an attribute filter (an SQL WHERE clause, e.g. "area > 1000 AND type = 'forest'"); null: all. Some drivers (e.g., GeoPackage) check the filter only when the features are read (an invalid filter: no features).
    • setSpatialFilter

      public void setSpatialFilter(double minX, double minY, double maxX, double maxY)
      Only the features which intersect the rectangle (in the coordinates of the layer).
    • clearSpatialFilter

      public void clearSpatialFilter()
      All features again (no spatial filter).
    • createField

      public void createField(String name, FieldType type)
      A new attribute field (before the features are added).
    • addFeature

      public long addFeature(Map<String,?> attributes, String wkt)
      Adds a feature: the attributes by field name (numbers, strings, booleans or null; unknown names are an error), the geometry as WKT (in the coordinates of the layer; null: without geometry).
      Returns:
      the id of the new feature
    • sync

      public void sync()
      Writes the changes to the file.
    • fieldIndex

      public int fieldIndex(String name)
      The index of a field (-1 if it doesn't exist).
    • name

      public String name()
    • featureCount

      public long featureCount()
      The number of features (counted if the format doesn't know it).
    • fieldNames

      public List<String> fieldNames()
      The names of the attribute fields.
    • geometryType

      public int geometryType()
      The type of the geometries (OGRwkbGeometryType: 1 point, 2 line string, 3 polygon, 4-6 multi..., 0 unknown).
    • spatialReference

      public SpatialReference spatialReference()
      The coordinate system (null if unknown). Close it after use.
    • extent

      public double[] extent()
      The extent {minX, minY, maxX, maxY} (null if unknown).
    • features

      public List<Feature> features()
      All features (for large layers see forEach(Consumer)).
    • forEach

      public void forEach(Consumer<Feature> action)
      Reads the features one after the other (from the start of the layer).
    • toString

      public String toString()
      Overrides:
      toString in class Object