Class GeoPackageOutputStore
- All Implemented Interfaces:
AutoCloseable
For writing to GeoPackage files.
Note that writing to GeoPackage files uses a shared connection. It is important that
is called to close this shared connection.</p>
-
Nested Class Summary
Nested classes/interfaces inherited from class nz.org.riskscape.engine.defaults.data.jdbc.BaseJdbcOutputStore
BaseJdbcOutputStore.JdbcRiskscapeWriter, BaseJdbcOutputStore.LocalProblems, BaseJdbcOutputStore.StructMappingToColumnMapping -
Field Summary
Fields inherited from class nz.org.riskscape.engine.defaults.data.jdbc.BaseJdbcOutputStore
DEFAULT_BATCH_INSERT_SIZE, ds, PROBLEMS, replaceExistingTables -
Constructor Summary
ConstructorsConstructorDescriptionGeoPackageOutputStore(File geoPackageFile, nz.org.riskscape.engine.pipeline.ExecutionContext context, boolean replaceExistingTables) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected BaseJdbcOutputStore.JdbcRiskscapeWritercreateJdbcWriter(String tableName, List<BaseJdbcOutputStore.StructMappingToColumnMapping> mappings, Connection conn, URI storedAt) protected voiddeleteTable(String tableName, Connection conn) protected ConnectionGet aConnectionthat will be used to both create and then populate the table.getTableURI(String tableName) Get a URI that represents the given table at the JDBC data source.protected voidinitDbIfNecessary(Connection conn) Initializes the GeoPackage with required tables should they not exist alreadyprotected nz.org.riskscape.problem.ResultOrProblems<BaseJdbcOutputStore.StructMappingToColumnMapping>toColumnMapping(nz.org.riskscape.engine.output.StructFlattener.StructMapping structMapping, nz.org.riskscape.engine.output.StructFlattener.StructMapping firstGeomMapping, Connection conn) Provide aBaseJdbcOutputStore.StructMappingToColumnMappingfor the given structMapping.static nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.engine.output.RiskscapeWriter>writerFor(File geoPackageFile, nz.org.riskscape.engine.pipeline.ExecutionContext context, nz.org.riskscape.engine.types.Struct type, String name, boolean replaceExistingTables) Get aRiskscapeWriterthat can write the given type/name to geoPackageFile.Methods inherited from class nz.org.riskscape.engine.defaults.data.jdbc.BaseJdbcOutputStore
appendingWriterFor, doWriterFor, getExistingTableNames, normalizeSridAndAxisOrder, quoteIdentifier, runScript, urlEncode, writerFor
-
Constructor Details
-
GeoPackageOutputStore
public GeoPackageOutputStore(File geoPackageFile, nz.org.riskscape.engine.pipeline.ExecutionContext context, boolean replaceExistingTables)
-
-
Method Details
-
writerFor
public static nz.org.riskscape.problem.ResultOrProblems<nz.org.riskscape.engine.output.RiskscapeWriter> writerFor(File geoPackageFile, nz.org.riskscape.engine.pipeline.ExecutionContext context, nz.org.riskscape.engine.types.Struct type, String name, boolean replaceExistingTables) Get a
RiskscapeWriterthat can write the given type/name to geoPackageFile.Note that the GeoPackageOutputStore will be closed when the returned RiskscapeWriter is closed.
This method is only appropriate when a single layer is to be written to the GeoPackage. If multiple layers are to be written then
BaseJdbcOutputStore.writerFor(Struct, String)should be used.- Parameters:
geoPackageFile- the GeoPackage file to be written tocontext- the execution context that will be using the writertype- the type to writename- the desired name to write toreplaceExistingTables- true if existing tables should be replaced- Returns:
- riskscape writer or problems preventing one from being created
-
getConnection
Description copied from class:BaseJdbcOutputStoreGet a
Connectionthat will be used to both create and then populate the table.Note that if this method is overridden to return a shared connection then
BaseJdbcOutputStore.createJdbcWriter(java.lang.String, java.util.List, java.sql.Connection, java.net.URI)should also be overridden to return aBaseJdbcOutputStore.JdbcRiskscapeWriterthat will not close the shared connection. In this case the implementation will need to take other steps to ensure that the connection is closed.- Overrides:
getConnectionin classBaseJdbcOutputStore- Throws:
SQLException
-
createJdbcWriter
protected BaseJdbcOutputStore.JdbcRiskscapeWriter createJdbcWriter(String tableName, List<BaseJdbcOutputStore.StructMappingToColumnMapping> mappings, Connection conn, URI storedAt) throws SQLException - Overrides:
createJdbcWriterin classBaseJdbcOutputStore- Throws:
SQLException
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
toColumnMapping
protected nz.org.riskscape.problem.ResultOrProblems<BaseJdbcOutputStore.StructMappingToColumnMapping> toColumnMapping(nz.org.riskscape.engine.output.StructFlattener.StructMapping structMapping, nz.org.riskscape.engine.output.StructFlattener.StructMapping firstGeomMapping, Connection conn) throws nz.org.riskscape.problem.ProblemException Description copied from class:BaseJdbcOutputStoreProvide a
BaseJdbcOutputStore.StructMappingToColumnMappingfor the given structMapping.firstGeomMapping is also provided to allow implementations that only allow one spatial entry to map subsequent geometries, maybe to text WKT.
- Specified by:
toColumnMappingin classBaseJdbcOutputStore- Parameters:
structMapping- the struct mapping to mapfirstGeomMapping- the first geometry mapping, if one exists- Returns:
- a mapper
- Throws:
nz.org.riskscape.problem.ProblemException
-
getTableURI
Description copied from class:BaseJdbcOutputStoreGet a URI that represents the given table at the JDBC data source. Will be returned from
RiskscapeWriter.getStoredAt()when writing is complete.- Specified by:
getTableURIin classBaseJdbcOutputStore- Parameters:
tableName- the table that is being written with URL encoding- Returns:
- URI representing the table
-
initDbIfNecessary
Initializes the GeoPackage with required tables should they not exist already
- Overrides:
initDbIfNecessaryin classBaseJdbcOutputStore- Parameters:
conn-
-
deleteTable
- Overrides:
deleteTablein classBaseJdbcOutputStore- Throws:
SQLException
-
getGeoPackageFile
-