mbtiles4j

A pure-java reader/writer for MBTiles

License

License

Categories

Categories

Geo Business Logic Libraries Geospatial
GroupId

GroupId

ch.poole.geo
ArtifactId

ArtifactId

mbtiles4j
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

mbtiles4j
A pure-java reader/writer for MBTiles
Project URL

Project URL

https://github.com/simonpoole/mbtiles4j
Source Code Management

Source Code Management

https://github.com/simonpoole/mbtiles4j.git

Download mbtiles4j

Dependencies

runtime (2)

Group / Artifact Type Version
org.xerial : sqlite-jdbc jar 3.8.7
commons-io : commons-io jar 2.4

Project Modules

There are no modules declared in this project.

mbtiles4j

A pure-java reader/writer for MBTiles

This is a fork of https://github.com/imintel/mbtiles4j that seems to be no longer maintained.

If you need it for Android, check out this fork.

About MBTiles

MBTiles is a MapBox specification for storing large collections of tiles in a single tileset. Each mbtiles file is a sqlite instance with metadata and tiles.

Maven

<dependency>
   <groupId>ch.poole.geo</groupId>
   <artifactId>mbtiles4j</artifactId>
   <version>1.2.0</version>
</dependency>

Illustrative Examples

Reading .mbtiles

MBTilesReader r = new MBTilesReader(new File("control-room-0.2.0.mbtiles"));
//metadata
MetadataEntry metadata = r.getMetadata();
String tileSetName = metadata.getTilesetName();
MetadataEntry.TileSetType type = metadata.getTilesetType();
String tilesetVersion = metadata.getTilesetVersion();
String description = metadata.getTilesetDescription();
MetadataEntry.TileMimeType tileMimeType = metadata.getTileMimeType();
MetadataBounds bounds = metadata.getTilesetBounds();
String attribution = metadata.getAttribution();
//tiles
TileIterator tiles = r.getTiles();
while (tiles.hasNext()) {
	Tile next = tiles.next();
	int zoom = next.getZoom();
	int column = next.getColumn();
	int row = next.getRow();
	InputStream tileData = next.getData();        
}
tiles.close();
r.close();

Writing .mbtiles

MBTilesWriter w = new MBTilesWriter(new File("example.mbtiles"));
MetadataEntry ent = new MetadataEntry();
//Add metadata parts
ent.setTilesetName("An example Tileset")
	.setTilesetType(MetadataEntry.TileSetType.BASE_LAYER)
	.setTilesetVersion("0.2.0")
	.setTilesetDescription("An example tileset description")
	.setTileMimeType(MetadataEntry.TileMimeType.PNG)
	.setAttribution("Tiles are Open Source!")
	.setTilesetBounds(-180, -85, 180, 85);
w.addMetadataEntry(ent);
//add someTile at Zoom (0), Column(0), Row (0)
w.addTile(someTileBytes, 0, 0, 0);
File result = w.close();

Versions

Version
1.2.0