Java Code Examples for mil.nga.geopackage.tiles.user.TileDao

The following examples show how to use mil.nga.geopackage.tiles.user.TileDao. These examples are extracted from open source projects. 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 Project: osmdroid   Source File: GeoPackageMapTileModuleProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * returns ALL available raster tile sources for the specified database.
 * This will throw if the database doesn't exist or isn't registered
 *
 * @return
 */
public List<GeopackageRasterTileSource> getTileSources(String database) {
    List<GeopackageRasterTileSource> srcs = new ArrayList<>();

    GeoPackage open = manager.open(database);
    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(database, tileTables.get(k), (int)tileDao.getMinZoom(), (int)tileDao.getMaxZoom(), bounds));

    }
    open.close();

    return srcs;
}
 
Example 2
Source Project: geopackage-android   Source File: GeoPackageImpl.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TileDao getTileDao(Contents contents) {

    if (contents == null) {
        throw new GeoPackageException("Non null "
                + Contents.class.getSimpleName()
                + " is required to create " + TileDao.class.getSimpleName());
    }

    TileMatrixSet tileMatrixSet = contents.getTileMatrixSet();
    if (tileMatrixSet == null) {
        throw new GeoPackageException("No "
                + TileMatrixSet.class.getSimpleName() + " exists for "
                + Contents.class.getSimpleName() + " " + contents.getId());
    }

    return getTileDao(tileMatrixSet);
}
 
Example 3
Source Project: geopackage-android   Source File: CoverageDataTestUtils.java    License: 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 4
Source Project: osmdroid   Source File: GeoPackageMapTileModuleProvider.java    License: 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 5
Source Project: geopackage-android-map   Source File: FeatureOverlay.java    License: MIT License 5 votes vote down vote up
/**
 * Ignore drawing tiles if they exist in the tile tables represented by the tile daos
 *
 * @param tileDaos tile data access objects
 * @since 1.2.6
 */
public void ignoreTileDaos(List<TileDao> tileDaos) {

    for (TileDao tileDao : tileDaos) {
        ignoreTileDao(tileDao);
    }

}
 
Example 6
Source Project: geopackage-android-map   Source File: GeoPackageOverlayFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Get a Bounded Overlay Tile Provider for the Tile DAO
 *
 * @param tileDao tile dao
 * @return bounded overlay
 * @since 1.2.5
 */
public static BoundedOverlay getBoundedOverlay(TileDao tileDao) {

    BoundedOverlay overlay = null;

    if (tileDao.isXYZTiles()) {
        overlay = new XYZGeoPackageOverlay(tileDao);
    } else {
        overlay = new GeoPackageOverlay(tileDao);
    }

    return overlay;
}
 
Example 7
Source Project: geopackage-android-map   Source File: GeoPackageOverlayFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Get a Bounded Overlay Tile Provider for the Tile DAO with the display density
 *
 * @param tileDao tile dao
 * @param density display density: {@link android.util.DisplayMetrics#density}
 * @return bounded overlay
 * @since 3.2.0
 */
public static BoundedOverlay getBoundedOverlay(TileDao tileDao, float density) {

    BoundedOverlay overlay = null;

    if (tileDao.isXYZTiles()) {
        overlay = new XYZGeoPackageOverlay(tileDao);
    } else {
        overlay = new GeoPackageOverlay(tileDao, density);
    }

    return overlay;
}
 
Example 8
Source Project: geopackage-java   Source File: CoverageDataTestUtils.java    License: 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
 * @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 9
Source Project: geopackage-android-map   Source File: GeoPackageOverlayFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Create a composite overlay by adding tile overlays for the tile DAOs
 *
 * @param tileDaos collection of tile daos
 * @return composite overlay
 */
public static CompositeOverlay getCompositeOverlay(Collection<TileDao> tileDaos) {

    CompositeOverlay compositeOverlay = new CompositeOverlay();

    for (TileDao tileDao : tileDaos) {
        BoundedOverlay boundedOverlay = GeoPackageOverlayFactory.getBoundedOverlay(tileDao);
        compositeOverlay.addOverlay(boundedOverlay);
    }

    return compositeOverlay;
}
 
Example 10
Source Project: geopackage-java   Source File: TileProperties.java    License: MIT License 5 votes vote down vote up
/**
 * Write the properties file using the tile dao
 * 
 * @param tileDao
 *            tile dao
 */
public void writeFile(TileDao tileDao) {
	try {
		PrintWriter pw = new PrintWriter(propertiesFile);

		TileMatrixSet tileMatrixSet = tileDao.getTileMatrixSet();
		pw.println(GEOPACKAGE_PROPERTIES_EPSG + "="
				+ tileMatrixSet.getSrs().getOrganizationCoordsysId());
		pw.println(GEOPACKAGE_PROPERTIES_MIN_X + "="
				+ tileMatrixSet.getMinX());
		pw.println(GEOPACKAGE_PROPERTIES_MAX_X + "="
				+ tileMatrixSet.getMaxX());
		pw.println(GEOPACKAGE_PROPERTIES_MIN_Y + "="
				+ tileMatrixSet.getMinY());
		pw.println(GEOPACKAGE_PROPERTIES_MAX_Y + "="
				+ tileMatrixSet.getMaxY());

		for (TileMatrix tileMatrix : tileDao.getTileMatrices()) {
			long zoom = tileMatrix.getZoomLevel();
			pw.println(getMatrixWidthProperty(zoom) + "="
					+ tileMatrix.getMatrixWidth());
			pw.println(getMatrixHeightProperty(zoom) + "="
					+ tileMatrix.getMatrixHeight());
		}

		pw.close();

	} catch (FileNotFoundException e) {
		throw new GeoPackageException(
				"GeoPackage file format properties file could not be created: "
						+ propertiesFile, e);
	}
}
 
Example 11
Source Project: geopackage-android-map   Source File: GeoPackageOverlay.java    License: MIT License 5 votes vote down vote up
/**
 * Constructor with tile scaling options
 *
 * @param tileDao tile dao
 * @param scaling tile scaling options
 * @since 2.0.2
 */
public GeoPackageOverlay(TileDao tileDao, TileScaling scaling) {
    GeoPackageTileRetriever tileRetriever = new GeoPackageTileRetriever(tileDao);
    if (scaling != null) {
        tileRetriever.setScaling(scaling);
    }
    this.retriever = tileRetriever;
}
 
Example 12
Source Project: geopackage-android   Source File: FeatureTileTableLinker.java    License: MIT License 5 votes vote down vote up
/**
 * Query for the tile tables linked to a feature table and return tile DAOs
 * to those tables
 *
 * @param featureTable feature table
 * @return tiles DAOs
 */
public List<TileDao> getTileDaosForFeatureTable(String featureTable) {

    List<TileDao> tileDaos = new ArrayList<TileDao>();

    List<String> tileTables = getTileTablesForFeatureTable(featureTable);
    for (String tileTable : tileTables) {
        if (geoPackage.isTileTable(tileTable)) {
            TileDao tileDao = geoPackage.getTileDao(tileTable);
            tileDaos.add(tileDao);
        }
    }

    return tileDaos;
}
 
Example 13
Source Project: geopackage-android   Source File: CoverageData.java    License: MIT License 5 votes vote down vote up
/**
 * Get a Tiled Gridded Coverage Data
 *
 * @param geoPackage        GeoPackage
 * @param tileDao           tile dao
 * @param width             coverage data response width
 * @param height            coverage data response height
 * @param requestProjection request projection
 * @return coverage data
 */
public static CoverageData<?> getCoverageData(GeoPackage geoPackage,
                                              TileDao tileDao, Integer width, Integer height,
                                              Projection requestProjection) {

    TileMatrixSet tileMatrixSet = tileDao.getTileMatrixSet();
    GriddedCoverageDao griddedCoverageDao = geoPackage
            .getGriddedCoverageDao();

    GriddedCoverage griddedCoverage = null;
    try {
        if (griddedCoverageDao.isTableExists()) {
            griddedCoverage = griddedCoverageDao.query(tileMatrixSet);
        }
    } catch (SQLException e) {
        throw new GeoPackageException(
                "Failed to get Gridded Coverage for table name: "
                        + tileMatrixSet.getTableName(), e);
    }

    CoverageData<?> coverageData = null;

    GriddedCoverageDataType dataType = griddedCoverage.getDataType();
    switch (dataType) {
        case INTEGER:
            coverageData = new CoverageDataPng(geoPackage, tileDao, width,
                    height, requestProjection);
            break;
        case FLOAT:
            coverageData = new CoverageDataTiff(geoPackage, tileDao, width,
                    height, requestProjection);
            break;
        default:
            throw new GeoPackageException(
                    "Unsupported Gridded Coverage Data Type: " + dataType);
    }

    return coverageData;
}
 
Example 14
Source Project: geopackage-android   Source File: CoverageData.java    License: 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 15
Source Project: geopackage-java   Source File: TileUtils.java    License: 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 16
Source Project: geopackage-java   Source File: GeoPackageTextOutput.java    License: MIT License 5 votes vote down vote up
/**
 * Build text from a tile table
 * 
 * @param table
 *            tile table
 * @return text
 */
public String tileTable(String table) {

	StringBuilder output = new StringBuilder();
	TileDao tileDao = geoPackage.getTileDao(table);
	output.append("Table Name: " + tileDao.getTableName());
	long minZoom = tileDao.getMinZoom();
	long maxZoom = tileDao.getMaxZoom();
	output.append("\nMin Zoom: " + minZoom);
	output.append("\nMax Zoom: " + maxZoom);
	output.append("\nTiles: " + tileDao.count());

	TileMatrixSet tileMatrixSet = tileDao.getTileMatrixSet();

	output.append("\n\nContents\n\n")
			.append(textOutput(tileMatrixSet.getContents()));

	output.append("\n\nTile Matrix Set\n\n")
			.append(textOutput(tileMatrixSet));

	output.append("\n\n Tile Matrices");

	for (long zoom = minZoom; zoom <= maxZoom; zoom++) {
		TileMatrix tileMatrix = tileDao.getTileMatrix(zoom);
		if (tileMatrix != null) {
			output.append("\n\n").append(textOutput(tileMatrix));
			output.append("\n\tTiles: " + tileDao.count(zoom));
			BoundingBox boundingBox = tileDao.getBoundingBox(zoom);
			output.append("\n\tTile Bounds: \n")
					.append(textOutput(boundingBox));
		}
	}

	return output.toString();
}
 
Example 17
Source Project: geopackage-android   Source File: TileCreator.java    License: MIT License 5 votes vote down vote up
/**
 * Constructor, specified tile size and projection
 *
 * @param tileDao           tile dao
 * @param width             requested width
 * @param height            requested height
 * @param requestProjection requested projection
 */
public TileCreator(TileDao tileDao, Integer width, Integer height, Projection requestProjection) {
    this.tileDao = tileDao;
    this.width = width;
    this.height = height;
    this.requestProjection = requestProjection;

    tileMatrixSet = tileDao.getTileMatrixSet();
    tilesProjection = tileDao.getTileMatrixSet().getProjection();
    tileSetBoundingBox = tileMatrixSet.getBoundingBox();

    // Check if the projections have the same units
    sameProjection = (requestProjection.getUnit().name.equals(tilesProjection.getUnit().name));
}
 
Example 18
Source Project: geopackage-android   Source File: CoverageDataTestUtils.java    License: 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 19
Source Project: geopackage-java   Source File: FeatureTileTableLinker.java    License: MIT License 5 votes vote down vote up
/**
 * Query for the tile tables linked to a feature table and return tile DAOs
 * to those tables
 * 
 * @param featureTable
 *            feature table
 * @return tiles DAOs
 */
public List<TileDao> getTileDaosForFeatureTable(String featureTable) {

	List<TileDao> tileDaos = new ArrayList<TileDao>();

	List<String> tileTables = getTileTablesForFeatureTable(featureTable);
	for (String tileTable : tileTables) {
		if (geoPackage.isTileTable(tileTable)) {
			TileDao tileDao = geoPackage.getTileDao(tileTable);
			tileDaos.add(tileDao);
		}
	}

	return tileDaos;
}
 
Example 20
Source Project: geopackage-java   Source File: CoverageData.java    License: MIT License 5 votes vote down vote up
/**
 * Get a Tiled Gridded Coverage Data
 * 
 * @param geoPackage
 *            GeoPackage
 * @param tileDao
 *            tile dao
 * @param width
 *            coverage data response width
 * @param height
 *            coverage data response height
 * @param requestProjection
 *            request projection
 * @return coverage data
 */
public static CoverageData<?> getCoverageData(GeoPackage geoPackage,
		TileDao tileDao, Integer width, Integer height,
		Projection requestProjection) {

	TileMatrixSet tileMatrixSet = tileDao.getTileMatrixSet();
	GriddedCoverageDao griddedCoverageDao = geoPackage
			.getGriddedCoverageDao();

	GriddedCoverage griddedCoverage = null;
	try {
		if (griddedCoverageDao.isTableExists()) {
			griddedCoverage = griddedCoverageDao.query(tileMatrixSet);
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to get Gridded Coverage for table name: "
						+ tileMatrixSet.getTableName(), e);
	}

	CoverageData<?> coverageData = null;

	GriddedCoverageDataType dataType = griddedCoverage.getDataType();
	switch (dataType) {
	case INTEGER:
		coverageData = new CoverageDataPng(geoPackage, tileDao, width,
				height, requestProjection);
		break;
	case FLOAT:
		coverageData = new CoverageDataTiff(geoPackage, tileDao, width,
				height, requestProjection);
		break;
	default:
		throw new GeoPackageException(
				"Unsupported Gridded Coverage Data Type: " + dataType);
	}

	return coverageData;
}
 
Example 21
Source Project: geopackage-java   Source File: TileCreator.java    License: MIT License 5 votes vote down vote up
/**
 * Constructor
 *
 * @param tileDao
 *            tile dao
 * @param width
 *            request width
 * @param height
 *            request height
 * @param requestProjection
 *            request projection
 * @param imageFormat
 *            image format
 */
public TileCreator(TileDao tileDao, Integer width, Integer height,
		Projection requestProjection, String imageFormat) {
	this.tileDao = tileDao;
	this.width = width;
	this.height = height;
	this.requestProjection = requestProjection;
	this.imageFormat = imageFormat;

	if (imageFormat == null && (width != null || height != null)) {
		throw new GeoPackageException(
				"The width and height request size can not be specified when requesting raw tiles (no image format specified)");
	}

	tileMatrixSet = tileDao.getTileMatrixSet();
	tilesProjection = tileDao.getTileMatrixSet().getProjection();
	tileSetBoundingBox = tileMatrixSet.getBoundingBox();

	// Check if the projections have the same units
	sameProjection = (requestProjection.getUnit().name
			.equals(tilesProjection.getUnit().name));

	if (imageFormat == null && !sameProjection) {
		throw new GeoPackageException(
				"The requested projection must be the same as the stored tiles when requesting raw tiles (no image format specified)");
	}
}
 
Example 22
Source Project: geopackage-java   Source File: CoverageData.java    License: 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 23
Source Project: geopackage-java   Source File: GeoPackageImpl.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TileDao getTileDao(Contents contents) {

	if (contents == null) {
		throw new GeoPackageException("Non null "
				+ Contents.class.getSimpleName() + " is required to create "
				+ TileDao.class.getSimpleName());
	}

	TileMatrixSet tileMatrixSet = null;
	try {
		tileMatrixSet = getTileMatrixSetDao()
				.queryForId(contents.getTableName());
	} catch (SQLException e) {
		throw new GeoPackageException("No "
				+ TileMatrixSet.class.getSimpleName()
				+ " could be retrieved for "
				+ Contents.class.getSimpleName() + " " + contents.getId());
	}

	if (tileMatrixSet == null) {
		throw new GeoPackageException("No "
				+ TileMatrixSet.class.getSimpleName() + " exists for "
				+ Contents.class.getSimpleName() + " " + contents.getId());
	}

	return getTileDao(tileMatrixSet);
}
 
Example 24
Source Project: geopackage-java   Source File: GeoPackageImpl.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TileDao getTileDao(String tableName) {

	TileMatrixSetDao dao = getTileMatrixSetDao();
	List<TileMatrixSet> tileMatrixSetList;
	try {
		tileMatrixSetList = dao.queryForEq(TileMatrixSet.COLUMN_TABLE_NAME,
				tableName);
	} catch (SQLException e) {
		throw new GeoPackageException("Failed to retrieve "
				+ TileDao.class.getSimpleName() + " for table name: "
				+ tableName + ". Exception retrieving "
				+ TileMatrixSet.class.getSimpleName() + ".", e);
	}
	if (tileMatrixSetList.isEmpty()) {
		throw new GeoPackageException(
				"No Tile Table exists for table name: " + tableName
						+ ", Tile Tables: " + getTileTables());
	} else if (tileMatrixSetList.size() > 1) {
		// This shouldn't happen with the table name primary key on tile
		// matrix set table
		throw new GeoPackageException("Unexpected state. More than one "
				+ TileMatrixSet.class.getSimpleName()
				+ " matched for table name: " + tableName + ", count: "
				+ tileMatrixSetList.size());
	}
	return getTileDao(tileMatrixSetList.get(0));
}
 
Example 25
Source Project: geopackage-java   Source File: TileUtils.java    License: MIT License 4 votes vote down vote up
/**
 * Validate a tile row
 * 
 * @param dao
 * @param columns
 * @param tileRow
 */
private static void validateTileRow(TileDao dao, String[] columns,
		TileRow tileRow) {
	TestCase.assertEquals(columns.length, tileRow.columnCount());

	for (int i = 0; i < tileRow.columnCount(); i++) {
		TileColumn column = tileRow.getTable().getColumns().get(i);
		TestCase.assertEquals(i, column.getIndex());
		TestCase.assertEquals(columns[i], tileRow.getColumnName(i));
		TestCase.assertEquals(i, tileRow.getColumnIndex(columns[i]));
		int rowType = tileRow.getRowColumnType(i);
		Object value = tileRow.getValue(i);

		switch (rowType) {

		case ResultUtils.FIELD_TYPE_INTEGER:
			TestUtils.validateIntegerValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_FLOAT:
			TestUtils.validateFloatValue(value, column.getDataType());
			break;

		case ResultUtils.FIELD_TYPE_STRING:
			TestCase.assertTrue(value instanceof String);
			break;

		case ResultUtils.FIELD_TYPE_BLOB:
			TestCase.assertTrue(value instanceof byte[]);
			break;

		case ResultUtils.FIELD_TYPE_NULL:
			TestCase.assertNull(value);
			break;

		}
	}

	TestCase.assertTrue(tileRow.getId() >= 0);
	TestCase.assertTrue(tileRow.getZoomLevel() >= 0);
	TestCase.assertTrue(tileRow.getTileColumn() >= 0);
	TestCase.assertTrue(tileRow.getTileRow() >= 0);
	byte[] tileData = tileRow.getTileData();
	TestCase.assertNotNull(tileData);
	TestCase.assertTrue(tileData.length > 0);

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

}
 
Example 26
Source Project: geopackage-android-map   Source File: TestUtils.java    License: 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 27
Source Project: geopackage-java   Source File: TestUtils.java    License: 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 28
Source Project: geopackage-java   Source File: UrlTileGeneratorUtils.java    License: 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 29
Source Project: geopackage-android   Source File: GeoPackageImpl.java    License: MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public TileDao getTileDao(TileMatrixSet tileMatrixSet) {

    if (tileMatrixSet == null) {
        throw new GeoPackageException("Non null "
                + TileMatrixSet.class.getSimpleName()
                + " is required to create " + TileDao.class.getSimpleName());
    }

    // Get the Tile Matrix collection, order by zoom level ascending & pixel
    // size descending per requirement 51
    List<TileMatrix> tileMatrices;
    try {
        TileMatrixDao tileMatrixDao = getTileMatrixDao();
        QueryBuilder<TileMatrix, TileMatrixKey> qb = tileMatrixDao
                .queryBuilder();
        qb.where().eq(TileMatrix.COLUMN_TABLE_NAME,
                tileMatrixSet.getTableName());
        qb.orderBy(TileMatrix.COLUMN_ZOOM_LEVEL, true);
        qb.orderBy(TileMatrix.COLUMN_PIXEL_X_SIZE, false);
        qb.orderBy(TileMatrix.COLUMN_PIXEL_Y_SIZE, false);
        PreparedQuery<TileMatrix> query = qb.prepare();
        tileMatrices = tileMatrixDao.query(query);
    } catch (SQLException e) {
        throw new GeoPackageException("Failed to retrieve "
                + TileDao.class.getSimpleName() + " for table name: "
                + tileMatrixSet.getTableName() + ". Exception retrieving "
                + TileMatrix.class.getSimpleName() + " collection.", e);
    }

    // Read the existing table and create the dao
    TileTableReader tableReader = new TileTableReader(
            tileMatrixSet.getTableName());
    final TileTable tileTable = tableReader.readTable(database);
    tileTable.setContents(tileMatrixSet.getContents());
    TileDao dao = new TileDao(getName(), database, tileMatrixSet, tileMatrices,
            tileTable);

    // Register the table name (with and without quotes) to wrap cursors with the tile cursor
    registerCursorWrapper(tileMatrixSet.getTableName(),
            new GeoPackageCursorWrapper() {

                @Override
                public Cursor wrapCursor(Cursor cursor) {
                    return new TileCursor(tileTable, cursor);
                }
            });

    return dao;
}
 
Example 30
Source Project: geopackage-java   Source File: TileUtils.java    License: 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);

		}
	}

}