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

The following examples show how to use mil.nga.geopackage.tiles.TileBoundingBoxUtils#boundWebMercatorBoundingBox() . 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: FeatureTiles.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Create an expanded bounding box to handle features outside the tile that
 * overlap
 *
 * @param webMercatorBoundingBox     web mercator bounding box
 * @param tileWebMercatorBoundingBox tile web mercator bounding box
 * @return bounding box
 * @since 3.2.0
 */
public BoundingBox expandBoundingBox(BoundingBox webMercatorBoundingBox, BoundingBox tileWebMercatorBoundingBox) {

    // Create an expanded bounding box to handle features outside the tile
    // that overlap
    double minLongitude = TileBoundingBoxUtils.getLongitudeFromPixel(
            tileWidth, webMercatorBoundingBox, tileWebMercatorBoundingBox, 0 - widthOverlap);
    double maxLongitude = TileBoundingBoxUtils.getLongitudeFromPixel(
            tileWidth, webMercatorBoundingBox, tileWebMercatorBoundingBox, tileWidth + widthOverlap);
    double maxLatitude = TileBoundingBoxUtils.getLatitudeFromPixel(
            tileHeight, webMercatorBoundingBox, tileWebMercatorBoundingBox, 0 - heightOverlap);
    double minLatitude = TileBoundingBoxUtils.getLatitudeFromPixel(
            tileHeight, webMercatorBoundingBox, tileWebMercatorBoundingBox, tileHeight + heightOverlap);

    // Choose the most expanded longitudes and latitudes
    minLongitude = Math.min(minLongitude, webMercatorBoundingBox.getMinLongitude());
    maxLongitude = Math.max(maxLongitude, webMercatorBoundingBox.getMaxLongitude());
    minLatitude = Math.min(minLatitude, webMercatorBoundingBox.getMinLatitude());
    maxLatitude = Math.max(maxLatitude, webMercatorBoundingBox.getMaxLatitude());

    BoundingBox expandedBoundingBox = new BoundingBox(minLongitude,
            minLatitude, maxLongitude, maxLatitude);

    // Bound with the web mercator limits
    expandedBoundingBox = TileBoundingBoxUtils
            .boundWebMercatorBoundingBox(expandedBoundingBox);

    return expandedBoundingBox;
}
 
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: FeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Create an expanded bounding box to handle features outside the tile that
 * overlap
 *
 * @param webMercatorBoundingBox
 *            web mercator bounding box
 * @param tileWebMercatorBoundingBox
 *            tile web mercator bounding box
 * @return bounding box
 * @since 3.2.0
 */
public BoundingBox expandBoundingBox(BoundingBox webMercatorBoundingBox,
		BoundingBox tileWebMercatorBoundingBox) {

	// Create an expanded bounding box to handle features outside the tile
	// that overlap
	double minLongitude = TileBoundingBoxUtils.getLongitudeFromPixel(
			tileWidth, webMercatorBoundingBox, tileWebMercatorBoundingBox,
			0 - widthOverlap);
	double maxLongitude = TileBoundingBoxUtils.getLongitudeFromPixel(
			tileWidth, webMercatorBoundingBox, tileWebMercatorBoundingBox,
			tileWidth + widthOverlap);
	double maxLatitude = TileBoundingBoxUtils.getLatitudeFromPixel(
			tileHeight, webMercatorBoundingBox, tileWebMercatorBoundingBox,
			0 - heightOverlap);
	double minLatitude = TileBoundingBoxUtils.getLatitudeFromPixel(
			tileHeight, webMercatorBoundingBox, tileWebMercatorBoundingBox,
			tileHeight + heightOverlap);

	// Choose the most expanded longitudes and latitudes
	minLongitude = Math.min(minLongitude,
			webMercatorBoundingBox.getMinLongitude());
	maxLongitude = Math.max(maxLongitude,
			webMercatorBoundingBox.getMaxLongitude());
	minLatitude = Math.min(minLatitude,
			webMercatorBoundingBox.getMinLatitude());
	maxLatitude = Math.max(maxLatitude,
			webMercatorBoundingBox.getMaxLatitude());

	BoundingBox expandedBoundingBox = new BoundingBox(minLongitude,
			minLatitude, maxLongitude, maxLatitude);

	// Bound with the web mercator limits
	expandedBoundingBox = TileBoundingBoxUtils
			.boundWebMercatorBoundingBox(expandedBoundingBox);

	return expandedBoundingBox;
}
 
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;
}