forked from imintel/mbtiles4j
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMBTilesReader.java
More file actions
59 lines (51 loc) · 1.88 KB
/
MBTilesReader.java
File metadata and controls
59 lines (51 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.myroutes.mbtiles4j;
import com.myroutes.mbtiles4j.*;
import com.myroutes.mbtiles4j.TileIterator;
import com.myroutes.mbtiles4j.model.MetadataEntry;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MBTilesReader {
private File f;
private Connection connection;
public MBTilesReader(File f) throws MBTilesReadException {
try {
connection = com.myroutes.mbtiles4j.SQLHelper.establishConnection(f);
} catch (MBTilesException e) {
throw new MBTilesReadException("Establish Connection to " + f.getAbsolutePath() + " failed", e);
}
this.f = f;
}
public File close() {
try {
connection.close();
} catch (SQLException e) {
}
return f;
}
public MetadataEntry getMetadata() throws MBTilesReadException {
String sql = "SELECT * from metadata;";
try {
ResultSet resultSet = com.myroutes.mbtiles4j.SQLHelper.executeQuery(connection, sql);
MetadataEntry ent = new MetadataEntry();
while (resultSet.next()) {
String name = resultSet.getString("name");
String value = resultSet.getString("value");
ent.addKeyValue(name, value);
}
return ent;
} catch (MBTilesException | SQLException e) {
throw new MBTilesReadException("Get Metadata failed", e);
}
}
public com.myroutes.mbtiles4j.TileIterator getTiles() throws MBTilesReadException {
String sql = "SELECT * from tiles;";
try {
ResultSet resultSet = com.myroutes.mbtiles4j.SQLHelper.executeQuery(connection, sql);
return new TileIterator(resultSet);
} catch (MBTilesException e) {
throw new MBTilesReadException("Access Tiles failed", e);
}
}
}