@LcdService(service=ILcdModelEncoder.class, priority=20000) public class TLcdDB2SpatialModelEncoder extends TLcdDatabaseModelEncoder
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. Each featureNames.i
must have a corresponding
featureDataTypes.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 (see
ILcdSHPMeasure
and
ILcdSHPMeasureList
).
dropBeforeCreatingTable
(optional, default=false): if set to
true
, 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.
useSHP
property is
true
useSHP
property is true
, 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.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
Constructor and Description |
---|
TLcdDB2SpatialModelEncoder()
Creates a new DB2 Spatial model encoder.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canExport(ILcdModel aModel,
String aDestinationName)
Returns whether the given model can be saved into the database described
by the given properties file.
|
boolean |
canSave(ILcdModel aModel)
Returns whether the given model can be saved back into the database.
|
void |
export(ILcdModel aModel,
Properties aProperties)
Exports the given model in a new table, based on the given properties.
|
int |
getAutoCommitCount()
Returns the number of inserted elements after which an export operation
is committed.
|
String |
getDisplayName()
Returns a short, displayable name for the format this
ILcdModelEncoder encodes to. |
void |
setAutoCommitCount(int aAutoCommitCount)
Sets the number of inserted elements after which an export operation
should be committed, periodically.
|
export, getDatabaseFactory, save, setDatabaseFactory
public TLcdDB2SpatialModelEncoder()
public void setAutoCommitCount(int aAutoCommitCount)
setAutoCommitCount
in class TLcdDatabaseModelEncoder
public int getAutoCommitCount()
getAutoCommitCount
in class TLcdDatabaseModelEncoder
public String getDisplayName()
ILcdModelEncoder
ILcdModelEncoder
encodes to.getDisplayName
in interface ILcdModelEncoder
getDisplayName
in class TLcdDatabaseModelEncoder
ILcdModelEncoder
.public boolean canExport(ILcdModel aModel, String aDestinationName)
canExport
in interface ILcdModelEncoder
canExport
in class TLcdDatabaseModelEncoder
aModel
- the model to be verified.aDestinationName
- the location where the model should be exported to.true
if this encoder can export the specified model to the
specified location, false
otherwise.ILcdModelEncoder.export(com.luciad.model.ILcdModel, java.lang.String)
public void export(ILcdModel aModel, Properties aProperties) throws IOException, IllegalArgumentException
export
in class TLcdDatabaseModelEncoder
aModel
- the model to be exported.aProperties
- the properties describing the database table to be created.IOException
- for any database access errors. This includes
the case where the table already exists.IllegalArgumentException
public boolean canSave(ILcdModel aModel)
canSave
in interface ILcdModelEncoder
canSave
in class TLcdDatabaseModelEncoder
aModel
- the model to be verified.true
if this encoder can save the model in the location where it originally came from,
false
otherwise.ILcdModelEncoder.save(com.luciad.model.ILcdModel)