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 classMBTilesFile.TileIterator
-
Field Summary
Fields Modifier and Type Field Description protected DataSourceconnPoolconnection poolprotected booleandisableJournalBoolean indicating if journal must be disabled or notprotected Filefiledatabase fileprotected static LoggerLOGGERLoggerprotected StringMD_ATTRIBUTIONprotected StringMD_BOUNDSprotected StringMD_CENTERprotected StringMD_DESCRIPTIONprotected StringMD_FORMATprotected StringMD_JSONprotected StringMD_MAXZOOMprotected StringMD_MINZOOMprotected StringMD_NAMEprotected StringMD_TYPEprotected StringMD_VERSIONstatic StringPRAGMA_JOURNAL_MODE_OFFstatic CoordinateReferenceSystemSPHERICAL_MERCATORprotected StringTABLE_GRID_DATAprotected StringTABLE_GRIDSprotected StringTABLE_METADATAprotected StringTABLE_TILESstatic ReferencedEnvelopeWORLD_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 voidclose()Closes the mbtiles database connection.longclosestZoom(long zoomLevel)FilegetFile()The underlying database file.protected RectangleLonggetTileBounds(long zoomLevel, boolean exact)Returns the actual tile bounds for the given zoom level,protected longgetZoomLevel(double distance)Returns the zoom level for the given simplification distancevoidinit()Initializes the mbtiles database.protected voidinit(Connection cx)Initializes a mbtiles connection.MBTilesGridloadGrid(long zoomLevel, long column, long row)MBTilesGridloadGrid(MBTilesGrid entry)MBTilesMetadataloadMetaData()MBTilesMetadataloadMetaData(MBTilesMetadata metaData)protected StringloadMetaDataEntry(String name, Connection cx)MBTilesTileloadTile(long zoomLevel, long column, long row)MBTilesTileloadTile(MBTilesTile entry)longmaxColumn(long zoomLevel)longmaxRow(long zoomLevel)longmaxZoom()longminColumn(long zoomLevel)longminRow(long zoomLevel)longminZoom()intnumberOfTiles()intnumberOfTiles(long zoomLevel)protected voidrunScript(String filename, Connection cx)voidsaveGrid(MBTilesGrid entry)Store a gridvoidsaveMetaData(MBTilesMetadata metaData)Store MetaData in fileprotected voidsaveMetaDataEntry(String name, String value, Connection cx)voidsaveMinMaxZoomMetadata(int min, int max)Save the minimum and maximum zoom level as metadata items.voidsaveTile(MBTilesTile entry)Store a tileMBTilesFile.TileIteratortiles()MBTilesFile.TileIteratortiles(long zoomLevel)MBTilesFile.TileIteratortiles(long zoomLevel, long leftTile, long bottomTile, long rightTile, long topTile)protected static longtilesForZoom(long zoomLevel)protected static ReferencedEnvelopetoEnvelope(MBTilesTileLocation tile)protected ReferencedEnvelopetoEnvelope(RectangleLong rect, long zoom)Converts the tile locations into a real world oneprotected RectangleLongtoTilesRectangle(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 IOExceptionCreates a new empty MbTilesFile, generating a new file.- Throws:
IOException
-
MBTilesFile
public MBTilesFile(boolean disableJournal) throws IOExceptionCreates 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 IOExceptionSave 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:
closein interfaceAutoCloseable
-
getFile
public File getFile()
The underlying database file.Note: this value may be
nulldepending 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 IOExceptionInitializes 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 SQLExceptionReturns the actual tile bounds for the given zoom level,- Throws:
SQLException
-
getZoomLevel
protected long getZoomLevel(double distance) throws SQLExceptionReturns 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)
-
-