Java Code Examples for mil.nga.geopackage.GeoPackage#getTileDao()

The following examples show how to use mil.nga.geopackage.GeoPackage#getTileDao() . 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: GeoPackageMapTileModuleProvider.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
/**
 * returns ALL available raster tile sources for all "imported" geopackage databases
 *
 * @return
 */
public List<GeopackageRasterTileSource> getTileSources() {
    List<GeopackageRasterTileSource> srcs = new ArrayList<>();

    List<String> databases = manager.databases();
    for (int i = 0; i < databases.size(); i++) {

        GeoPackage open = manager.open(databases.get(i));
        List<String> tileTables = open.getTileTables();
        for (int k = 0; k < tileTables.size(); k++) {
            TileDao tileDao = open.getTileDao(tileTables.get(k));

            ProjectionTransform transform = tileDao.getProjection().getTransformation(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
            mil.nga.geopackage.BoundingBox boundingBox = transform.transform(tileDao.getBoundingBox());
            BoundingBox bounds = new BoundingBox(Math.min(tileSystem.getMaxLatitude(), boundingBox.getMaxLatitude()),
                boundingBox.getMaxLongitude(),
                Math.max(tileSystem.getMinLatitude(), boundingBox.getMinLatitude()),
                boundingBox.getMinLongitude());

            srcs.add(new GeopackageRasterTileSource(databases.get(i), tileTables.get(k), (int)tileDao.getMinZoom(), (int)tileDao.getMaxZoom(), bounds));
        }
        open.close();
    }

    return srcs;
}
 
Example 2
Source File: CoverageDataTestUtils.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Get the coverage data value at the coordinate
 *
 * @param geoPackage GeoPackage
 * @param algorithm  algorithm
 * @param latitude   latitude
 * @param longitude  longitude
 * @param epsg       epsg
 * @return coverage data value
 * @throws Exception
 */
public static Double getValue(GeoPackage geoPackage,
                              CoverageDataAlgorithm algorithm, double latitude,
                              double longitude, long epsg) throws Exception {

    Double value = null;

    List<String> coverageDataTables = CoverageData.getTables(geoPackage);
    TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

    for (String coverageTable : coverageDataTables) {

        TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);
        TileDao tileDao = geoPackage.getTileDao(tileMatrixSet);

        Projection requestProjection = ProjectionFactory
                .getProjection(epsg);

        // Test getting the coverage data value of a single coordinate
        CoverageData<?> coverageData = CoverageData.getCoverageData(geoPackage, tileDao, requestProjection);
        coverageData.setAlgorithm(algorithm);
        value = coverageData.getValue(latitude, longitude);
    }

    return value;
}
 
Example 3
Source File: GeoPackageProvider.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
public GeopackageRasterTileSource getTileSource(String database, String table) {
    Iterator<GeoPackage> iterator = geopackage.tileSources.iterator();
    while (iterator.hasNext()){
        GeoPackage next = iterator.next();
        if (next.getName().equalsIgnoreCase(database)) {
            //found the database
            if (next.getTileTables().contains(table)) {
                //find the tile table
                TileDao tileDao = next.getTileDao(table);
                mil.nga.geopackage.BoundingBox boundingBox = tileDao.getBoundingBox();
                ProjectionTransform transformation = tileDao.getProjection().getTransformation(tileDao.getProjection());
                boundingBox=transformation.transform(boundingBox);
                BoundingBox bounds =new BoundingBox(boundingBox.getMaxLatitude(),boundingBox.getMaxLongitude(),boundingBox.getMinLatitude(),boundingBox.getMinLongitude());
                return new GeopackageRasterTileSource(database,table, (int)tileDao.getMinZoom(),(int)tileDao.getMaxZoom(), bounds);
            }
        }
    }

    return null;
}
 
Example 4
Source File: CoverageDataTestUtils.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the coverage data for the bounding box
 *
 * @param geoPackage  GeoPackage
 * @param algorithm   algorithm
 * @param boundingBox bounding box
 * @param width       results width
 * @param height      results height
 * @param epsg        epsg code
 * @return coverage data results
 * @throws Exception
 */
public static CoverageDataResults getValues(GeoPackage geoPackage,
                                            CoverageDataAlgorithm algorithm, BoundingBox boundingBox,
                                            int width, int height, long epsg) throws Exception {

    CoverageDataResults values = null;

    List<String> coverageDataTables = CoverageData.getTables(geoPackage);
    TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

    for (String coverageTable : coverageDataTables) {

        TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);
        TileDao tileDao = geoPackage.getTileDao(tileMatrixSet);

        Projection requestProjection = ProjectionFactory
                .getProjection(epsg);

        // Test getting the coverage data value of a single coordinate
        CoverageData<?> coverageData = CoverageData.getCoverageData(geoPackage, tileDao, requestProjection);
        coverageData.setAlgorithm(algorithm);
        coverageData.setWidth(width);
        coverageData.setHeight(height);
        values = coverageData.getValues(boundingBox);
    }

    return values;
}
 
Example 5
Source File: CoverageDataTestUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the coverage data value at the coordinate
 * 
 * @param geoPackage
 *            GeoPackage
 * @param algorithm
 *            algorithm
 * @param latitude
 *            latitude
 * @param longitude
 *            longitude
 * @param epsg
 *            epsg
 * @return coverage data value
 * @throws Exception
 */
public static Double getValue(GeoPackage geoPackage,
		CoverageDataAlgorithm algorithm, double latitude, double longitude,
		long epsg) throws Exception {

	Double value = null;

	List<String> coverageDataTables = CoverageData.getTables(geoPackage);
	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

	for (String coverageTable : coverageDataTables) {

		TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);
		TileDao tileDao = geoPackage.getTileDao(tileMatrixSet);

		Projection requestProjection = ProjectionFactory
				.getProjection(epsg);

		// Test getting the coverage data value of a single coordinate
		CoverageData<?> coverageData = CoverageData.getCoverageData(
				geoPackage, tileDao, requestProjection);
		coverageData.setAlgorithm(algorithm);
		value = coverageData.getValue(latitude, longitude);
	}

	return value;
}
 
Example 6
Source File: CoverageData.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Create the coverage data tile table with metadata and extension
 * 
 * @param geoPackage
 *            GeoPackage
 * @param tableName
 *            table name
 * @param contentsBoundingBox
 *            contents bounding box
 * @param contentsSrsId
 *            contents srs id
 * @param tileMatrixSetBoundingBox
 *            tile matrix set bounding box
 * @param tileMatrixSetSrsId
 *            tile matrix set srs id
 * @param dataType
 *            gridded coverage data type
 * @return coverage data
 */
public static CoverageData<?> createTileTableWithMetadata(
		GeoPackage geoPackage, String tableName,
		BoundingBox contentsBoundingBox, long contentsSrsId,
		BoundingBox tileMatrixSetBoundingBox, long tileMatrixSetSrsId,
		GriddedCoverageDataType dataType) {

	TileMatrixSet tileMatrixSet = CoverageDataCore
			.createTileTableWithMetadata(geoPackage, tableName,
					contentsBoundingBox, contentsSrsId,
					tileMatrixSetBoundingBox, tileMatrixSetSrsId);
	TileDao tileDao = geoPackage.getTileDao(tileMatrixSet);

	CoverageData<?> coverageData = null;
	switch (dataType) {
	case INTEGER:
		coverageData = new CoverageDataPng(geoPackage, tileDao);
		break;
	case FLOAT:
		coverageData = new CoverageDataTiff(geoPackage, tileDao);
		break;
	default:
		throw new GeoPackageException(
				"Unsupported Gridded Coverage Data Type: " + dataType);
	}

	coverageData.getOrCreate();

	return coverageData;
}
 
Example 7
Source File: TileUtils.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Test delete
 * 
 * @param geoPackage
 *            GeoPackage
 * @throws SQLException
 *             upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

	if (tileMatrixSetDao.isTableExists()) {
		List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();

		for (TileMatrixSet tileMatrixSet : results) {

			TileDao dao = geoPackage.getTileDao(tileMatrixSet);
			TestCase.assertNotNull(dao);

			TileResultSet cursor = dao.queryForAll();
			int count = cursor.getCount();
			if (count > 0) {

				// Choose random tile
				int random = (int) (Math.random() * count);
				cursor.moveToPosition(random);

				TileRow tileRow = cursor.getRow();
				cursor.close();

				// Delete row
				TestCase.assertEquals(1, dao.delete(tileRow));

				// Verify deleted
				TileRow queryTileRow = dao.queryForIdRow(tileRow.getId());
				TestCase.assertNull(queryTileRow);
				cursor = dao.queryForAll();
				TestCase.assertEquals(count - 1, cursor.getCount());
				cursor.close();
			}
			cursor.close();
		}

	}
}
 
Example 8
Source File: TileUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test delete
 *
 * @param geoPackage GeoPackage
 * @throws SQLException upon error
 */
public static void testDelete(GeoPackage geoPackage) throws SQLException {

    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

    if (tileMatrixSetDao.isTableExists()) {
        List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();

        for (TileMatrixSet tileMatrixSet : results) {

            TileDao dao = geoPackage.getTileDao(tileMatrixSet);
            TestCase.assertNotNull(dao);

            TileCursor cursor = dao.queryForAll();
            int count = cursor.getCount();
            if (count > 0) {

                // Choose random tile
                int random = (int) (Math.random() * count);
                cursor.moveToPosition(random);

                TileRow tileRow = cursor.getRow();
                cursor.close();

                // Delete row
                try {
                    TestCase.assertEquals(1, dao.delete(tileRow));
                } catch (SQLiteException e) {
                    if (TestUtils.isFutureSQLiteException(e)) {
                        continue;
                    } else {
                        throw e;
                    }
                }

                // Verify deleted
                TileRow queryTileRow = dao.queryForIdRow(tileRow.getId());
                TestCase.assertNull(queryTileRow);
                cursor = dao.queryForAll();
                TestCase.assertEquals(count - 1, cursor.getCount());
                cursor.close();
            }
            cursor.close();
        }

    }
}
 
Example 9
Source File: TileUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test update
 * 
 * @param geoPackage
 *            GeoPackage
 * @throws SQLException
 *             upon error
 * @throws IOException
 *             upon error
 */
public static void testUpdate(GeoPackage geoPackage) throws SQLException,
		IOException {

	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

	if (tileMatrixSetDao.isTableExists()) {
		List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();

		for (TileMatrixSet tileMatrixSet : results) {

			TileDao dao = geoPackage.getTileDao(tileMatrixSet);
			testUpdate(dao);

		}
	}

}
 
Example 10
Source File: TestUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Add rows to the tile table
 *
 * @param geoPackage
 * @param tileMatrix
 * @param tileData
 */
public static void addRowsToTileTable(GeoPackage geoPackage,
		TileMatrix tileMatrix, byte[] tileData) {

	TileDao dao = geoPackage.getTileDao(tileMatrix.getTableName());

	for (int column = 0; column < tileMatrix.getMatrixWidth(); column++) {

		for (int row = 0; row < tileMatrix.getMatrixHeight(); row++) {

			TileRow newRow = dao.newRow();

			newRow.setZoomLevel(tileMatrix.getZoomLevel());
			newRow.setTileColumn(column);
			newRow.setTileRow(row);
			newRow.setTileData(tileData);

			dao.create(newRow);
		}

	}

}
 
Example 11
Source File: TileWriter.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Write the tile table tile image set within the GeoPackage file to the
 * provided directory
 * 
 * @param geoPackage
 *            open GeoPackage
 * @param tileTable
 *            tile table
 * @param directory
 *            output directory
 * @param imageFormat
 *            image format
 * @param width
 *            optional image width
 * @param height
 *            optional image height
 * @param tileType
 *            tile type
 * @param rawImage
 *            use raw image flag
 * @throws IOException
 *             upon failure
 * @since 1.2.0
 */
public static void writeTiles(GeoPackage geoPackage, String tileTable,
		File directory, String imageFormat, Integer width, Integer height,
		TileFormatType tileType, boolean rawImage) throws IOException {

	// Get a tile data access object for the tile table
	TileDao tileDao = geoPackage.getTileDao(tileTable);

	// If no format, use the default
	if (imageFormat == null) {
		imageFormat = DEFAULT_IMAGE_FORMAT;
	}

	// If no tiles type, use the default
	if (tileType == null) {
		tileType = DEFAULT_TILE_TYPE;
	}

	LOGGER.log(Level.INFO, "GeoPackage: " + geoPackage.getName()
			+ ", Tile Table: " + tileTable + ", Output Directory: "
			+ directory + (rawImage ? ", Raw Images" : "")
			+ ", Image Format: " + imageFormat + ", Image Width: " + width
			+ ", Image Height: " + height + ", Tiles Type: " + tileType
			+ ", Tile Zoom Range: " + tileDao.getMinZoom() + " - "
			+ tileDao.getMaxZoom());

	int totalCount = 0;

	switch (tileType) {

	case GEOPACKAGE:
		totalCount = writeGeoPackageFormatTiles(tileDao, directory,
				imageFormat, width, height, rawImage);
		break;

	case XYZ:
	case TMS:
		totalCount = writeFormatTiles(tileDao, directory, imageFormat,
				width, height, tileType, rawImage);
		break;

	default:
		throw new UnsupportedOperationException("Tile Type Not Supported: "
				+ tileType);

	}

	// If GeoPackage format, write a properties file
	if (tileType == TileFormatType.GEOPACKAGE) {
		tileDao = geoPackage.getTileDao(tileTable);
		TileProperties tileProperties = new TileProperties(directory);
		tileProperties.writeFile(tileDao);
	}

	LOGGER.log(Level.INFO, "Total Tiles: " + totalCount);
}
 
Example 12
Source File: MapFragment.java    From mage-android with Apache License 2.0 4 votes vote down vote up
/**
 * Add the GeoPackage Tile Table Cache Overlay
 * @param enabledCacheOverlays
 * @param tileTableCacheOverlay
 * @param geoPackage
 * @param linkedToFeatures
 */
private void addGeoPackageTileCacheOverlay(Map<String, CacheOverlay> enabledCacheOverlays, GeoPackageTileTableCacheOverlay tileTableCacheOverlay, GeoPackage geoPackage, boolean linkedToFeatures){
	// Retrieve the cache overlay if it already exists (and remove from cache overlays)
	CacheOverlay cacheOverlay = cacheOverlays.remove(tileTableCacheOverlay.getCacheName());
	if(cacheOverlay != null){
		// If the existing cache overlay is being replaced, create a new cache overlay
		if(tileTableCacheOverlay.getParent().isAdded()){
			cacheOverlay = null;
		}
	}
	if(cacheOverlay == null){
		// Create a new GeoPackage tile provider and add to the map
		TileDao tileDao = geoPackage.getTileDao(tileTableCacheOverlay.getName());

		TileTableScaling tileTableScaling = new TileTableScaling(geoPackage, tileDao);
		TileScaling tileScaling = tileTableScaling.get();

		BoundedOverlay overlay = GeoPackageOverlayFactory
				.getBoundedOverlay(tileDao, getResources().getDisplayMetrics().density, tileScaling);

		TileOverlayOptions overlayOptions = null;
		if(linkedToFeatures){
			overlayOptions = createFeatureTileOverlayOptions(overlay);
		}else {
			overlayOptions = createTileOverlayOptions(overlay);
		}
		TileOverlay tileOverlay = map.addTileOverlay(overlayOptions);
		tileTableCacheOverlay.setTileOverlay(tileOverlay);

		// Check for linked feature tables
		tileTableCacheOverlay.clearFeatureOverlayQueries();
		FeatureTileTableLinker linker = new FeatureTileTableLinker(geoPackage);
		List<FeatureDao> featureDaos = linker.getFeatureDaosForTileTable(tileDao.getTableName());
		for(FeatureDao featureDao: featureDaos){

			// Create the feature tiles
			FeatureTiles featureTiles = new DefaultFeatureTiles(getActivity(), geoPackage, featureDao,
					getResources().getDisplayMetrics().density);

			// Add the feature overlay query
			FeatureOverlayQuery featureOverlayQuery = new FeatureOverlayQuery(getActivity(), overlay, featureTiles);
			tileTableCacheOverlay.addFeatureOverlayQuery(featureOverlayQuery);
		}

		cacheOverlay = tileTableCacheOverlay;
	}
	// Add the cache overlay to the enabled cache overlays
	enabledCacheOverlays.put(cacheOverlay.getCacheName(), cacheOverlay);
}
 
Example 13
Source File: TileUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test update
 *
 * @param testContext test context
 * @param geoPackage  GeoPackage
 * @throws SQLException upon error
 * @throws IOException  upon error
 */
public static void testUpdate(Context testContext, GeoPackage geoPackage) throws SQLException,
        IOException {

    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

    if (tileMatrixSetDao.isTableExists()) {
        List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();

        for (TileMatrixSet tileMatrixSet : results) {

            TileDao dao = geoPackage.getTileDao(tileMatrixSet);
            testUpdate(testContext, dao);

        }
    }

}
 
Example 14
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void createRelatedTablesTilesExtension(
        GeoPackage geoPackage) {

    String featureTable = "point2";
    String tileTable = "nga";

    RelatedTablesExtension relatedTables = new RelatedTablesExtension(
            geoPackage);

    List<UserCustomColumn> additionalMappingColumns = RelatedTablesUtils
            .createAdditionalUserColumns();

    UserMappingTable userMappingTable = UserMappingTable.create(
            featureTable + "_" + tileTable, additionalMappingColumns);
    ExtendedRelation relation = relatedTables.addTilesRelationship(
            featureTable, tileTable, userMappingTable);

    UserMappingDao userMappingDao = relatedTables.getMappingDao(relation);

    FeatureDao featureDao = geoPackage
            .getFeatureDao(relation.getBaseTableName());
    TileDao tileDao = geoPackage.getTileDao(relation.getRelatedTableName());

    FeatureCursor featureCursor = featureDao.queryForAll();
    while (featureCursor.moveToNext()) {

        FeatureRow featureRow = featureCursor.getRow();
        String featureName = featureRow.getValue(TEXT_COLUMN).toString();

        TileCursor tileCursor = tileDao
                .queryForTile(tileDao.getMinZoom());
        while (tileCursor.moveToNext()) {

            TileRow tileRow = tileCursor.getRow();

            UserMappingRow userMappingRow = userMappingDao.newRow();
            userMappingRow.setBaseId(featureRow.getId());
            userMappingRow.setRelatedId(tileRow.getId());
            RelatedTablesUtils.populateUserRow(userMappingDao.getTable(),
                    userMappingRow, UserMappingTable.requiredColumns());
            DublinCoreMetadata.setValue(userMappingRow,
                    DublinCoreType.TITLE, featureName);
            DublinCoreMetadata.setValue(userMappingRow,
                    DublinCoreType.DESCRIPTION, featureName);
            DublinCoreMetadata.setValue(userMappingRow,
                    DublinCoreType.SOURCE, featureName);
            userMappingDao.create(userMappingRow);
        }
        tileCursor.close();

    }
    featureCursor.close();

}
 
Example 15
Source File: UrlTileGeneratorUtils.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test generating tiles
 * 
 * @param tileGenerator
 * @throws SQLException
 * @throws IOException
 */
private static void testGenerateTiles(TileGenerator tileGenerator)
		throws SQLException, IOException {

	GeoPackage geoPackage = tileGenerator.getGeoPackage();
	String tableName = tileGenerator.getTableName();
	int minZoom = tileGenerator.getMinZoom();
	int maxZoom = tileGenerator.getMaxZoom();
	BoundingBox webMercatorBoundingBox = tileGenerator.getBoundingBox();

	TestGeoPackageProgress progress = new TestGeoPackageProgress();
	tileGenerator.setProgress(progress);

	int count = tileGenerator.generateTiles();

	long expected = expectedTiles(webMercatorBoundingBox, minZoom, maxZoom);
	TestCase.assertEquals(expected, count);
	TestCase.assertEquals(expected, progress.getProgress());

	TileDao tileDao = geoPackage.getTileDao(tableName);
	TestCase.assertEquals(expected, tileDao.count());
	TestCase.assertEquals(minZoom, tileDao.getMinZoom());
	TestCase.assertEquals(maxZoom, tileDao.getMaxZoom());

	BoundingBox tileMatrixSetBoundingBox = tileDao.getBoundingBox();

	for (int zoom = minZoom; zoom <= maxZoom; zoom++) {
		TileGrid expectedTileGrid = TileBoundingBoxUtils.getTileGrid(
				webMercatorBoundingBox, zoom);
		BoundingBox expectedBoundingBox = TileBoundingBoxUtils
				.getWebMercatorBoundingBox(expectedTileGrid, zoom);
		BoundingBox zoomBoundingBox = tileDao.getBoundingBox(zoom);
		TestCase.assertEquals(expectedBoundingBox.getMinLongitude(),
				zoomBoundingBox.getMinLongitude(), .000001);
		TestCase.assertEquals(expectedBoundingBox.getMaxLongitude(),
				zoomBoundingBox.getMaxLongitude(), .000001);
		TestCase.assertEquals(expectedBoundingBox.getMinLatitude(),
				zoomBoundingBox.getMinLatitude(), .000001);
		TestCase.assertEquals(expectedBoundingBox.getMaxLatitude(),
				zoomBoundingBox.getMaxLatitude(), .000001);
		long expectedZoomTiles = expectedTiles(webMercatorBoundingBox, zoom);
		TestCase.assertEquals(expectedZoomTiles, tileDao.count(zoom));

		TileMatrix tileMatrix = tileDao.getTileMatrix(zoom);

		TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
				tileMatrixSetBoundingBox, tileMatrix.getMatrixWidth(),
				tileMatrix.getMatrixHeight(), zoomBoundingBox);

		TestCase.assertTrue(tileGrid.getMinX() >= 0);
		TestCase.assertTrue(tileGrid.getMaxX() < tileMatrix
				.getMatrixWidth());
		TestCase.assertTrue(tileGrid.getMinY() >= 0);
		TestCase.assertTrue(tileGrid.getMaxY() < tileMatrix
				.getMatrixHeight());

		TileResultSet resultSet = tileDao.queryForTile(zoom);
		TestCase.assertEquals(expectedZoomTiles, resultSet.getCount());
		int resultCount = 0;
		while (resultSet.moveToNext()) {
			TileRow tileRow = resultSet.getRow();
			resultCount++;
			byte[] tileData = tileRow.getTileData();
			TestCase.assertNotNull(tileData);
			BufferedImage image = tileRow.getTileDataImage();
			TestCase.assertNotNull(image);
			TestCase.assertEquals(tileMatrix.getTileWidth(),
					image.getWidth());
			TestCase.assertEquals(tileMatrix.getTileHeight(),
					image.getHeight());
		}
		TestCase.assertEquals(expectedZoomTiles, resultCount);
	}

}
 
Example 16
Source File: CoverageDataTestUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test the pixel encoding location
 *
 * @param geoPackage GeoPackage
 * @param allowNulls allow nulls
 * @throws Exception
 */
public static void testPixelEncoding(GeoPackage geoPackage,
                                     boolean allowNulls) throws Exception {

    List<String> coverageDataTables = CoverageData.getTables(geoPackage);
    TestCase.assertFalse(coverageDataTables.isEmpty());

    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();
    TestCase.assertTrue(tileMatrixSetDao.isTableExists());
    TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();
    TestCase.assertTrue(tileMatrixDao.isTableExists());

    for (String coverageTable : coverageDataTables) {

        TileMatrixSet tileMatrixSet = tileMatrixSetDao
                .queryForId(coverageTable);

        TileDao tileDao = geoPackage.getTileDao(tileMatrixSet);
        CoverageData<?> coverageData = CoverageData.getCoverageData(
                geoPackage, tileDao);
        GriddedCoverage griddedCoverage = coverageData.getGriddedCoverage();
        GriddedCoverageEncodingType encoding = griddedCoverage
                .getGridCellEncodingType();

        TileCursor tileCursor = tileDao.queryForTile(tileDao
                .getMaxZoom());
        TestCase.assertNotNull(tileCursor);
        try {
            TestCase.assertTrue(tileCursor.getCount() > 0);
            while (tileCursor.moveToNext()) {
                TileRow tileRow = tileCursor.getRow();

                TileMatrix tileMatrix = tileDao.getTileMatrix(tileRow
                        .getZoomLevel());
                TestCase.assertNotNull(tileMatrix);

                GriddedTile griddedTile = coverageData.getGriddedTile(tileRow
                        .getId());
                TestCase.assertNotNull(griddedTile);

                byte[] tileData = tileRow.getTileData();
                TestCase.assertNotNull(tileData);

                BoundingBox boundingBox = TileBoundingBoxUtils.getBoundingBox(
                        tileMatrixSet.getBoundingBox(), tileMatrix,
                        tileRow.getTileColumn(), tileRow.getTileRow());

                int tileHeight = (int) tileMatrix.getTileHeight();
                int tileWidth = (int) tileMatrix.getTileWidth();

                int heightChunk = Math.max(tileHeight / 10, 1);
                int widthChunk = Math.max(tileWidth / 10, 1);

                for (int y = 0; y < tileHeight; y = Math.min(y + heightChunk,
                        y == tileHeight - 1 ? tileHeight : tileHeight - 1)) {
                    for (int x = 0; x < tileWidth; x = Math.min(x + widthChunk,
                            x == tileWidth - 1 ? tileWidth : tileWidth - 1)) {

                        Double pixelValue = coverageData.getValue(griddedTile,
                                tileData, x, y);
                        double pixelLongitude = boundingBox.getMinLongitude()
                                + (x * tileMatrix.getPixelXSize());
                        double pixelLatitude = boundingBox.getMaxLatitude()
                                - (y * tileMatrix.getPixelYSize());
                        switch (encoding) {
                            case CENTER:
                            case AREA:
                                pixelLongitude += (tileMatrix.getPixelXSize() / 2.0);
                                pixelLatitude -= (tileMatrix.getPixelYSize() / 2.0);
                                break;
                            case CORNER:
                                pixelLatitude -= tileMatrix.getPixelYSize();
                                break;
                        }
                        Double value = coverageData.getValue(pixelLatitude,
                                pixelLongitude);

                        if (!allowNulls || pixelValue != null) {
                            TestCase.assertEquals("x: " + x + ", y: " + y
                                            + ", encoding: " + encoding, pixelValue,
                                    value);
                        }
                    }
                }

                break;
            }
        } finally {
            tileCursor.close();
        }
    }

}
 
Example 17
Source File: TestUtils.java    From geopackage-android-map with MIT License 4 votes vote down vote up
/**
 * Add rows to the tile table
 *
 * @param geoPackage
 * @param tileMatrix
 * @param tileData
 */
public static void addRowsToTileTable(GeoPackage geoPackage,
                                      TileMatrix tileMatrix, byte[] tileData) {

    TileDao dao = geoPackage.getTileDao(tileMatrix.getTableName());

    for (int column = 0; column < tileMatrix.getMatrixWidth(); column++) {

        for (int row = 0; row < tileMatrix.getMatrixHeight(); row++) {

            TileRow newRow = dao.newRow();

            newRow.setZoomLevel(tileMatrix.getZoomLevel());
            newRow.setTileColumn(column);
            newRow.setTileRow(row);
            newRow.setTileData(tileData);

            dao.create(newRow);
        }

    }

}
 
Example 18
Source File: GeoPackageOverlayUtils.java    From geopackage-android-map with MIT License 3 votes vote down vote up
/**
 * Test overlay
 * 
 * @param geoPackage
 * @throws SQLException
 */
public static void testOverlay(GeoPackage geoPackage) throws SQLException {

	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

	if (tileMatrixSetDao.isTableExists()) {
		List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();

		for (TileMatrixSet tileMatrixSet : results) {

			TileDao dao = geoPackage.getTileDao(tileMatrixSet);

			GeoPackageOverlay overlay = new GeoPackageOverlay(dao);

			for (int zoom = 0; zoom <= 21; zoom++) {
				int tileLength = (int) Math.pow(2, zoom);

				int column = (int) (Math.random() * tileLength);
				int row = (int) (Math.random() * tileLength);

				for (int maxColumns = Math.min(tileLength, column + 2); column < maxColumns; column++) {
					for (int maxRows = Math.min(tileLength, row + 2); row < maxRows; row++) {
						Tile tile = overlay.getTile(column, row, zoom);
						if (tile != null) {
							TestCase.assertTrue(tile.height > 0);
							TestCase.assertTrue(tile.width > 0);
						}
					}
				}

			}

		}

	}

}
 
Example 19
Source File: TileUtils.java    From geopackage-java with MIT License 2 votes vote down vote up
/**
 * Test getZoomLevel
 * 
 * @param geoPackage
 *            GeoPackage
 * @throws SQLException
 *             upon error
 */
public static void testGetZoomLevel(GeoPackage geoPackage)
		throws SQLException {

	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

	if (tileMatrixSetDao.isTableExists()) {
		List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();

		for (TileMatrixSet tileMatrixSet : results) {

			TileDao dao = geoPackage.getTileDao(tileMatrixSet);

			List<TileMatrix> tileMatrices = dao.getTileMatrices();

			for (TileMatrix tileMatrix : tileMatrices) {

				double width = tileMatrix.getPixelXSize()
						* tileMatrix.getTileWidth();
				double height = tileMatrix.getPixelYSize()
						* tileMatrix.getTileHeight();

				long zoomLevel = dao.getZoomLevel(width);
				TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

				zoomLevel = dao.getZoomLevel(width, height);
				TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

				zoomLevel = dao.getZoomLevel(width + 1);
				TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

				zoomLevel = dao.getZoomLevel(width + 1, height + 1);
				TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

				zoomLevel = dao.getZoomLevel(width - 1);
				TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

				zoomLevel = dao.getZoomLevel(width - 1, height - 1);
				TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

			}

		}

	}

}
 
Example 20
Source File: TileUtils.java    From geopackage-android with MIT License 2 votes vote down vote up
/**
 * Test getZoomLevel
 *
 * @param geoPackage GeoPackage
 * @throws SQLException upon error
 */
public static void testGetZoomLevel(GeoPackage geoPackage)
        throws SQLException {

    TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

    if (tileMatrixSetDao.isTableExists()) {
        List<TileMatrixSet> results = tileMatrixSetDao.queryForAll();

        for (TileMatrixSet tileMatrixSet : results) {

            TileDao dao = geoPackage.getTileDao(tileMatrixSet);

            List<TileMatrix> tileMatrices = dao.getTileMatrices();

            for (TileMatrix tileMatrix : tileMatrices) {

                double width = tileMatrix.getPixelXSize()
                        * tileMatrix.getTileWidth();
                double height = tileMatrix.getPixelYSize()
                        * tileMatrix.getTileHeight();

                long zoomLevel = dao.getZoomLevel(width);
                TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

                zoomLevel = dao.getZoomLevel(width, height);
                TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

                zoomLevel = dao.getZoomLevel(width + 1);
                TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

                zoomLevel = dao.getZoomLevel(width + 1, height + 1);
                TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

                zoomLevel = dao.getZoomLevel(width - 1);
                TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

                zoomLevel = dao.getZoomLevel(width - 1, height - 1);
                TestCase.assertEquals(tileMatrix.getZoomLevel(), zoomLevel);

            }

        }

    }

}