Package org.geotools.mbtiles
Class MBTilesFile
- Object
-
- MBTilesFile
-
- All Implemented Interfaces:
AutoCloseable
public class MBTilesFile extends Object implements AutoCloseable
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
MBTilesFile.TileIterator
-
Field Summary
Fields Modifier and Type Field Description protected DataSource
connPool
connection poolprotected boolean
disableJournal
Boolean indicating if journal must be disabled or notprotected File
file
database fileprotected static Logger
LOGGER
Loggerprotected String
MD_ATTRIBUTION
protected String
MD_BOUNDS
protected String
MD_CENTER
protected String
MD_DESCRIPTION
protected String
MD_FORMAT
protected String
MD_JSON
protected String
MD_MAXZOOM
protected String
MD_MINZOOM
protected String
MD_NAME
protected String
MD_TYPE
protected String
MD_VERSION
static String
PRAGMA_JOURNAL_MODE_OFF
static CoordinateReferenceSystem
SPHERICAL_MERCATOR
protected String
TABLE_GRID_DATA
protected String
TABLE_GRIDS
protected String
TABLE_METADATA
protected String
TABLE_TILES
static ReferencedEnvelope
WORLD_ENVELOPE
-
Constructor Summary
Constructors Constructor Description MBTilesFile()
Creates a new empty MbTilesFile, generating a new file.MBTilesFile(boolean disableJournal)
Creates a new empty MbTilesFile, generating a new file, also deciding if journal must be disabled or not.MBTilesFile(File file)
Creates a MbTilesFile from an existing file.MBTilesFile(File file, boolean disableJournal)
Creates a MbTilesFile from an existing file, also deciding if journal must be disabled or not.MBTilesFile(File file, String user, String passwd, boolean disableJournal)
Creates a MbTilesFile from an existing file specifying database credentials.MBTilesFile(DataSource dataSource)
Create an MBTilesFile from an SQL DataSource connected to an MBTiles file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the mbtiles database connection.long
closestZoom(long zoomLevel)
File
getFile()
The underlying database file.protected RectangleLong
getTileBounds(long zoomLevel, boolean exact)
Returns the actual tile bounds for the given zoom level,protected long
getZoomLevel(double distance)
Returns the zoom level for the given simplification distancevoid
init()
Initializes the mbtiles database.protected void
init(Connection cx)
Initializes a mbtiles connection.MBTilesGrid
loadGrid(long zoomLevel, long column, long row)
MBTilesGrid
loadGrid(MBTilesGrid entry)
MBTilesMetadata
loadMetaData()
MBTilesMetadata
loadMetaData(MBTilesMetadata metaData)
protected String
loadMetaDataEntry(String name, Connection cx)
MBTilesTile
loadTile(long zoomLevel, long column, long row)
MBTilesTile
loadTile(MBTilesTile entry)
long
maxColumn(long zoomLevel)
long
maxRow(long zoomLevel)
long
maxZoom()
long
minColumn(long zoomLevel)
long
minRow(long zoomLevel)
long
minZoom()
int
numberOfTiles()
int
numberOfTiles(long zoomLevel)
protected void
runScript(String filename, Connection cx)
void
saveGrid(MBTilesGrid entry)
Store a gridvoid
saveMetaData(MBTilesMetadata metaData)
Store MetaData in fileprotected void
saveMetaDataEntry(String name, String value, Connection cx)
void
saveMinMaxZoomMetadata(int min, int max)
Save the minimum and maximum zoom level as metadata items.void
saveTile(MBTilesTile entry)
Store a tileMBTilesFile.TileIterator
tiles()
MBTilesFile.TileIterator
tiles(long zoomLevel)
MBTilesFile.TileIterator
tiles(long zoomLevel, long leftTile, long bottomTile, long rightTile, long topTile)
protected static long
tilesForZoom(long zoomLevel)
protected static ReferencedEnvelope
toEnvelope(MBTilesTileLocation tile)
protected ReferencedEnvelope
toEnvelope(RectangleLong rect, long zoom)
Converts the tile locations into a real world oneprotected RectangleLong
toTilesRectangle(Envelope envelope, long zoomLevel)
Converts the envelope into a tiles rectangle containing it, at the requested zoom level.
-
-
-
Field Detail
-
PRAGMA_JOURNAL_MODE_OFF
public static final String PRAGMA_JOURNAL_MODE_OFF
- See Also:
- Constant Field Values
-
TABLE_METADATA
protected final String TABLE_METADATA
- See Also:
- Constant Field Values
-
TABLE_TILES
protected final String TABLE_TILES
- See Also:
- Constant Field Values
-
TABLE_GRIDS
protected final String TABLE_GRIDS
- See Also:
- Constant Field Values
-
TABLE_GRID_DATA
protected final String TABLE_GRID_DATA
- See Also:
- Constant Field Values
-
MD_NAME
protected final String MD_NAME
- See Also:
- Constant Field Values
-
MD_TYPE
protected final String MD_TYPE
- See Also:
- Constant Field Values
-
MD_VERSION
protected final String MD_VERSION
- See Also:
- Constant Field Values
-
MD_DESCRIPTION
protected final String MD_DESCRIPTION
- See Also:
- Constant Field Values
-
MD_FORMAT
protected final String MD_FORMAT
- See Also:
- Constant Field Values
-
MD_BOUNDS
protected final String MD_BOUNDS
- See Also:
- Constant Field Values
-
MD_CENTER
protected final String MD_CENTER
- See Also:
- Constant Field Values
-
MD_ATTRIBUTION
protected final String MD_ATTRIBUTION
- See Also:
- Constant Field Values
-
MD_MINZOOM
protected final String MD_MINZOOM
- See Also:
- Constant Field Values
-
MD_MAXZOOM
protected final String MD_MAXZOOM
- See Also:
- Constant Field Values
-
MD_JSON
protected final String MD_JSON
- See Also:
- Constant Field Values
-
LOGGER
protected static final Logger LOGGER
Logger
-
SPHERICAL_MERCATOR
public static final CoordinateReferenceSystem SPHERICAL_MERCATOR
-
WORLD_ENVELOPE
public static final ReferencedEnvelope WORLD_ENVELOPE
-
file
protected File file
database file
-
connPool
protected final DataSource connPool
connection pool
-
disableJournal
protected boolean disableJournal
Boolean indicating if journal must be disabled or not
-
-
Constructor Detail
-
MBTilesFile
public MBTilesFile() throws IOException
Creates a new empty MbTilesFile, generating a new file.- Throws:
IOException
-
MBTilesFile
public MBTilesFile(boolean disableJournal) throws IOException
Creates a new empty MbTilesFile, generating a new file, also deciding if journal must be disabled or not.This constructor assumes no credentials are required to connect to the database.
- Throws:
IOException
-
MBTilesFile
public MBTilesFile(File file) throws IOException
Creates a MbTilesFile from an existing file.This constructor assumes no credentials are required to connect to the database.
- Throws:
IOException
-
MBTilesFile
public MBTilesFile(File file, boolean disableJournal) throws IOException
Creates a MbTilesFile from an existing file, also deciding if journal must be disabled or not.This constructor assumes no credentials are required to connect to the database.
- Throws:
IOException
-
MBTilesFile
public MBTilesFile(File file, String user, String passwd, boolean disableJournal) throws IOException
Creates a MbTilesFile from an existing file specifying database credentials.- Throws:
IOException
-
MBTilesFile
public MBTilesFile(DataSource dataSource)
Create an MBTilesFile from an SQL DataSource connected to an MBTiles file. Behaviour is undefined if the DataSource is any other form of database.
-
-
Method Detail
-
saveMetaData
public void saveMetaData(MBTilesMetadata metaData) throws IOException
Store MetaData in file- Throws:
IOException
-
saveMinMaxZoomMetadata
public void saveMinMaxZoomMetadata(int min, int max) throws IOException
Save the minimum and maximum zoom level as metadata items. GDAL and QGIS expect these items.- Parameters:
min
- The minimum zoom levelmax
- The maximum zoom level- Throws:
IOException
-
saveTile
public void saveTile(MBTilesTile entry) throws IOException
Store a tile- Throws:
IOException
-
saveGrid
public void saveGrid(MBTilesGrid entry) throws IOException
Store a grid- Throws:
IOException
-
loadMetaData
public MBTilesMetadata loadMetaData() throws IOException
- Throws:
IOException
-
loadMetaData
public MBTilesMetadata loadMetaData(MBTilesMetadata metaData) throws IOException
- Throws:
IOException
-
loadTile
public MBTilesTile loadTile(long zoomLevel, long column, long row) throws IOException
- Throws:
IOException
-
loadTile
public MBTilesTile loadTile(MBTilesTile entry) throws IOException
- Throws:
IOException
-
loadGrid
public MBTilesGrid loadGrid(long zoomLevel, long column, long row) throws IOException
- Throws:
IOException
-
loadGrid
public MBTilesGrid loadGrid(MBTilesGrid entry) throws IOException
- Throws:
IOException
-
tiles
public MBTilesFile.TileIterator tiles() throws SQLException
- Throws:
SQLException
-
tiles
public MBTilesFile.TileIterator tiles(long zoomLevel) throws SQLException
- Throws:
SQLException
-
tiles
public MBTilesFile.TileIterator tiles(long zoomLevel, long leftTile, long bottomTile, long rightTile, long topTile) throws SQLException
- Throws:
SQLException
-
numberOfTiles
public int numberOfTiles() throws SQLException
- Throws:
SQLException
-
numberOfTiles
public int numberOfTiles(long zoomLevel) throws SQLException
- Throws:
SQLException
-
closestZoom
public long closestZoom(long zoomLevel) throws SQLException
- Throws:
SQLException
-
minZoom
public long minZoom() throws SQLException
- Throws:
SQLException
-
maxZoom
public long maxZoom() throws SQLException
- Throws:
SQLException
-
minColumn
public long minColumn(long zoomLevel) throws SQLException
- Throws:
SQLException
-
maxColumn
public long maxColumn(long zoomLevel) throws SQLException
- Throws:
SQLException
-
minRow
public long minRow(long zoomLevel) throws SQLException
- Throws:
SQLException
-
maxRow
public long maxRow(long zoomLevel) throws SQLException
- Throws:
SQLException
-
close
public void close()
Closes the mbtiles database connection.The application should always call this method when done with a mbtiles to prevent connection leakage.
- Specified by:
close
in interfaceAutoCloseable
-
getFile
public File getFile()
The underlying database file.Note: this value may be
null
depending on how the geopackage was initialized.
-
saveMetaDataEntry
protected void saveMetaDataEntry(String name, String value, Connection cx) throws SQLException
- Throws:
SQLException
-
loadMetaDataEntry
protected String loadMetaDataEntry(String name, Connection cx) throws SQLException
- Throws:
SQLException
-
init
public void init() throws IOException
Initializes the mbtiles database.This method creates all the necessary tables.
- Throws:
IOException
-
init
protected void init(Connection cx) throws SQLException
Initializes a mbtiles connection.This method creates all the necessary tables.
- Throws:
SQLException
-
runScript
protected void runScript(String filename, Connection cx) throws SQLException
- Throws:
SQLException
-
toTilesRectangle
protected RectangleLong toTilesRectangle(Envelope envelope, long zoomLevel) throws SQLException
Converts the envelope into a tiles rectangle containing it, at the requested zoom level. X tiles start from west and increase towards east, Y tiles start from north and increase towards south- Throws:
SQLException
-
tilesForZoom
protected static long tilesForZoom(long zoomLevel)
-
getTileBounds
protected RectangleLong getTileBounds(long zoomLevel, boolean exact) throws SQLException
Returns the actual tile bounds for the given zoom level,- Throws:
SQLException
-
getZoomLevel
protected long getZoomLevel(double distance) throws SQLException
Returns the zoom level for the given simplification distance- Throws:
SQLException
-
toEnvelope
protected ReferencedEnvelope toEnvelope(RectangleLong rect, long zoom)
Converts the tile locations into a real world one- Parameters:
rect
- The tile rectangle, in tile spacezoom
- The zoom level
-
toEnvelope
protected static ReferencedEnvelope toEnvelope(MBTilesTileLocation tile)
-
-