Java Code Examples for mil.nga.geopackage.features.columns.GeometryColumnsDao#queryForAll()
The following examples show how to use
mil.nga.geopackage.features.columns.GeometryColumnsDao#queryForAll() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureUtils.java From geopackage-java with MIT License | 5 votes |
/** * Test delete * * @param geoPackage * GeoPackage * @throws SQLException * upon error */ public static void testDelete(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); TestCase.assertNotNull(dao); FeatureResultSet cursor = dao.queryForAll(); int count = cursor.getCount(); if (count > 0) { // Choose random feature int random = (int) (Math.random() * count); cursor.moveToPosition(random); FeatureRow featureRow = cursor.getRow(); cursor.close(); // Delete row TestCase.assertEquals(1, dao.delete(featureRow)); // Verify deleted FeatureRow queryFeatureRow = dao.queryForIdRow(featureRow .getId()); TestCase.assertNull(queryFeatureRow); cursor = dao.queryForAll(); TestCase.assertEquals(count - 1, cursor.getCount()); cursor.close(); } cursor.close(); } } }
Example 2
Source File: GoogleMapShapeConverterUtils.java From geopackage-android-map with MIT License | 4 votes |
/** * Test shapes * * @param geoPackage * @throws SQLException */ public static void testShapes(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); GoogleMapShapeConverter converter = new GoogleMapShapeConverter( dao.getProjection()); converter.setExteriorOrientation(null); converter.setHoleOrientation(null); // Query for all FeatureCursor cursor = dao.queryForAll(); while (cursor.moveToNext()) { FeatureRow featureRow = cursor.getRow(); GeoPackageGeometryData geometryData = featureRow .getGeometry(); if (geometryData != null) { Geometry geometry = geometryData.getGeometry(); GeometryType geometryType = geometry.getGeometryType(); switch (geometryType) { case POINT: convertPoint(converter, (Point) geometry); break; case LINESTRING: convertLineString(converter, (LineString) geometry); break; case POLYGON: convertPolygon(converter, (Polygon) geometry); break; case MULTIPOINT: convertMultiPoint(converter, (MultiPoint) geometry); break; case MULTILINESTRING: convertMultiLineString(converter, (MultiLineString) geometry); break; case MULTIPOLYGON: convertMultiPolygon(converter, (MultiPolygon) geometry); break; case CIRCULARSTRING: convertLineString(converter, (CircularString) geometry); break; case COMPOUNDCURVE: convertCompoundCurve(converter, (CompoundCurve) geometry); break; case POLYHEDRALSURFACE: convertMultiPolygon(converter, (PolyhedralSurface) geometry); break; case TIN: convertMultiPolygon(converter, (TIN) geometry); break; case TRIANGLE: convertPolygon(converter, (Triangle) geometry); break; default: } } } cursor.close(); } } }
Example 3
Source File: FeatureUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test update * * @param geoPackage GeoPackage * @throws SQLException upon error */ public static void testUpdate(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); testUpdate(dao); } } }
Example 4
Source File: FeatureUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test delete * * @param geoPackage GeoPackage * @throws SQLException upon error */ public static void testDelete(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); TestCase.assertNotNull(dao); FeatureCursor cursor = dao.queryForAll(); int count = cursor.getCount(); if (count > 0) { // Choose random feature int random = (int) (Math.random() * count); cursor.moveToPosition(random); FeatureRow featureRow = cursor.getRow(); cursor.close(); // Delete row try { TestCase.assertEquals(1, dao.delete(featureRow)); } catch (SQLiteException e) { if (TestUtils.isFutureSQLiteException(e)) { continue; } else { throw e; } } // Verify deleted FeatureRow queryFeatureRow = dao.queryForIdRow(featureRow .getId()); TestCase.assertNull(queryFeatureRow); cursor = dao.queryForAll(); TestCase.assertEquals(count - 1, cursor.getCount()); cursor.close(); } cursor.close(); } } }
Example 5
Source File: GeometryColumnsUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test delete * * @param geoPackage * @throws SQLException */ public static void testDelete(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao(); if (dao.isTableExists()) { List<GeometryColumns> results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random geometry columns int random = (int) (Math.random() * results.size()); GeometryColumns geometryColumns = results.get(random); // Delete the geometry columns dao.delete(geometryColumns); // Verify deleted GeometryColumns queryGeometryColumns = dao .queryForId(geometryColumns.getId()); TestCase.assertNull(queryGeometryColumns); // Prepared deleted results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random geometry columns random = (int) (Math.random() * results.size()); geometryColumns = results.get(random); // Find which geometry columns to delete QueryBuilder<GeometryColumns, TableColumnKey> qb = dao .queryBuilder(); qb.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME, geometryColumns.getGeometryType().getName()); PreparedQuery<GeometryColumns> query = qb.prepare(); List<GeometryColumns> queryResults = dao.query(query); int count = queryResults.size(); // Delete DeleteBuilder<GeometryColumns, TableColumnKey> db = dao .deleteBuilder(); db.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME, geometryColumns.getGeometryType().getName()); PreparedDelete<GeometryColumns> deleteQuery = db.prepare(); int deleted = dao.delete(deleteQuery); TestCase.assertEquals(count, deleted); } } } }
Example 6
Source File: GeoPackageGeometryDataUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test transforming geometries between projections * * @param geoPackage * @throws SQLException * @throws IOException */ public static void testGeometryProjectionTransform(GeoPackage geoPackage) throws SQLException, IOException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); TestCase.assertNotNull(dao); FeatureCursor cursor = dao.queryForAll(); while (cursor.moveToNext()) { GeoPackageGeometryData geometryData = cursor.getGeometry(); if (geometryData != null) { Geometry geometry = geometryData.getGeometry(); if (geometry != null) { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = geometryData.getSrsId(); SpatialReferenceSystem srs = srsDao .queryForId(srsId); long epsg = srs.getOrganizationCoordsysId(); Projection projection = srs.getProjection(); long toEpsg = -1; if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) { toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; } else { toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM; } ProjectionTransform transformTo = projection .getTransformation(toEpsg); ProjectionTransform transformFrom = srs.getTransformation(transformTo .getToProjection()); byte[] bytes = geometryData.getWkbBytes(); Geometry projectedGeometry = transformTo .transform(geometry); GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData( -1); projectedGeometryData .setGeometry(projectedGeometry); projectedGeometryData.toBytes(); byte[] projectedBytes = projectedGeometryData .getWkbBytes(); if (epsg > 0) { TestCase.assertFalse(equalByteArrays(bytes, projectedBytes)); } Geometry restoredGeometry = transformFrom .transform(projectedGeometry); compareGeometries(geometry, restoredGeometry, .001); } } } cursor.close(); } } }
Example 7
Source File: FeatureUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test update * * @param geoPackage * GeoPackage * @throws SQLException * upon error */ public static void testUpdate(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); testUpdate(dao); } } }
Example 8
Source File: GeometryColumnsUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test delete * * @param geoPackage * @throws SQLException */ public static void testDelete(GeoPackage geoPackage) throws SQLException { GeometryColumnsDao dao = geoPackage.getGeometryColumnsDao(); if (dao.isTableExists()) { List<GeometryColumns> results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random geometry columns int random = (int) (Math.random() * results.size()); GeometryColumns geometryColumns = results.get(random); // Delete the geometry columns dao.delete(geometryColumns); // Verify deleted GeometryColumns queryGeometryColumns = dao .queryForId(geometryColumns.getId()); TestCase.assertNull(queryGeometryColumns); // Prepared deleted results = dao.queryForAll(); if (!results.isEmpty()) { // Choose random geometry columns random = (int) (Math.random() * results.size()); geometryColumns = results.get(random); // Find which geometry columns to delete QueryBuilder<GeometryColumns, TableColumnKey> qb = dao .queryBuilder(); qb.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME, geometryColumns.getGeometryType().getName()); PreparedQuery<GeometryColumns> query = qb.prepare(); List<GeometryColumns> queryResults = dao.query(query); int count = queryResults.size(); // Delete DeleteBuilder<GeometryColumns, TableColumnKey> db = dao .deleteBuilder(); db.where().eq(GeometryColumns.COLUMN_GEOMETRY_TYPE_NAME, geometryColumns.getGeometryType().getName()); PreparedDelete<GeometryColumns> deleteQuery = db.prepare(); int deleted = dao.delete(deleteQuery); TestCase.assertEquals(count, deleted); } } } }
Example 9
Source File: GeoPackageGeometryDataUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test transforming geometries between projections * * @param geoPackage * @throws SQLException * @throws IOException */ public static void testGeometryProjectionTransform(GeoPackage geoPackage) throws SQLException, IOException { GeometryColumnsDao geometryColumnsDao = geoPackage .getGeometryColumnsDao(); if (geometryColumnsDao.isTableExists()) { List<GeometryColumns> results = geometryColumnsDao.queryForAll(); for (GeometryColumns geometryColumns : results) { FeatureDao dao = geoPackage.getFeatureDao(geometryColumns); TestCase.assertNotNull(dao); FeatureResultSet cursor = dao.queryForAll(); while (cursor.moveToNext()) { GeoPackageGeometryData geometryData = cursor.getGeometry(); if (geometryData != null) { Geometry geometry = geometryData.getGeometry(); if (geometry != null) { SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = geometryData.getSrsId(); SpatialReferenceSystem srs = srsDao .queryForId(srsId); long epsg = srs.getOrganizationCoordsysId(); Projection projection = srs.getProjection(); long toEpsg = -1; if (epsg == ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM) { toEpsg = ProjectionConstants.EPSG_WEB_MERCATOR; } else { toEpsg = ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM; } ProjectionTransform transformTo = projection .getTransformation(toEpsg); ProjectionTransform transformFrom = srs .getTransformation(transformTo .getToProjection()); byte[] bytes = geometryData.getWkbBytes(); Geometry projectedGeometry = transformTo .transform(geometry); GeoPackageGeometryData projectedGeometryData = new GeoPackageGeometryData( -1); projectedGeometryData .setGeometry(projectedGeometry); projectedGeometryData.toBytes(); byte[] projectedBytes = projectedGeometryData .getWkbBytes(); if (epsg > 0) { TestCase.assertFalse(equalByteArrays(bytes, projectedBytes)); } Geometry restoredGeometry = transformFrom .transform(projectedGeometry); compareGeometries(geometry, restoredGeometry, .001); } } } cursor.close(); } } }