Image Mosaic JDBC Design¶
Outline of the multi-threaded architecture¶
The multi-threaded architecture is based on synchronized Queue available since SDK 5.0. The following threads will be used:
One ImageComposer thread which reads GridCoverages from the Queue, mosaicing the image and finally rescales the image for the requested dimension.
For each tile, a TileDecoder thread which decodes the tile, crops the tile if necessary and puts the result as GridCoverage in the queue.
The Main thread for controlling this threads
The Main threads performs the following steps in chronological order If the requested CRS is not equal to the CRS of the tiles, transform the requested CRS
Calculate the best pyramid and query the tiles needed from the database
Create the queue and start the ImageComposer Thread
For each tile fetch the image data and immediately start an ImageDecoder Thread
Wait for all ImageDecoder Threads
Put a predefined End Message in the queue which causes the ImageComposer Thread to finish its work
Wait for the ImageComposer Thread
If the requested CRS is not equal to the CRS of the tiles, reproject the image
Return the GridCoverage
Database Design¶
First, we need a Meta Table for holding Information for each pyramid of the maps. This table has 9 columns as described below
Name(String): The name of the mapSpatialTable(String): The name of the table where to find the georeferencing informationTileTable(String): The name of the table where to find the tile data stored as BLOB.ResX(Double): The resolution of the x-axisResY(Double): The resolution of the y-axisMinX(Double): The minimum X of the extentMinY(Double): The minimum Y of the extentMaxX(Double): The maximum X of the extentMaxY(Double): The maximum Y of the extent
Important
The only fields you have to fill are Name, SpatialTable and TileTable. These three fields together are the primary key. All other fields will be calculated by the plugin. It is not necessary to do calculations. The plugin implements the following mechanism during the first request:
Check if
ResXorResYis null, if true, calculate the values from a random chosen tile from the corresponding tile table.Check if one of
MinX,MinY,MaxX,MaxYis null, if true, calculate the values from the corresponding spatial table.If something has been calculated, store these values into to the database to avoid recalculation at the next restart
This approach assures that the probably costly calculation is only executed once, but updating,adding or removing tiles requires you to nullify one of the MinX, MinY, MaxX, MaxY attributes to force a new extent calculation.
First example
Assume we have a Map called Europe with 2 Pyramids. Since we have 3 levels, we need 3 tile tables and 3 spatial tables. Lets start filling the META table.
|
|
|
|
|
|
|
|
|
|---|---|---|---|---|---|---|---|---|
Europe |
EUSPAT0 |
EUTILE0 |
. |
. |
. |
. |
. |
. |
Europe |
EUSPAT1 |
EUTILE1 |
. |
. |
. |
. |
. |
. |
Europe |
EUSPAT2 |
EUTILE2 |
. |
. |
. |
. |
. |
. |
Remember: You do not have to fill the other attributes.
A tile table needs the following attributes:
Location (String) : A unique identifier for the tile
Data (Blob) : The image data (Encoded in a format readable by JAI, e.g.
png,jpeg,…)
The table EUTILE0 for example ( 0x…. indicates binary data)
Location |
Data |
|---|---|
Tile_1_1 |
0x10011… |
Tile_1_2 |
0x00011.. |
A spatial table contains the georeferencing information. Depending on your database installation, there are 2 possibilities.
You have no spatial db extension implies storing the extent in 4 Double fields
Having a spatial extension offers the possibility to use a geometry column
A spatial Table without using a spatial extension needs the following attributes:
Location(String) : A unique identifier used for joining into the tiles tableMinX(Double): minimum X of the tile extentMinY(Double): minimum Y of the tile extentMaxX(Double): maximum X of the tile extentMaxY(Double): maximum Y of the tile extent
The table EUSPAT0 for example.
|
|
|
|
|
|---|---|---|---|---|
Tile_1_1 |
10 |
10 |
20 |
20 |
Tile_1_2 |
20 |
10 |
30 |
20 |
A spatial Table using a spatial extension needs the following attributes:
Location(String) : A unique identifier used for joining into the tiles tableGeometry(Geometry): A multi-polygon type provided by your database.
The table EUTILE0 for example
Location |
Geom |
|---|---|
Tile_1_1 |
0x00111… |
Tile_1_2 |
0x10011… |
Reducing the number of tables
Since the number of rows in a spatial table has to be equal to the number of rows in a tile table, there is a one to one relationship. It is no problem to join these tables. Applying this redesign to our samples results in the following table structure:
|
|
|
|
|
|
|
|
|
|---|---|---|---|---|---|---|---|---|
Europe |
EU0 |
EU0 |
. |
. |
. |
. |
. |
. |
Europe |
EU1 |
EU1 |
. |
. |
. |
. |
. |
. |
Europe |
EU2 |
EU2 |
. |
. |
. |
. |
. |
. |
The EU0 Table
|
|
|
|
|
|
|---|---|---|---|---|---|
Tile_1_1 |
10 |
10 |
20 |
20 |
0x10011.. |
Tile_1_2 |
20 |
10 |
30 |
20 |
0x00011.. |
or using a geometry column
|
|
|
|---|---|---|
Tile_1_1 |
0x00111… |
0x10011.. |
Tile_1_2 |
0x10011… |
0x00011.. |
Further Database Design Rules
It is possible to add custom columns to your tables
It is possible to create one meta table for all your maps and pyramid levels , or create one meta table for each map containing records for the map and its pyramids, or do any mixture of these two approaches, the only rule is to store a map and its pyramids level together in the same meta table.
All primary key attributes will be handled as JDBC String, the exact DB Type and length depends on your needs.
All numerical fields will be handled as JDBC Double.
Tile image data has to be a BLOB