Class AbstractDataStoreWriter

java.lang.Object
nz.org.riskscape.engine.output.RiskscapeWriter
nz.org.riskscape.engine.output.AbstractDataStoreWriter
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
ShapefileWriter

public abstract class AbstractDataStoreWriter extends nz.org.riskscape.engine.output.RiskscapeWriter implements Closeable

Writes typed riskscape Values out to a new file.

Due to restrictions in the shapefile format and geotools' own hacks to work with them, the ShapefileWriter writes out the geometry to the the_geom magic feature attribute. If geometry also appears in the value, the writer either ignores it (if it was also passed as the special geometry parameter) or writes it out as text in WKT

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected AxisSwapper
    some formats require mandate x-y ordering, regardless of what the prj says - this is here to apply that.
    static final String
    The name of the geometry output in the written feature - by convention with shapefiles this must be the_geom
     
    protected boolean
     
    protected int
    SRID to write geometries as.
    static final String
    When writing out a SimpleType value, the feature's only attribute is named this
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractDataStoreWriter(File outfile, nz.org.riskscape.engine.SRIDSet sridSet, org.geotools.api.data.DataStore dataStore)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    protected org.geotools.api.feature.simple.SimpleFeatureType
    featureTypeFromMappings(org.geotools.feature.simple.SimpleFeatureTypeBuilder builder)
     
    protected int
    Sub classes should override and return a positive value to force attribute names to be truncated if they exceed the max length.
    nz.org.riskscape.engine.types.Struct
    The Type we are writing out to file.
     
    protected Class<?>
    mapJavaType(Class<?> toMap)
     
    protected Object
    mapValueIfNecessary(Object value, nz.org.riskscape.engine.types.Type type)
    Allows implementations to perform any value mapping should this be required.
    protected org.geotools.api.referencing.crs.CoordinateReferenceSystem
    outputCrs(@NonNull org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)
    Get a crs that will be "correct" for the produced file.
    protected void
    setAttr(org.geotools.api.feature.simple.SimpleFeature toWrite, String key, Object value, nz.org.riskscape.engine.types.Type type)
     
    protected void
    setupCrsAndGeoType(nz.org.riskscape.engine.Tuple value)
     
    void
    write(nz.org.riskscape.engine.Tuple value)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • VALUE_ATTRIBUTE

      public static final String VALUE_ATTRIBUTE

      When writing out a SimpleType value, the feature's only attribute is named this

      See Also:
    • GEOMETRY_ATTRIBUTE

      public static final String GEOMETRY_ATTRIBUTE

      The name of the geometry output in the written feature - by convention with shapefiles this must be the_geom

      See Also:
    • mappings

      protected List<StructFlattener.StructMapping> mappings
    • setup

      protected boolean setup
    • targetSrid

      protected int targetSrid

      SRID to write geometries as.

    • axisSwapper

      protected AxisSwapper axisSwapper

      some formats require mandate x-y ordering, regardless of what the prj says - this is here to apply that. Implementations should set the axisSwapper if required by overriding the outputCrs method

  • Constructor Details

    • AbstractDataStoreWriter

      public AbstractDataStoreWriter(File outfile, nz.org.riskscape.engine.SRIDSet sridSet, org.geotools.api.data.DataStore dataStore) throws IOException
      Throws:
      IOException
  • Method Details

    • outputCrs

      protected org.geotools.api.referencing.crs.CoordinateReferenceSystem outputCrs(@NonNull @NonNull org.geotools.api.referencing.crs.CoordinateReferenceSystem crs)

      Get a crs that will be "correct" for the produced file. This is to allow implementions to modify output where this may be expected by other software. Such as EPSG:4326 in shapefiles other software ignores axis defintion in projection file and instead uses Long/Lat.

      Implementations that override this method should set the targetSrid to match the returned CRS.

      Parameters:
      crs -
      Returns:
      crs correct crs for the produced file
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • write

      public void write(nz.org.riskscape.engine.Tuple value) throws WriteException
      Specified by:
      write in class nz.org.riskscape.engine.output.RiskscapeWriter
      Throws:
      WriteException
    • setupCrsAndGeoType

      protected void setupCrsAndGeoType(nz.org.riskscape.engine.Tuple value) throws IOException
      Throws:
      IOException
    • getAttrNameMaxLength

      protected int getAttrNameMaxLength()

      Sub classes should override and return a positive value to force attribute names to be truncated if they exceed the max length.

      Returns:
      desired max length of attribute names
    • setAttr

      protected void setAttr(org.geotools.api.feature.simple.SimpleFeature toWrite, String key, Object value, nz.org.riskscape.engine.types.Type type)
    • mapValueIfNecessary

      protected Object mapValueIfNecessary(Object value, nz.org.riskscape.engine.types.Type type)

      Allows implementations to perform any value mapping should this be required.

      Parameters:
      value - to map
      type - Riskscape type that values is
      Returns:
      value, or a mapped version of value.
    • featureTypeFromMappings

      protected org.geotools.api.feature.simple.SimpleFeatureType featureTypeFromMappings(org.geotools.feature.simple.SimpleFeatureTypeBuilder builder)
    • mapJavaType

      protected Class<?> mapJavaType(Class<?> toMap)
    • getRiskscapeType

      public nz.org.riskscape.engine.types.Struct getRiskscapeType()

      The Type we are writing out to file. All calls to write(Tuple) must match this type.

    • getStoredAt

      public URI getStoredAt()
      Specified by:
      getStoredAt in class nz.org.riskscape.engine.output.RiskscapeWriter