Skip to content

Commit

Permalink
geopackage-core version 6.6.7, bounds query tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bosborn committed Jan 18, 2024
1 parent 264713c commit 097cf9c
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Adheres to [Semantic Versioning](http://semver.org/).

## 6.6.5 (TBD)

* TBD
* geopackage-core version 6.6.7

## [6.6.4](https://github.com/ngageoint/geopackage-java/releases/tag/6.6.4) (11-29-2023)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>mil.nga.geopackage</groupId>
<artifactId>geopackage-core</artifactId>
<version>6.6.5</version>
<version>6.6.7</version>
<exclusions>
<exclusion>
<groupId>com.j256.ormlite</groupId>
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/mil/nga/geopackage/tiles/user/TileCreateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,16 @@ public void testThreadedTileDao() throws SQLException {

}

/**
* Test bounds query on any table as a user custom dao
*
* @throws SQLException
*/
@Test
public void testBoundsQuery() throws SQLException {

TileUtils.testBoundsQuery(geoPackage);

}

}
12 changes: 12 additions & 0 deletions src/test/java/mil/nga/geopackage/tiles/user/TileImportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,16 @@ public void testThreadedTileDao() throws SQLException {

}

/**
* Test bounds query on any table as a user custom dao
*
* @throws SQLException
*/
@Test
public void testBoundsQuery() throws SQLException {

TileUtils.testBoundsQuery(geoPackage);

}

}
232 changes: 232 additions & 0 deletions src/test/java/mil/nga/geopackage/tiles/user/TileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
import mil.nga.geopackage.tiles.matrixset.TileMatrixSet;
import mil.nga.geopackage.tiles.matrixset.TileMatrixSetDao;
import mil.nga.geopackage.user.ColumnValue;
import mil.nga.geopackage.user.custom.UserCustomDao;
import mil.nga.geopackage.user.custom.UserCustomResultSet;
import mil.nga.geopackage.user.custom.UserCustomRow;
import mil.nga.proj.ProjectionConstants;
import mil.nga.sf.proj.GeometryTransform;

Expand Down Expand Up @@ -1363,4 +1366,233 @@ public void run() {
}
}

/**
* Test bounds query on any table as a user custom dao
*
* @param geoPackage
* GeoPackage
* @throws SQLException
* upon error
*/
public static void testBoundsQuery(GeoPackage geoPackage)
throws SQLException {

TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

if (tileMatrixSetDao.isTableExists()) {

UserCustomDao dao = geoPackage
.getUserCustomDao(TileMatrixSet.TABLE_NAME);

List<TileMatrixSet> tileMatrixSets = tileMatrixSetDao.queryForAll();

for (TileMatrixSet tileMatrixSet : tileMatrixSets) {

String tableName = tileMatrixSet.getTableName();

final BoundingBox boundingBox = tileMatrixSet.getBoundingBox();

UserCustomResultSet results = query(dao, boundingBox);
TestCase.assertTrue(contains(results, tableName));

double midLon = boundingBox.getMinLongitude()
+ ((boundingBox.getMaxLongitude()
- boundingBox.getMinLongitude()) / 2.0);
double midLat = boundingBox.getMinLatitude()
+ ((boundingBox.getMaxLatitude()
- boundingBox.getMinLatitude()) / 2.0);

BoundingBox bbox = boundingBox.copy();
bbox.setMaxLongitude(midLon);
bbox.setMaxLatitude(midLat);

results = query(dao, bbox);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(midLon);
bbox.setMinLatitude(midLat);

results = query(dao, bbox);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(midLon - 0.000001);
bbox.setMinLatitude(midLat - 0.000001);
bbox.setMaxLongitude(midLon + 0.000001);
bbox.setMaxLatitude(midLat + 0.000001);

results = query(dao, bbox);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(midLon);
bbox.setMinLatitude(boundingBox.getMinLatitude() - 0.000001);
bbox.setMaxLongitude(boundingBox.getMaxLongitude() + 0.000001);
bbox.setMaxLatitude(midLat);

results = query(dao, bbox);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(boundingBox.getMinLongitude() - 0.000001);
bbox.setMinLatitude(midLat);
bbox.setMaxLongitude(midLon);
bbox.setMaxLatitude(boundingBox.getMaxLatitude() + 0.000001);

results = query(dao, bbox);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLatitude(boundingBox.getMaxLatitude());
bbox.setMaxLatitude(boundingBox.getMaxLatitude() + 0.000001);

results = query(dao, bbox);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLatitude(boundingBox.getMaxLatitude() + 0.000001);
bbox.setMaxLatitude(boundingBox.getMaxLatitude() + 1.0);

results = query(dao, bbox);
TestCase.assertFalse(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(boundingBox.getMinLongitude() - 0.000001);
bbox.setMaxLongitude(boundingBox.getMinLongitude());

results = query(dao, bbox);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(boundingBox.getMinLongitude() - 1.0);
bbox.setMaxLongitude(boundingBox.getMinLongitude() - 0.000001);

results = query(dao, bbox);
TestCase.assertFalse(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(boundingBox.getMinLongitude() - 0.000001);
bbox.setMinLatitude(boundingBox.getMinLatitude() - 0.000001);
bbox.setMaxLongitude(boundingBox.getMaxLongitude() + 0.000001);
bbox.setMaxLatitude(boundingBox.getMaxLatitude() + 0.000001);

results = query(dao, bbox);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(midLon - 0.000001);
bbox.setMinLatitude(boundingBox.getMaxLatitude() + 0.000001);
bbox.setMaxLongitude(midLon + 0.000001);
bbox.setMaxLatitude(boundingBox.getMaxLatitude() + 1.0);

results = query(dao, bbox);
TestCase.assertFalse(contains(results, tableName));

results = query(dao, bbox, null, 0.000001);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(boundingBox.getMinLongitude() - 1.0);
bbox.setMinLatitude(midLat - 0.000001);
bbox.setMaxLongitude(boundingBox.getMinLongitude() - 0.000001);
bbox.setMaxLatitude(midLat + 0.000001);

results = query(dao, bbox);
TestCase.assertFalse(contains(results, tableName));

results = query(dao, bbox, 0.000001, null);
TestCase.assertTrue(contains(results, tableName));

bbox = boundingBox.copy();
bbox.setMinLongitude(boundingBox.getMinLongitude() - 2.0);
bbox.setMinLatitude(boundingBox.getMaxLatitude() + 1.0);
bbox.setMaxLongitude(boundingBox.getMinLongitude() - 1.0);
bbox.setMaxLatitude(boundingBox.getMaxLatitude() + 2.0);

results = query(dao, bbox);
TestCase.assertFalse(contains(results, tableName));

results = query(dao, bbox, null, 1.0);
TestCase.assertFalse(contains(results, tableName));

results = query(dao, bbox, 1.0, null);
TestCase.assertFalse(contains(results, tableName));

results = query(dao, bbox, 1.0, 1.0);
TestCase.assertTrue(contains(results, tableName));

}
}

}

/**
* Query for the bounding box
*
* @param dao
* data access object
* @param boundingBox
* bounding box
* @return results
*/
private static UserCustomResultSet query(UserCustomDao dao,
BoundingBox boundingBox) {
return query(dao, boundingBox, null, null);
}

/**
* Query for the bounding box
*
* @param dao
* data access object
* @param boundingBox
* bounding box
* @param lonTolerance
* longitude tolerance
* @param latTolerance
* latitude tolerance
* @return results
*/
private static UserCustomResultSet query(UserCustomDao dao,
BoundingBox boundingBox, Double lonTolerance, Double latTolerance) {

String where = dao.buildWhere(TileMatrixSet.COLUMN_MIN_X,
TileMatrixSet.COLUMN_MIN_Y, TileMatrixSet.COLUMN_MAX_X,
TileMatrixSet.COLUMN_MAX_Y, boundingBox);
String[] args = dao.buildWhereArgs(boundingBox, lonTolerance,
latTolerance);

return dao.query(where, args);
}

/**
* Check if the table name was found in the results
*
* @param results
* results
* @param tableName
* table name
* @return true if in results
*/
private static boolean contains(UserCustomResultSet results,
String tableName) {

boolean found = false;

try {
for (UserCustomRow row : results) {
if (row.getValue(TileMatrixSet.COLUMN_TABLE_NAME)
.equals(tableName)) {
found = true;
break;
}
}
} finally {
results.close();
}

return found;
}

}

0 comments on commit 097cf9c

Please sign in to comment.