Classes for reading data from an Oracle spatial relational model database
The reader classes for Oracle®
SDO relational model (package ilog.views.maps.format.oracle) are:
- IlvSDOFeatureIterator for converting Oracle Spatial layer data into IlvMapFeature objects.
- IlvSDOLayer for implementing load-on-demand for Oracle Spatial data.
- IlvSDOTileLoader abstract class for defining Oracle queries for the
IlvSDOLayer
. An optimized subclass, IlvDefaultSDOTileLoader is used byIlvSDOLayer
.
The IlvSDOFeatureIterator class
The IlvSDOFeatureIterator class reads data
from the result of an SQL query to a relational Oracle Spatial
layer and converts them into
IlvMapFeature
objects. JViews
Maps applications can handle Oracle Spatial data using this
class in a transparent manner.
The following example of Java™
code performs a query, loading data from an Oracle Spatial
layer named
ROADS_SDOGEOM
. It includes classes from the
java.sql
package:
String query = "SELECT * FROM ROADS_SDOGEOM ORDER BY 1, 2, 4 "; Statement statement = getConnection().createStatement(); ResultSet resultSet = statement.executeQuery(query); IlvSDOFeatureIterator iterator = new IlvSDOFeatureIterator(resultSet);
The
connection
variable is a
java.sql.Connection
object.
The query orders the result using the
following three criteria, which must be given in the order
indicated:
- GID (Geometric ID)
- ESEQ (Element Sequence)
- SEQ (Row Sequence)
Note
This ordering is necessary for the
IlvSDOFeatureIterator
to work correctly.
The
ResultSet
of any query to an Oracle Spatial layer can be used to
initialize an IlvSDOFeatureIterator, but all the SDO
columns must be in the
resultSet
(columns defining the GID, ESEQ, ETYPE, SEQ, and the
coordinates).
The features returned by this iterator have no attributes.
However, the GID of the Oracle Spatial geometry is used as the
identifier of each feature and this identifier can be used to
retrieve additional attributes from the database. See the
method getId.
The IlvSDOLayer class
This class implements load-on-demand for
a relational Oracle Spatial data source. The default
implementation takes an Oracle Spatial layer for which a
spatial indexation has been performed and reads its content
with a tiling equivalent to the Oracle Spatial tiling.
The following example creates an IlvSDOLayer on an Oracle Spatial layer
named
ROADS
:
IlvSDOConnection connection = new IlvSDOConnection(url, userName, password); IlvSDOLayer layer = new IlvSDOLayer(connection, "ROADS"); manager.addLayer(layer,-1);
The IlvSDOTileLoader class
This class offers additional possibilities when retrieving data
from an Oracle Spatial database. These possibilities are meant
as a supplement to the default behavior of
IlvSDOLayer
. For example, you may want to add filters to a layer or to
have a tiling definition that is different than the Oracle
tiling.
The example in the file <installdir> /jviews-maps810/samples/oracle/index.htmlshows
how to implement a subclass IlvSDOTileLoader that uses spatial
queries to retrieve data for a JViews Maps tile.
The IlvDefaultSDOTileLoader class
This class is a subclass of
IlvSDOTileLoader
and is used by the
IlvSDOLayer
. It has some optimizations. For example, the setTileGroupingCount method allows you to
set the number of tiles that are grouped in one unique query to
the database. In fact, each tile corresponds to a Spatial
Query. If you have an average of
n
tiles to load each time you want to load on demand, you should
use
setTileGroupingCount(n)
, where all the
n
queries are grouped into one unique query that is sent to the
database.
Note
If you want to handle special operations on each IlvMapFeature retrieved in
Load-On-Demand with the IlvSDOLayer layer, you have to subclass
the IlvDefaultSDOTileLoader in order to
override the
getFeatureIterator()
method. In this method, you have to return an instance of a
subclass of IlvSDOFeatureIterator where you have
overridden the
getNextFeature()
method (inside which you can perform your specific operations
on each
IlvMapFeature
returned by the layer). Finally, you have to set your subclass
of
IlvDefaultSDOTileLoader
as the tile loader of the layer.
Class for writing data to an Oracle spatial relational model database
The IlvSDOWriter class allows you to write map
features into a relational Oracle Spatial database.
The IlvSDOWriter class
The
IlvSDOWriter
class can write any IlvMapFeatureIterator whose features have
a geometry supported by the relational model of Oracle Spatial
and write them to the database as in the following example:
IlvSDOWriter writer = new IlvSDOWriter(connection.getConnection() "MyLayer", 16, new IlvCoordinate(-360d, 90d), new IlvCoordinate(360d, -90d)); // Creating a source feature iterator. IlvShapeFileReader reader = new IlvShapeFileReader(...); // Dumping its content to the Oracle layer. writer.writeFeatureIterator(reader);
The
write()
method of the
IlvSDOWriter
does not write the attributes of the features. If you want to
write the attributes of the features, you can subtype the
writeFeature()
method of the
IlvSDOWriter
, after calling
super.writeFeature(feature)
.
The geometries supported by the Oracle
Spatial writer are:
- IlvMapMultiCurve for geometries composed of multiple line strings.
- IlvMapMultiArea for geometries composed of multiple polygons.