Java Code Examples for mil.nga.geopackage.tiles.TileBoundingBoxUtils#getZoomLevel()

The following examples show how to use mil.nga.geopackage.tiles.TileBoundingBoxUtils#getZoomLevel() . 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: UserCoreDao.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Get the approximate zoom level of where the bounding box of the user data
 * fits into the world
 * 
 * @return zoom level
 * @since 1.1.0
 */
public int getZoomLevel() {
	Projection projection = getProjection();
	if (projection == null) {
		throw new GeoPackageException(
				"No projection was set which is required to determine the zoom level");
	}
	int zoomLevel = 0;
	BoundingBox boundingBox = getBoundingBox();
	if (boundingBox != null) {
		if (projection.isUnit(Units.DEGREES)) {
			boundingBox = TileBoundingBoxUtils
					.boundDegreesBoundingBoxWithWebMercatorLimits(
							boundingBox);
		}
		ProjectionTransform webMercatorTransform = projection
				.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
		BoundingBox webMercatorBoundingBox = boundingBox
				.transform(webMercatorTransform);
		zoomLevel = TileBoundingBoxUtils
				.getZoomLevel(webMercatorBoundingBox);
	}
	return zoomLevel;
}
 
Example 2
Source File: FeaturePreview.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Draw a preview image
 *
 * @return preview image
 */
public Bitmap draw() {

    Bitmap image = null;

    FeatureDao featureDao = featureTiles.getFeatureDao();
    String table = featureDao.getTableName();

    Projection webMercator = ProjectionFactory
            .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);

    BoundingBox boundingBox = geoPackage.getFeatureBoundingBox(webMercator,
            table, false);
    if (boundingBox == null) {
        boundingBox = geoPackage.getContentsBoundingBox(webMercator, table);
    }
    if (boundingBox == null && manual) {
        boundingBox = geoPackage.getFeatureBoundingBox(webMercator, table,
                manual);
    }
    if (boundingBox != null) {
        boundingBox = TileBoundingBoxUtils
                .boundWebMercatorBoundingBox(boundingBox);
        BoundingBox expandedBoundingBox = boundingBox
                .squareExpand(bufferPercentage);
        expandedBoundingBox = TileBoundingBoxUtils
                .boundWebMercatorBoundingBox(expandedBoundingBox);
        int zoom = TileBoundingBoxUtils.getZoomLevel(expandedBoundingBox);

        FeatureCursor results = featureDao.query(
                columns.toArray(new String[]{}), where, whereArgs, null,
                null, null, limit != null ? limit.toString() : null);
        image = featureTiles.drawTile(zoom, expandedBoundingBox, results);
    }

    return image;
}
 
Example 3
Source File: GeoPackageExample.java    From geopackage-android with MIT License 5 votes vote down vote up
private static void createFeatureTileLinkExtension(Context context, GeoPackage geoPackage)
        throws SQLException, IOException {

    List<String> featureTables = geoPackage.getFeatureTables();
    for (String featureTable : featureTables) {

        FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
        FeatureTiles featureTiles = new DefaultFeatureTiles(context, geoPackage, featureDao,
                context.getResources().getDisplayMetrics().density);

        BoundingBox boundingBox = featureDao.getBoundingBox();
        Projection projection = featureDao.getProjection();

        Projection requestProjection = ProjectionFactory
                .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
        ProjectionTransform transform = projection
                .getTransformation(requestProjection);
        BoundingBox requestBoundingBox = boundingBox.transform(transform);

        int zoomLevel = TileBoundingBoxUtils
                .getZoomLevel(requestBoundingBox);
        zoomLevel = Math.max(zoomLevel, 8);
        zoomLevel = Math.min(zoomLevel, 19);

        int minZoom = zoomLevel - 8;
        int maxZoom = zoomLevel + 2;

        TileGenerator tileGenerator = new FeatureTileGenerator(context, geoPackage,
                featureTable + "_tiles", featureTiles, minZoom, maxZoom,
                requestBoundingBox, requestProjection);

        tileGenerator.generateTiles();
        featureTiles.close();
    }
}
 
Example 4
Source File: FeaturePreview.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Draw a preview image
 * 
 * @return preview image
 */
public BufferedImage draw() {

	BufferedImage image = null;

	FeatureDao featureDao = featureTiles.getFeatureDao();
	String table = featureDao.getTableName();

	Projection webMercator = ProjectionFactory
			.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);

	BoundingBox boundingBox = geoPackage.getFeatureBoundingBox(webMercator,
			table, false);
	if (boundingBox == null) {
		boundingBox = geoPackage.getContentsBoundingBox(webMercator, table);
	}
	if (boundingBox == null && manual) {
		boundingBox = geoPackage.getFeatureBoundingBox(webMercator, table,
				manual);
	}
	if (boundingBox != null) {
		boundingBox = TileBoundingBoxUtils
				.boundWebMercatorBoundingBox(boundingBox);
		BoundingBox expandedBoundingBox = boundingBox
				.squareExpand(bufferPercentage);
		expandedBoundingBox = TileBoundingBoxUtils
				.boundWebMercatorBoundingBox(expandedBoundingBox);
		int zoom = TileBoundingBoxUtils.getZoomLevel(expandedBoundingBox);

		FeatureResultSet results = featureDao.query(
				columns.toArray(new String[] {}), where, whereArgs, null,
				null, null, limit != null ? limit.toString() : null);
		image = featureTiles.drawTile(zoom, expandedBoundingBox, results);
	}

	return image;
}
 
Example 5
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createFeatureTileLinkExtension(GeoPackage geoPackage)
		throws SQLException, IOException {

	List<String> featureTables = geoPackage.getFeatureTables();
	for (String featureTable : featureTables) {

		FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
		FeatureTiles featureTiles = new DefaultFeatureTiles(geoPackage,
				featureDao);

		BoundingBox boundingBox = featureDao.getBoundingBox();
		Projection projection = featureDao.getProjection();

		Projection requestProjection = ProjectionFactory
				.getProjection(ProjectionConstants.EPSG_WEB_MERCATOR);
		ProjectionTransform transform = projection
				.getTransformation(requestProjection);
		BoundingBox requestBoundingBox = boundingBox.transform(transform);

		int zoomLevel = TileBoundingBoxUtils
				.getZoomLevel(requestBoundingBox);
		zoomLevel = Math.max(zoomLevel, 8);
		zoomLevel = Math.min(zoomLevel, 19);

		int minZoom = zoomLevel - 8;
		int maxZoom = zoomLevel + 2;

		TileGenerator tileGenerator = new FeatureTileGenerator(geoPackage,
				featureTable + "_tiles", featureTiles, minZoom, maxZoom,
				requestBoundingBox, requestProjection);

		tileGenerator.generateTiles();
	}
}