Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEOT-6123] GeoPackage reader slowness against large raster geopackages #2046

Merged
merged 1 commit into from Sep 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -161,6 +161,11 @@ public GeoPackage(File file) throws IOException {

/** Creates a GeoPackage from an existing file specifying database credentials. */
public GeoPackage(File file, String user, String passwd) throws IOException {
this(file, user, passwd, false);
}

/** Creates a GeoPackage from an existing file specifying database credentials. */
public GeoPackage(File file, String user, String passwd, boolean readOnly) throws IOException {
this.file = file;

Map params = new HashMap();
Expand All @@ -170,6 +175,9 @@ public GeoPackage(File file, String user, String passwd) throws IOException {
if (passwd != null) {
params.put(GeoPkgDataStoreFactory.PASSWD.key, passwd);
}
if (readOnly) {
params.put(GeoPkgDataStoreFactory.READ_ONLY.key, readOnly);
}

params.put(GeoPkgDataStoreFactory.DATABASE.key, file.getPath());
params.put(GeoPkgDataStoreFactory.DBTYPE.key, GeoPkgDataStoreFactory.DBTYPE.sample);
Expand Down Expand Up @@ -1307,7 +1315,7 @@ public void add(TileEntry entry, Tile tile) throws IOException {
}

/**
* Retrieve tiles within certain zooms and column/row boundaries
* Retrieve tiles within certain zooms and column/row boundaries.
*
* @param entry the tile entry
* @param lowZoom low zoom boundary
Expand All @@ -1331,24 +1339,9 @@ public TileReader reader(

try {
List<String> q = new ArrayList();
if (lowZoom != null) {
q.add("zoom_level >= " + lowZoom);
}
if (highZoom != null) {
q.add("zoom_level <= " + highZoom);
}
if (lowCol != null) {
q.add("tile_column >= " + lowCol);
}
if (highCol != null) {
q.add("tile_column <= " + highCol);
}
if (lowRow != null) {
q.add("tile_row >= " + lowRow);
}
if (highRow != null) {
q.add("tile_row <= " + highRow);
}
addRange("zoom_level", lowZoom, highZoom, q);
addRange("tile_column", lowCol, highCol, q);
addRange("tile_row", lowRow, highRow, q);

StringBuffer sql = new StringBuffer("SELECT * FROM ").append(entry.getTableName());
if (!q.isEmpty()) {
Expand All @@ -1371,6 +1364,19 @@ public TileReader reader(
}
}

public void addRange(String attribute, Integer low, Integer high, List<String> q) {
if (low != null && high != null && low == high) {
q.add(attribute + " = " + low);
} else {
if (low != null) {
q.add(attribute + " >= " + low);
}
if (high != null) {
q.add(attribute + " <= " + high);
}
}
}

protected String getSpatialIndexName(FeatureEntry entry) {

String spatial_index = "rtree_" + entry.getTableName() + "_" + entry.getGeometryColumn();
Expand Down
Expand Up @@ -51,6 +51,8 @@ public class GeoPkgDataStoreFactory extends JDBCDataStoreFactory {
/** parameter for database instance */
public static final Param DATABASE = new Param("database", File.class, "Database", true);

public static final Param READ_ONLY = new Param("read_only", Boolean.class, "Read only", false);

/** base location to store database files */
File baseDirectory = null;

Expand Down Expand Up @@ -156,7 +158,7 @@ public BasicDataSource createDataSource(Map params) throws IOException {
// url
dataSource.setUrl(getJDBCUrl(params));

addConnectionProperties(dataSource);
addConnectionProperties(dataSource, params);

dataSource.setAccessToUnderlyingConnectionAllowed(true);

Expand Down Expand Up @@ -185,10 +187,17 @@ protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOE
return ds;
}

static void addConnectionProperties(BasicDataSource dataSource) {
static void addConnectionProperties(BasicDataSource dataSource, Map configuration)
throws IOException {
SQLiteConfig config = new SQLiteConfig();
config.setSharedCache(true);
config.enableLoadExtension(true);
Object synchronous = READ_ONLY.lookUp(configuration);
if (Boolean.TRUE.equals(synchronous)) {
config.setPragma(SQLiteConfig.Pragma.SYNCHRONOUS, "OFF");
config.setReadOnly(true);
}
// config.setPragma(SQLiteConfig.Pragma.MMAP_SIZE, "268435456");

for (Map.Entry e : config.toProperties().entrySet()) {
dataSource.addConnectionProperty((String) e.getKey(), (String) e.getValue());
Expand Down