Class TLcdDB2SpatialModelEncoder
- All Implemented Interfaces:
ILcdModelEncoder,Serializable
ILcdModelEncoder encodes models into DB2 Spatial
databases.
A spatial database is accessed based on a set of properties. The properties
can be passed in a Properties object, or using a properties file
with extension "db2".
The common properties needed to establish a connection and to specify tables,
columns, rows, etc. are the same as those for the
TLcdDB2SpatialModelDecoder. In addition, the following property is
required:
featureDataTypes.0, ...: the SQL data types of the feature columns. EachfeatureNames.imust have a correspondingfeatureDataTypes.i.
SRID: the database system reference identifier corresponding to the model reference. If not specified, the encoder will attempt to find a suitable the SRID by itself. If this fails, the model is encoded with the SRID=0 ("unspecified") and a warning is issued to the log.EPSG: the EPSG code corresponding to the model reference. If this property is present, the encoder will try to find and use the associated SRID from the database. If the SRID cannot be found, the model is encoded with the SRID=0 ("unspecified") and a warning is issued to the log. When both the SRID and the EPSG properties are specified by the user the SRID takes precendence.useSHP(default=false): the elements will be stored in the database in the ESRI Shapefile format. This allows specifying 3D coordinates and/or measurement values (seeILcdSHPMeasureandILcdSHPMeasureList).dropBeforeCreatingTable(optional, default=false): if set totrue, the encoder will attempt to drop the spatial table before re-creating it.voronoiIndex(optional, default=1): when the encoded spatial table contains geodetic data, this property specifies the cell structure ID of the geodetic Voronoi index (see the IBM DB2 User Guide).spatialIndex(optional, default=1.0, 5.0, 50.0): when the encoded spatial table contains spatial data, this property specifies the spatial grid index (see the IBM DB2 User Guide).
Example properties file:
# The basic database connection properties. driver = com.ibm.db2.jcc.DB2Driver url = jdbc:db2://host_name:50002/db_name user = db2inst1 password = db2inst1 # The data of interest. table = STATES spatialColumn = GEOM # The feature columns to be decoded. featureNames.0 = ID featureNames.1 = STATE # The index of the feature that can be used as primary key. primaryFeatureIndex = 0 # Optional additional constraints to retrieve a subset of the table. #selectionTables = #selectionFilter = STATE = 'New York' # Optional maximum cache size (expressed as number of objects, default is 100). maxCacheSize = 60 # Optionally close the database connection after each query. # Only advisable when using a connection pooling database driver. #alwaysCloseConnection = false # Additional properties required for creating a new DB2 Spatial table. # SRID = 1003 # Alternatively, an EPSG code can be specified (SRID takes precedence) # EPSG = 4326 # The regular SQL data types of the feature columns. featureDataTypes.0 = NUMERIC(11,3) featureDataTypes.1 = CHAR(20)
The encoder supports ILcdShape objects. They are converted
to DB2 Spatial objects as follows:
FROMILcdShape | TOESRI SHAPE Geometry |
|---|---|
ILcdPoint | POINT |
ILcdPolyline | LINE_STRING |
ILcdPolygon | POLYGON |
ILcdComplexPolygon | POLYGON or MULTI_POLYGON |
ILcdPolypoint | MULTI_POINT |
ILcdShapeList containing one ILcdPoint element | POINT |
ILcdShapeList containing one ILcdPolyline element | LINE_STRING |
ILcdShapeList containing one ILcdPolygon element | POLYGON |
ILcdShapeList containing one ILcdComplexPolygon element | POLYGON or MULTI_POLYGON |
ILcdShapeList containing one ILcdPolypoint element | MULTI_POINT |
ILcdShapeList containing several ILcdPoint elements | MULTI_POINT |
ILcdShapeList containing several ILcdPolyline elements | MULTI_LINE_STRING |
ILcdShapeList containing several ILcdPolygon elements | MULTI_POLYGON |
ILcdShapeList containing several ILcdComplexPolygon elements | MULTI_POLYGON |
The ILcdShape can also be a homogeneous
ILcdShapeList containing any of the above ILcdShape
instances.
If a LuciadLightspeed complex polygon consists of a single exterior ring and
possibly one or more interior rings (holes) the encoder will map it
to a POLYGON element. If the complex polygon contains more than
one exterior ring, it will be split into several complex polygons, each
containing exactly one exterior ring and all the associated interior rings.
In this case the result is encoded as a MULTI_POLYGON.
When using geodetic data, DB2 expects the orientation of the exterior ring of a complex polygon to be counter-clockwise and the orientation of the interior rings to be clockwise (cf. Chapter 16 - "DB2 Geodetic Data Management Feature" from the IBM DB2 user guide). The encoder automatically changes the orientation of the exterior/interior rings to meet this requirement.
Features are retrieved by means of the ILcdFeatured interface,
which the objects must implement.
Known limitations
- Shapes can be encoded in 3D only when the
useSHPproperty istrue - When the
useSHPproperty istrue, shape list objects containing more than one complex polygon are stored as an unfolded list of all the composing simple polygons, regardless whether they are inner or outer polygons.
Requirements
- When using short-form database connection URLs (
jdbc:db2:DATABASE), the db2jcct2 native library must be in the Java's library path. The library can usually be found in the DB2 installation directory - for example "/opt/ibm/db2/V9.5/lib". To use it, add the "-Djava.library.path=[path]" argument to the command line when launching the Java virtual machine
- Since:
- 8.3.03
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the given model can be saved into the database described by the given properties file.booleanReturns whether the given model can be saved back into the database.voidexport(ILcdModel aModel, Properties aProperties) Exports the given model in a new table, based on the given properties.intReturns the number of inserted elements after which an export operation is committed.Returns a short, displayable name for the format thisILcdModelEncoderencodes to.voidsetAutoCommitCount(int aAutoCommitCount) Sets the number of inserted elements after which an export operation should be committed, periodically.Methods inherited from class com.luciad.format.database.TLcdDatabaseModelEncoder
export, getDatabaseFactory, save, setDatabaseFactory
-
Constructor Details
-
TLcdDB2SpatialModelEncoder
public TLcdDB2SpatialModelEncoder()Creates a new DB2 Spatial model encoder.
-
-
Method Details
-
setAutoCommitCount
public void setAutoCommitCount(int aAutoCommitCount) Sets the number of inserted elements after which an export operation should be committed, periodically. The default is 0, meaning that the export operation is only committed when all elements have been inserted. A different value can be useful to avoid overflow of database transaction logs.- Overrides:
setAutoCommitCountin classTLcdDatabaseModelEncoder
-
getAutoCommitCount
public int getAutoCommitCount()Returns the number of inserted elements after which an export operation is committed.- Overrides:
getAutoCommitCountin classTLcdDatabaseModelEncoder
-
getDisplayName
Description copied from interface:ILcdModelEncoderReturns a short, displayable name for the format thisILcdModelEncoderencodes to.- Specified by:
getDisplayNamein interfaceILcdModelEncoder- Overrides:
getDisplayNamein classTLcdDatabaseModelEncoder- Returns:
- the displayable name of this
ILcdModelEncoder.
-
canExport
Returns whether the given model can be saved into the database described by the given properties file.- Specified by:
canExportin interfaceILcdModelEncoder- Overrides:
canExportin classTLcdDatabaseModelEncoder- Parameters:
aModel- the model to be verified.aDestinationName- the location where the model should be exported to.- Returns:
trueif this encoder can export the specified model to the specified location,falseotherwise.- See Also:
-
export
public void export(ILcdModel aModel, Properties aProperties) throws IOException, IllegalArgumentException Exports the given model in a new table, based on the given properties.- Overrides:
exportin classTLcdDatabaseModelEncoder- Parameters:
aModel- the model to be exported.aProperties- the properties describing the database table to be created.- Throws:
IOException- for any database access errors. This includes the case where the table already exists.IllegalArgumentException
-
canSave
Returns whether the given model can be saved back into the database.- Specified by:
canSavein interfaceILcdModelEncoder- Overrides:
canSavein classTLcdDatabaseModelEncoder- Parameters:
aModel- the model to be verified.- Returns:
trueif this encoder can save the model in the location where it originally came from,falseotherwise.- See Also:
-