Java Code Examples for mil.nga.geopackage.core.srs.SpatialReferenceSystemDao#queryForId()
The following examples show how to use
mil.nga.geopackage.core.srs.SpatialReferenceSystemDao#queryForId() .
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: FeatureInfoBuilder.java From geopackage-android-map with MIT License | 5 votes |
/** * Project the geometry into the provided projection * * @param geometryData geometry data * @param projection projection */ public void projectGeometry(GeoPackageGeometryData geometryData, Projection projection) { if (geometryData.getGeometry() != null) { try { SpatialReferenceSystemDao srsDao = DaoManager.createDao(featureDao.getDb().getConnectionSource(), SpatialReferenceSystem.class); int srsId = geometryData.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId((long) srsId); if (!projection.equals(srs.getOrganization(), srs.getOrganizationCoordsysId())) { Projection geomProjection = srs.getProjection(); ProjectionTransform transform = geomProjection.getTransformation(projection); Geometry projectedGeometry = transform.transform(geometryData.getGeometry()); geometryData.setGeometry(projectedGeometry); SpatialReferenceSystem projectionSrs = srsDao.getOrCreateCode(projection.getAuthority(), Long.parseLong(projection.getCode())); geometryData.setSrsId((int) projectionSrs.getSrsId()); } } catch (SQLException e) { throw new GeoPackageException("Failed to project geometry to projection with Authority: " + projection.getAuthority() + ", Code: " + projection.getCode(), e); } } }
Example 2
Source File: TestSetupTeardown.java From geopackage-android-map with MIT License | 4 votes |
/** * Set up create for tiles test * * @param testContext * @param geoPackage * @throws SQLException * @throws IOException */ private static void setUpCreateTiles(Context testContext, GeoPackage geoPackage) throws SQLException, IOException { // Get existing SRS objects SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l); TestCase.assertNotNull(epsgSrs); // Create the Tile Matrix Set and Tile Matrix tables geoPackage.createTileMatrixSetTable(); geoPackage.createTileMatrixTable(); // Create new Contents ContentsDao contentsDao = geoPackage.getContentsDao(); Contents contents = new Contents(); contents.setTableName("test_tiles"); contents.setDataType(ContentsDataType.TILES); contents.setIdentifier("test_tiles"); // contents.setDescription(""); // contents.setLastChange(new Date()); contents.setMinX(-180.0); contents.setMinY(-90.0); contents.setMaxX(180.0); contents.setMaxY(90.0); contents.setSrs(epsgSrs); // Create the user tile table TileTable tileTable = TestUtils.buildTileTable(contents.getTableName()); geoPackage.createTileTable(tileTable); // Create the contents contentsDao.create(contents); // Create new Tile Matrix Set TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao(); TileMatrixSet tileMatrixSet = new TileMatrixSet(); tileMatrixSet.setContents(contents); tileMatrixSet.setSrs(contents.getSrs()); tileMatrixSet.setMinX(contents.getMinX()); tileMatrixSet.setMinY(contents.getMinY()); tileMatrixSet.setMaxX(contents.getMaxX()); tileMatrixSet.setMaxY(contents.getMaxY()); tileMatrixSetDao.create(tileMatrixSet); // Create new Tile Matrix rows TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); int matrixWidthAndHeight = 2; double pixelXSize = 69237.2; double pixelYSize = 68412.1; // Read the asset tile to bytes and convert to bitmap byte[] assetTileData = TestUtils.getAssetFileBytes(testContext, TestConstants.TILE_FILE_NAME); Bitmap bitmap = BitmapConverter.toBitmap(assetTileData); // Get the width and height of the bitmap final int tileWidth = bitmap.getWidth(); final int tileHeight = bitmap.getHeight(); // Compress the bitmap back to bytes and use those for the test byte[] tileData = BitmapConverter.toBytes(bitmap, CompressFormat .valueOf(TestConstants.TILE_FILE_NAME_EXTENSION.toUpperCase())); for (int zoom = 0; zoom < CREATE_TILE_MATRIX_COUNT; zoom++) { TileMatrix tileMatrix = new TileMatrix(); tileMatrix.setContents(contents); tileMatrix.setZoomLevel(zoom); tileMatrix.setMatrixWidth(matrixWidthAndHeight); tileMatrix.setMatrixHeight(matrixWidthAndHeight); tileMatrix.setTileWidth(tileWidth); tileMatrix.setTileHeight(tileHeight); tileMatrix.setPixelXSize(pixelXSize); tileMatrix.setPixelYSize(pixelYSize); tileMatrixDao.create(tileMatrix); matrixWidthAndHeight *= 2; pixelXSize /= 2.0; pixelYSize /= 2.0; // Populate the tile table with rows TestUtils.addRowsToTileTable(geoPackage, tileMatrix, tileData); } }
Example 3
Source File: CoverageDataPngImportTest.java From geopackage-android with MIT License | 4 votes |
/** * Test 10 random locations and optionally print * * @throws Exception */ @Test public void testRandomLocations() throws Exception { BoundingBox projectedBoundingBox = null; List<String> coverageDataTables = CoverageDataPng.getTables(geoPackage); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable); BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); if (PRINT) { System.out.println("Min Latitude: " + boundingBox.getMinLatitude()); System.out.println("Max Latitude: " + boundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + boundingBox.getMinLongitude()); System.out.println("Max Longitude: " + boundingBox.getMaxLongitude()); System.out.println(); } SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = tileMatrixSet.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId(srsId); Projection projection = srs.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); ProjectionTransform coverageToRequest = projection .getTransformation(requestProjection); projectedBoundingBox = boundingBox.transform(coverageToRequest); } if (PRINT) { System.out.println("Min Latitude: " + projectedBoundingBox.getMinLatitude()); System.out.println("Max Latitude: " + projectedBoundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + projectedBoundingBox.getMinLongitude()); System.out.println("Max Longitude: " + projectedBoundingBox.getMaxLongitude()); System.out.println(); } double latDistance = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); double lonDistance = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); for (int i = 0; i < 10; i++) { // Get a random coordinate double latitude = latDistance * .9 * Math.random() + projectedBoundingBox.getMinLatitude() + (.05 * latDistance); double longitude = lonDistance * .9 * Math.random() + projectedBoundingBox.getMinLongitude() + (.05 * lonDistance); testLocation(latitude, longitude); if (PRINT) { System.out.println(); } } }
Example 4
Source File: CoverageDataTiffImportTest.java From geopackage-android with MIT License | 4 votes |
/** * Test 10 random locations and optionally print * * @throws Exception */ @Test public void testRandomLocations() throws Exception { BoundingBox projectedBoundingBox = null; List<String> coverageDataTables = CoverageDataTiff.getTables(geoPackage); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable); BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); if (PRINT) { System.out.println("Min Latitude: " + boundingBox.getMinLatitude()); System.out.println("Max Latitude: " + boundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + boundingBox.getMinLongitude()); System.out.println("Max Longitude: " + boundingBox.getMaxLongitude()); System.out.println(); } SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = tileMatrixSet.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId(srsId); Projection projection = srs.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); ProjectionTransform coverageToRequest = projection .getTransformation(requestProjection); projectedBoundingBox = boundingBox.transform(coverageToRequest); } if (PRINT) { System.out.println("Min Latitude: " + projectedBoundingBox.getMinLatitude()); System.out.println("Max Latitude: " + projectedBoundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + projectedBoundingBox.getMinLongitude()); System.out.println("Max Longitude: " + projectedBoundingBox.getMaxLongitude()); System.out.println(); } double latDistance = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); double lonDistance = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); for (int i = 0; i < 10; i++) { // Get a random coordinate double latitude = latDistance * .9 * Math.random() + projectedBoundingBox.getMinLatitude() + (.05 * latDistance); double longitude = lonDistance * .9 * Math.random() + projectedBoundingBox.getMinLongitude() + (.05 * lonDistance); testLocation(latitude, longitude); if (PRINT) { System.out.println(); } } }
Example 5
Source File: TestSetupTeardown.java From geopackage-android with MIT License | 4 votes |
/** * Set up create for tiles test * * @param testContext * @param geoPackage * @throws SQLException * @throws IOException */ private static void setUpCreateTiles(Context testContext, GeoPackage geoPackage) throws SQLException, IOException { // Get existing SRS objects SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l); TestCase.assertNotNull(epsgSrs); // Create the Tile Matrix Set and Tile Matrix tables geoPackage.createTileMatrixSetTable(); geoPackage.createTileMatrixTable(); // Create new Contents ContentsDao contentsDao = geoPackage.getContentsDao(); Contents contents = new Contents(); contents.setTableName("test_tiles"); contents.setDataType(ContentsDataType.TILES); contents.setIdentifier("test_tiles"); // contents.setDescription(""); // contents.setLastChange(new Date()); contents.setMinX(-180.0); contents.setMinY(-90.0); contents.setMaxX(180.0); contents.setMaxY(90.0); contents.setSrs(epsgSrs); // Create the user tile table TileTable tileTable = TestUtils.buildTileTable(contents.getTableName()); geoPackage.createTileTable(tileTable); // Create the contents contentsDao.create(contents); // Create new Tile Matrix Set TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao(); TileMatrixSet tileMatrixSet = new TileMatrixSet(); tileMatrixSet.setContents(contents); tileMatrixSet.setSrs(contents.getSrs()); tileMatrixSet.setMinX(contents.getMinX()); tileMatrixSet.setMinY(contents.getMinY()); tileMatrixSet.setMaxX(contents.getMaxX()); tileMatrixSet.setMaxY(contents.getMaxY()); tileMatrixSetDao.create(tileMatrixSet); // Create new Tile Matrix rows TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); // Read the asset tile to bytes and convert to bitmap byte[] assetTileData = TestUtils.getAssetFileBytes(testContext, TestConstants.TILE_FILE_NAME); Bitmap bitmap = BitmapConverter.toBitmap(assetTileData); // Get the width and height of the bitmap final int tileWidth = bitmap.getWidth(); final int tileHeight = bitmap.getHeight(); int matrixWidthAndHeight = 2; double pixelXSize = (tileMatrixSet.getMaxX() - tileMatrixSet.getMinX()) / (matrixWidthAndHeight * tileWidth); double pixelYSize = (tileMatrixSet.getMaxY() - tileMatrixSet.getMinY()) / (matrixWidthAndHeight * tileHeight); // Compress the bitmap back to bytes and use those for the test byte[] tileData = BitmapConverter.toBytes(bitmap, CompressFormat .valueOf(TestConstants.TILE_FILE_NAME_EXTENSION.toUpperCase())); for (int zoom = 0; zoom < CREATE_TILE_MATRIX_COUNT; zoom++) { TileMatrix tileMatrix = new TileMatrix(); tileMatrix.setContents(contents); tileMatrix.setZoomLevel(zoom); tileMatrix.setMatrixWidth(matrixWidthAndHeight); tileMatrix.setMatrixHeight(matrixWidthAndHeight); tileMatrix.setTileWidth(tileWidth); tileMatrix.setTileHeight(tileHeight); tileMatrix.setPixelXSize(pixelXSize); tileMatrix.setPixelYSize(pixelYSize); tileMatrixDao.create(tileMatrix); matrixWidthAndHeight *= 2; pixelXSize /= 2.0; pixelYSize /= 2.0; // Populate the tile table with rows TestUtils.addRowsToTileTable(geoPackage, tileMatrix, tileData); } }
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: SpatialReferenceSystemUtils.java From geopackage-android with MIT License | 4 votes |
/** * Test create * * @param geoPackage * @throws SQLException */ public static void testCreate(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao dao = geoPackage .getSpatialReferenceSystemDao(); // Get current count long count = dao.countOf(); String srsName = "TEST_SRS_NAME"; long srsId = 123456l; String organization = "TEST_ORG"; int organizationCoordSysId = 123456; String definition = "TEST_DEFINITION"; String description = "TEST_DESCRIPTION"; // Create new srs SpatialReferenceSystem srs = new SpatialReferenceSystem(); srs.setSrsName(srsName); srs.setSrsId(srsId); srs.setOrganization(organization); srs.setOrganizationCoordsysId(organizationCoordSysId); srs.setDefinition(definition); srs.setDescription(description); dao.create(srs); // Verify count long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); // Verify saved srs SpatialReferenceSystem querySrs = dao.queryForId(srsId); TestCase.assertEquals(srsName, querySrs.getSrsName()); TestCase.assertEquals(srsId, querySrs.getSrsId()); TestCase.assertEquals(organization, querySrs.getOrganization()); TestCase.assertEquals(organizationCoordSysId, querySrs.getOrganizationCoordsysId()); TestCase.assertEquals(definition, querySrs.getDefinition()); TestCase.assertEquals(description, querySrs.getDescription()); // Test copied srs SpatialReferenceSystem copySrs = new SpatialReferenceSystem(querySrs); TestCase.assertEquals(querySrs.getSrsName(), copySrs.getSrsName()); TestCase.assertEquals(querySrs.getId(), copySrs.getId()); TestCase.assertEquals(querySrs.getOrganization(), copySrs.getOrganization()); TestCase.assertEquals(querySrs.getOrganizationCoordsysId(), copySrs.getOrganizationCoordsysId()); TestCase.assertEquals(querySrs.getDefinition(), copySrs.getDefinition()); TestCase.assertEquals(querySrs.getDescription(), copySrs.getDescription()); TestCase.assertEquals(querySrs.getDefinition_12_063(), copySrs.getDefinition_12_063()); // Change pk long copySrsId = 654321l; copySrs.setSrsId(copySrsId); dao.create(copySrs); // Verify count long newCount2 = dao.countOf(); TestCase.assertEquals(count + 2, newCount2); // Verify saved contents SpatialReferenceSystem queryCopiedSrs = dao.queryForId(copySrsId); TestCase.assertEquals(querySrs.getSrsName(), queryCopiedSrs.getSrsName()); TestCase.assertEquals(copySrsId, queryCopiedSrs.getSrsId()); TestCase.assertEquals(querySrs.getOrganization(), queryCopiedSrs.getOrganization()); TestCase.assertEquals(querySrs.getOrganizationCoordsysId(), queryCopiedSrs.getOrganizationCoordsysId()); TestCase.assertEquals(querySrs.getDefinition(), queryCopiedSrs.getDefinition()); TestCase.assertEquals(querySrs.getDescription(), queryCopiedSrs.getDescription()); }
Example 8
Source File: CoverageDataPngImportTest.java From geopackage-java with MIT License | 4 votes |
/** * Test 10 random locations and optionally print * * @throws Exception */ @Test public void testRandomLocations() throws Exception { BoundingBox projectedBoundingBox = null; List<String> coverageDataTables = CoverageDataPng.getTables(geoPackage); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable); BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); if (PRINT) { System.out.println("Min Latitude: " + boundingBox.getMinLatitude()); System.out.println("Max Latitude: " + boundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + boundingBox.getMinLongitude()); System.out.println("Max Longitude: " + boundingBox.getMaxLongitude()); System.out.println(); } SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = tileMatrixSet.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId(srsId); Projection projection = srs.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); ProjectionTransform coverageToRequest = projection .getTransformation(requestProjection); projectedBoundingBox = boundingBox.transform(coverageToRequest); } if (PRINT) { System.out.println("Min Latitude: " + projectedBoundingBox.getMinLatitude()); System.out.println("Max Latitude: " + projectedBoundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + projectedBoundingBox.getMinLongitude()); System.out.println("Max Longitude: " + projectedBoundingBox.getMaxLongitude()); System.out.println(); } double latDistance = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); double lonDistance = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); for (int i = 0; i < 10; i++) { // Get a random coordinate double latitude = latDistance * .9 * Math.random() + projectedBoundingBox.getMinLatitude() + (.05 * latDistance); double longitude = lonDistance * .9 * Math.random() + projectedBoundingBox.getMinLongitude() + (.05 * lonDistance); testLocation(latitude, longitude); if (PRINT) { System.out.println(); } } }
Example 9
Source File: CoverageDataTiffImportTest.java From geopackage-java with MIT License | 4 votes |
/** * Test 10 random locations and optionally print * * @throws Exception */ @Test public void testRandomLocations() throws Exception { BoundingBox projectedBoundingBox = null; List<String> coverageDataTables = CoverageDataTiff .getTables(geoPackage); TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao(); for (String coverageTable : coverageDataTables) { TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable); BoundingBox boundingBox = tileMatrixSet.getBoundingBox(); if (PRINT) { System.out.println("Min Latitude: " + boundingBox.getMinLatitude()); System.out.println("Max Latitude: " + boundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + boundingBox.getMinLongitude()); System.out.println("Max Longitude: " + boundingBox.getMaxLongitude()); System.out.println(); } SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); long srsId = tileMatrixSet.getSrsId(); SpatialReferenceSystem srs = srsDao.queryForId(srsId); Projection projection = srs.getProjection(); Projection requestProjection = ProjectionFactory .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM); ProjectionTransform coverageToRequest = projection .getTransformation(requestProjection); projectedBoundingBox = boundingBox.transform(coverageToRequest); } if (PRINT) { System.out.println("Min Latitude: " + projectedBoundingBox.getMinLatitude()); System.out.println("Max Latitude: " + projectedBoundingBox.getMaxLatitude()); System.out.println("Min Longitude: " + projectedBoundingBox.getMinLongitude()); System.out.println("Max Longitude: " + projectedBoundingBox.getMaxLongitude()); System.out.println(); } double latDistance = projectedBoundingBox.getMaxLatitude() - projectedBoundingBox.getMinLatitude(); double lonDistance = projectedBoundingBox.getMaxLongitude() - projectedBoundingBox.getMinLongitude(); for (int i = 0; i < 10; i++) { // Get a random coordinate double latitude = latDistance * .9 * Math.random() + projectedBoundingBox.getMinLatitude() + (.05 * latDistance); double longitude = lonDistance * .9 * Math.random() + projectedBoundingBox.getMinLongitude() + (.05 * lonDistance); testLocation(latitude, longitude); if (PRINT) { System.out.println(); } } }
Example 10
Source File: TestSetupTeardown.java From geopackage-java with MIT License | 4 votes |
/** * Set up create for tiles test * * @param geoPackage * @throws SQLException * @throws IOException */ private static void setUpCreateTiles(GeoPackage geoPackage) throws SQLException, IOException { // Get existing SRS objects SpatialReferenceSystemDao srsDao = geoPackage .getSpatialReferenceSystemDao(); SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l); TestCase.assertNotNull(epsgSrs); // Create the Tile Matrix Set and Tile Matrix tables geoPackage.createTileMatrixSetTable(); geoPackage.createTileMatrixTable(); // Create new Contents ContentsDao contentsDao = geoPackage.getContentsDao(); Contents contents = new Contents(); contents.setTableName("test_tiles"); contents.setDataType(ContentsDataType.TILES); contents.setIdentifier("test_tiles"); // contents.setDescription(""); // contents.setLastChange(new Date()); contents.setMinX(-180.0); contents.setMinY(-90.0); contents.setMaxX(180.0); contents.setMaxY(90.0); contents.setSrs(epsgSrs); // Create the user tile table TileTable tileTable = TestUtils.buildTileTable(contents.getTableName()); geoPackage.createTileTable(tileTable); // Create the contents contentsDao.create(contents); // Create new Tile Matrix Set TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao(); TileMatrixSet tileMatrixSet = new TileMatrixSet(); tileMatrixSet.setContents(contents); tileMatrixSet.setSrs(contents.getSrs()); tileMatrixSet.setMinX(contents.getMinX()); tileMatrixSet.setMinY(contents.getMinY()); tileMatrixSet.setMaxX(contents.getMaxX()); tileMatrixSet.setMaxY(contents.getMaxY()); tileMatrixSetDao.create(tileMatrixSet); // Create new Tile Matrix rows TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao(); final int tileWidth = 256; final int tileHeight = 256; int matrixWidthAndHeight = 2; double pixelXSize = (tileMatrixSet.getMaxX() - tileMatrixSet.getMinX()) / (matrixWidthAndHeight * tileWidth); double pixelYSize = (tileMatrixSet.getMaxY() - tileMatrixSet.getMinY()) / (matrixWidthAndHeight * tileHeight); byte[] tileData = TestUtils.getTileBytes(); for (int zoom = 0; zoom < CREATE_TILE_MATRIX_COUNT; zoom++) { TileMatrix tileMatrix = new TileMatrix(); tileMatrix.setContents(contents); tileMatrix.setZoomLevel(zoom); tileMatrix.setMatrixWidth(matrixWidthAndHeight); tileMatrix.setMatrixHeight(matrixWidthAndHeight); tileMatrix.setTileWidth(tileWidth); tileMatrix.setTileHeight(tileHeight); tileMatrix.setPixelXSize(pixelXSize); tileMatrix.setPixelYSize(pixelYSize); tileMatrixDao.create(tileMatrix); matrixWidthAndHeight *= 2; pixelXSize /= 2.0; pixelYSize /= 2.0; // Populate the tile table with rows TestUtils.addRowsToTileTable(geoPackage, tileMatrix, tileData); } }
Example 11
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(); } } }
Example 12
Source File: SpatialReferenceSystemUtils.java From geopackage-java with MIT License | 4 votes |
/** * Test create * * @param geoPackage * @throws SQLException */ public static void testCreate(GeoPackage geoPackage) throws SQLException { SpatialReferenceSystemDao dao = geoPackage .getSpatialReferenceSystemDao(); // Get current count long count = dao.countOf(); String srsName = "TEST_SRS_NAME"; long srsId = 123456l; String organization = "TEST_ORG"; int organizationCoordSysId = 123456; String definition = "TEST_DEFINITION"; String description = "TEST_DESCRIPTION"; // Create new srs SpatialReferenceSystem srs = new SpatialReferenceSystem(); srs.setSrsName(srsName); srs.setSrsId(srsId); srs.setOrganization(organization); srs.setOrganizationCoordsysId(organizationCoordSysId); srs.setDefinition(definition); srs.setDescription(description); dao.create(srs); // Verify count long newCount = dao.countOf(); TestCase.assertEquals(count + 1, newCount); // Verify saved srs SpatialReferenceSystem querySrs = dao.queryForId(srsId); TestCase.assertEquals(srsName, querySrs.getSrsName()); TestCase.assertEquals(srsId, querySrs.getSrsId()); TestCase.assertEquals(organization, querySrs.getOrganization()); TestCase.assertEquals(organizationCoordSysId, querySrs.getOrganizationCoordsysId()); TestCase.assertEquals(definition, querySrs.getDefinition()); TestCase.assertEquals(description, querySrs.getDescription()); // Test copied srs SpatialReferenceSystem copySrs = new SpatialReferenceSystem(querySrs); TestCase.assertEquals(querySrs.getSrsName(), copySrs.getSrsName()); TestCase.assertEquals(querySrs.getId(), copySrs.getId()); TestCase.assertEquals(querySrs.getOrganization(), copySrs.getOrganization()); TestCase.assertEquals(querySrs.getOrganizationCoordsysId(), copySrs.getOrganizationCoordsysId()); TestCase.assertEquals(querySrs.getDefinition(), copySrs.getDefinition()); TestCase.assertEquals(querySrs.getDescription(), copySrs.getDescription()); TestCase.assertEquals(querySrs.getDefinition_12_063(), copySrs.getDefinition_12_063()); // Change pk long copySrsId = 654321l; copySrs.setSrsId(copySrsId); dao.create(copySrs); // Verify count long newCount2 = dao.countOf(); TestCase.assertEquals(count + 2, newCount2); // Verify saved contents SpatialReferenceSystem queryCopiedSrs = dao.queryForId(copySrsId); TestCase.assertEquals(querySrs.getSrsName(), queryCopiedSrs.getSrsName()); TestCase.assertEquals(copySrsId, queryCopiedSrs.getSrsId()); TestCase.assertEquals(querySrs.getOrganization(), queryCopiedSrs.getOrganization()); TestCase.assertEquals(querySrs.getOrganizationCoordsysId(), queryCopiedSrs.getOrganizationCoordsysId()); TestCase.assertEquals(querySrs.getDefinition(), queryCopiedSrs.getDefinition()); TestCase.assertEquals(querySrs.getDescription(), queryCopiedSrs.getDescription()); }