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

The following examples show how to use mil.nga.geopackage.tiles.user.TileDao. 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: GeoPackageImpl.java    From geopackage-android with 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 #2
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 #3
Source File: GeoPackageMapTileModuleProvider.java    From osmdroid with 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 #4
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 #5
Source File: GeoPackageImpl.java    From geopackage-java with 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 #6
Source File: GeoPackageOverlay.java    From geopackage-android-map with 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 #7
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 #8
Source File: TileProperties.java    From geopackage-java with 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 #9
Source File: GeoPackageOverlayFactory.java    From geopackage-android-map with 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 File: CoverageDataTestUtils.java    From geopackage-java 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
 * @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 #11
Source File: GeoPackageOverlayFactory.java    From geopackage-android-map with 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 #12
Source File: GeoPackageOverlayFactory.java    From geopackage-android-map with 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 #13
Source File: GeoPackageImpl.java    From geopackage-java with 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 #14
Source File: FeatureTileTableLinker.java    From geopackage-java with 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 #15
Source File: CoverageData.java    From geopackage-java with 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 #16
Source File: TileCreator.java    From geopackage-java with 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 #17
Source File: FeatureTileTableLinker.java    From geopackage-android with 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 #18
Source File: CoverageData.java    From geopackage-android with 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 #19
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 #20
Source File: TileCreator.java    From geopackage-android with 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 #21
Source File: CoverageData.java    From geopackage-android 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 #22
Source File: FeatureOverlay.java    From geopackage-android-map with 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 #23
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 #24
Source File: GeoPackageTextOutput.java    From geopackage-java with 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 #25
Source File: GeoPackageImpl.java    From geopackage-android with 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 #26
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 #27
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 #28
Source File: GeoPackageExample.java    From geopackage-java 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());

	FeatureResultSet featureResultSet = featureDao.queryForAll();
	while (featureResultSet.moveToNext()) {

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

		TileResultSet tileResultSet = tileDao
				.queryForTile(tileDao.getMinZoom());
		while (tileResultSet.moveToNext()) {

			TileRow tileRow = tileResultSet.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);
		}
		tileResultSet.close();

	}
	featureResultSet.close();

}
 
Example #29
Source File: TileUtils.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Validate a tile row
 *
 * @param dao
 * @param columns
 * @param tileRow
 * @param testBitmap
 */
private static void validateTileRow(TileDao dao, String[] columns,
                                    TileRow tileRow, boolean testBitmap) {
    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 Cursor.FIELD_TYPE_INTEGER:
                TestUtils.validateIntegerValue(value, column.getDataType());
                break;

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

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

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

            case Cursor.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);

    if (testBitmap) {
        Bitmap bitmap = tileRow.getTileDataBitmap();
        if (dao.getTileMatrixSet().getContents().getDataType() != ContentsDataType.GRIDDED_COVERAGE) {
            TestCase.assertNotNull(bitmap);
            TestCase.assertEquals(tileMatrix.getTileWidth(), bitmap.getWidth());
            TestCase.assertEquals(tileMatrix.getTileHeight(),
                    bitmap.getHeight());
        }
    }
}
 
Example #30
Source File: TestUtils.java    From geopackage-android 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);
        }

    }

}