@Test public void testLocalEnvelopeToTiles() throws IOException, SQLException { MBTilesFile mbTilesFile = new MBTilesFile( new File("./src/test/resources/org/geotools/mbtiles/madagascar.mbtiles")); ReferencedEnvelope envelope = new ReferencedEnvelope(0, 5000000, 0, 5000000, MBTilesFile.SPHERICAL_MERCATOR); RectangleLong bounds = mbTilesFile.toTilesRectangle(envelope, 7); System.out.println(bounds); assertEquals(64, bounds.getMinX()); assertEquals(79, bounds.getMaxX()); assertEquals(64, bounds.getMinY()); assertEquals(79, bounds.getMaxY()); }
protected RectangleLong toTilesRectangle(Envelope envelope, long zoomLevel) throws SQLException { long numberOfTiles = tilesForZoom(zoomLevel); double resX = WORLD_ENVELOPE.getSpan(0) / numberOfTiles; double resY = WORLD_ENVELOPE.getSpan(1) / numberOfTiles; double offsetX = WORLD_ENVELOPE.getMinimum(0); double offsetY = WORLD_ENVELOPE.getMinimum(1); long minTileX = Math.round(Math.floor((envelope.getMinX() - offsetX) / resX)); long maxTileX = Math.round(Math.floor((envelope.getMaxX() - offsetX) / resX)); long minTileY = Math.round(Math.floor((envelope.getMinY() - offsetY) / resY)); long maxTileY = Math.round(Math.floor((envelope.getMaxY() - offsetY) / resY)); return new RectangleLong(minTileX, maxTileX, minTileY, maxTileY); }
MBTilesFile implements AutoCloseable { protected RectangleLong toTilesRectangle(Envelope envelope, long zoomLevel) throws SQLException { long numberOfTiles = tilesForZoom(zoomLevel); double resX = WORLD_ENVELOPE.getSpan(0) / numberOfTiles; double resY = WORLD_ENVELOPE.getSpan(1) / numberOfTiles; double offsetX = WORLD_ENVELOPE.getMinimum(0); double offsetY = WORLD_ENVELOPE.getMinimum(1); long minTileX = Math.round(Math.floor((envelope.getMinX() - offsetX) / resX)); long maxTileX = Math.round(Math.floor((envelope.getMaxX() - offsetX) / resX)); long minTileY = Math.round(Math.floor((envelope.getMinY() - offsetY) / resY)); long maxTileY = Math.round(Math.floor((envelope.getMaxY() - offsetY) / resY)); return new RectangleLong(minTileX, maxTileX, minTileY, maxTileY); } }
MBTilesFile implements AutoCloseable { protected RectangleLong toTilesRectangle(Envelope envelope, long zoomLevel) throws SQLException { long numberOfTiles = tilesForZoom(zoomLevel); double resX = WORLD_ENVELOPE.getSpan(0) / numberOfTiles; double resY = WORLD_ENVELOPE.getSpan(1) / numberOfTiles; double offsetX = WORLD_ENVELOPE.getMinimum(0); double offsetY = WORLD_ENVELOPE.getMinimum(1); long minTileX = Math.round(Math.floor((envelope.getMinX() - offsetX) / resX)); long maxTileX = Math.round(Math.floor((envelope.getMaxX() - offsetX) / resX)); long minTileY = Math.round(Math.floor((envelope.getMinY() - offsetY) / resY)); long maxTileY = Math.round(Math.floor((envelope.getMaxY() - offsetY) / resY)); return new RectangleLong(minTileX, maxTileX, minTileY, maxTileY); } MBTilesFile();  MBTilesFile(boolean disableJournal);  MBTilesFile(File file);  MBTilesFile(File file, boolean disableJournal);  MBTilesFile(File file, String user, String passwd, boolean disableJournal);  MBTilesFile(DataSource dataSource); }
MBTilesFile implements AutoCloseable { protected RectangleLong toTilesRectangle(Envelope envelope, long zoomLevel) throws SQLException { long numberOfTiles = tilesForZoom(zoomLevel); double resX = WORLD_ENVELOPE.getSpan(0) / numberOfTiles; double resY = WORLD_ENVELOPE.getSpan(1) / numberOfTiles; double offsetX = WORLD_ENVELOPE.getMinimum(0); double offsetY = WORLD_ENVELOPE.getMinimum(1); long minTileX = Math.round(Math.floor((envelope.getMinX() - offsetX) / resX)); long maxTileX = Math.round(Math.floor((envelope.getMaxX() - offsetX) / resX)); long minTileY = Math.round(Math.floor((envelope.getMinY() - offsetY) / resY)); long maxTileY = Math.round(Math.floor((envelope.getMaxY() - offsetY) / resY)); return new RectangleLong(minTileX, maxTileX, minTileY, maxTileY); } MBTilesFile();  MBTilesFile(boolean disableJournal);  MBTilesFile(File file);  MBTilesFile(File file, boolean disableJournal);  MBTilesFile(File file, String user, String passwd, boolean disableJournal);  MBTilesFile(DataSource dataSource); void saveMetaData(MBTilesMetadata metaData); void saveMinMaxZoomMetadata(int min, int max); void saveTile(MBTilesTile entry); void saveGrid(MBTilesGrid entry); MBTilesMetadata loadMetaData(); MBTilesMetadata loadMetaData(MBTilesMetadata metaData); MBTilesTile loadTile(long zoomLevel, long column, long row); MBTilesTile loadTile(MBTilesTile entry); MBTilesGrid loadGrid(long zoomLevel, long column, long row); MBTilesGrid loadGrid(MBTilesGrid entry); @SuppressWarnings("PMD.CloseResource") TileIterator tiles(); @SuppressWarnings("PMD.CloseResource") TileIterator tiles(long zoomLevel); @SuppressWarnings("PMD.CloseResource") TileIterator tiles(
            long zoomLevel, long leftTile, long bottomTile, long rightTile, long topTile); int numberOfTiles(); int numberOfTiles(long zoomLevel); long closestZoom(long zoomLevel); long minZoom(); long maxZoom(); long minColumn(long zoomLevel); long maxColumn(long zoomLevel); long minRow(long zoomLevel); long maxRow(long zoomLevel); void close(); File getFile(); void init(); }
MBTilesFile implements AutoCloseable { protected RectangleLong toTilesRectangle(Envelope envelope, long zoomLevel) throws SQLException { long numberOfTiles = tilesForZoom(zoomLevel); double resX = WORLD_ENVELOPE.getSpan(0) / numberOfTiles; double resY = WORLD_ENVELOPE.getSpan(1) / numberOfTiles; double offsetX = WORLD_ENVELOPE.getMinimum(0); double offsetY = WORLD_ENVELOPE.getMinimum(1); long minTileX = Math.round(Math.floor((envelope.getMinX() - offsetX) / resX)); long maxTileX = Math.round(Math.floor((envelope.getMaxX() - offsetX) / resX)); long minTileY = Math.round(Math.floor((envelope.getMinY() - offsetY) / resY)); long maxTileY = Math.round(Math.floor((envelope.getMaxY() - offsetY) / resY)); return new RectangleLong(minTileX, maxTileX, minTileY, maxTileY); } MBTilesFile();  MBTilesFile(boolean disableJournal);  MBTilesFile(File file);  MBTilesFile(File file, boolean disableJournal);  MBTilesFile(File file, String user, String passwd, boolean disableJournal);  MBTilesFile(DataSource dataSource); void saveMetaData(MBTilesMetadata metaData); void saveMinMaxZoomMetadata(int min, int max); void saveTile(MBTilesTile entry); void saveGrid(MBTilesGrid entry); MBTilesMetadata loadMetaData(); MBTilesMetadata loadMetaData(MBTilesMetadata metaData); MBTilesTile loadTile(long zoomLevel, long column, long row); MBTilesTile loadTile(MBTilesTile entry); MBTilesGrid loadGrid(long zoomLevel, long column, long row); MBTilesGrid loadGrid(MBTilesGrid entry); @SuppressWarnings("PMD.CloseResource") TileIterator tiles(); @SuppressWarnings("PMD.CloseResource") TileIterator tiles(long zoomLevel); @SuppressWarnings("PMD.CloseResource") TileIterator tiles(
            long zoomLevel, long leftTile, long bottomTile, long rightTile, long topTile); int numberOfTiles(); int numberOfTiles(long zoomLevel); long closestZoom(long zoomLevel); long minZoom(); long maxZoom(); long minColumn(long zoomLevel); long maxColumn(long zoomLevel); long minRow(long zoomLevel); long maxRow(long zoomLevel); void close(); File getFile(); void init(); static final String PRAGMA_JOURNAL_MODE_OFF; static final CoordinateReferenceSystem SPHERICAL_MERCATOR; static final ReferencedEnvelope WORLD_ENVELOPE; }