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

The following examples show how to use mil.nga.geopackage.tiles.matrix.TileMatrix#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: CoverageData.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Get the coverage data tile results by zooming in from the provided tile
 * matrix
 *
 * @param requestProjectedBoundingBox request projected bounding box
 * @param tileMatrix                  tile matrix
 * @param overlappingPixels           overlapping request pixels
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResultsZoomIn(
        BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix,
        int overlappingPixels) {

    CoverageDataTileMatrixResults results = null;
    for (long zoomLevel = tileMatrix.getZoomLevel() + 1; zoomLevel <= tileDao
            .getMaxZoom(); zoomLevel++) {
        TileMatrix zoomTileMatrix = tileDao.getTileMatrix(zoomLevel);
        if (zoomTileMatrix != null) {
            results = getResults(requestProjectedBoundingBox,
                    zoomTileMatrix, overlappingPixels);
            if (results != null) {
                break;
            }
        }
    }
    return results;
}
 
Example 2
Source File: CoverageData.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Get the coverage data tile results by zooming out from the provided tile
 * matrix
 *
 * @param requestProjectedBoundingBox request projected bounding box
 * @param tileMatrix                  tile matrix
 * @param overlappingPixels           overlapping request pixels
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResultsZoomOut(
        BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix,
        int overlappingPixels) {

    CoverageDataTileMatrixResults results = null;
    for (long zoomLevel = tileMatrix.getZoomLevel() - 1; zoomLevel >= tileDao
            .getMinZoom(); zoomLevel--) {
        TileMatrix zoomTileMatrix = tileDao.getTileMatrix(zoomLevel);
        if (zoomTileMatrix != null) {
            results = getResults(requestProjectedBoundingBox,
                    zoomTileMatrix, overlappingPixels);
            if (results != null) {
                break;
            }
        }
    }
    return results;
}
 
Example 3
Source File: CoverageData.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Get the coverage data tile results by zooming in from the provided tile
 * matrix
 * 
 * @param requestProjectedBoundingBox
 *            request projected bounding box
 * @param tileMatrix
 *            tile matrix
 * @param overlappingPixels
 *            overlapping request pixels
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResultsZoomIn(
		BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix,
		int overlappingPixels) {

	CoverageDataTileMatrixResults results = null;
	for (long zoomLevel = tileMatrix.getZoomLevel() + 1; zoomLevel <= tileDao
			.getMaxZoom(); zoomLevel++) {
		TileMatrix zoomTileMatrix = tileDao.getTileMatrix(zoomLevel);
		if (zoomTileMatrix != null) {
			results = getResults(requestProjectedBoundingBox,
					zoomTileMatrix, overlappingPixels);
			if (results != null) {
				break;
			}
		}
	}
	return results;
}
 
Example 4
Source File: CoverageData.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Get the coverage data tile results by zooming out from the provided tile
 * matrix
 * 
 * @param requestProjectedBoundingBox
 *            request projected bounding box
 * @param tileMatrix
 *            tile matrix
 * @param overlappingPixels
 *            overlapping request pixels
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResultsZoomOut(
		BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix,
		int overlappingPixels) {

	CoverageDataTileMatrixResults results = null;
	for (long zoomLevel = tileMatrix.getZoomLevel() - 1; zoomLevel >= tileDao
			.getMinZoom(); zoomLevel--) {
		TileMatrix zoomTileMatrix = tileDao.getTileMatrix(zoomLevel);
		if (zoomTileMatrix != null) {
			results = getResults(requestProjectedBoundingBox,
					zoomTileMatrix, overlappingPixels);
			if (results != null) {
				break;
			}
		}
	}
	return results;
}
 
Example 5
Source File: TileDao.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Determine if the tiles are in the XYZ tile coordinate format
 *
 * @return true if XYZ tile format
 * @since 3.5.0
 */
public boolean isXYZTiles() {

    // Convert the bounding box to wgs84
    BoundingBox boundingBox = tileMatrixSet.getBoundingBox();
    BoundingBox wgs84BoundingBox = boundingBox.transform(
            projection.getTransformation(
                    ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM));

    boolean xyzTiles = false;

    // Verify the bounds are the entire world
    if (wgs84BoundingBox.getMinLatitude() <= ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE
            && wgs84BoundingBox.getMaxLatitude() >= ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE
            && wgs84BoundingBox.getMinLongitude() <= -ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH
            && wgs84BoundingBox.getMaxLongitude() >= ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH) {

        xyzTiles = true;

        // Verify each tile matrix is the correct width and height
        for (TileMatrix tileMatrix : tileMatrices) {
            long zoomLevel = tileMatrix.getZoomLevel();
            long tilesPerSide = TileBoundingBoxUtils
                    .tilesPerSide((int) zoomLevel);
            if (tileMatrix.getMatrixWidth() != tilesPerSide
                    || tileMatrix.getMatrixHeight() != tilesPerSide) {
                xyzTiles = false;
                break;
            }
        }
    }

    return xyzTiles;
}
 
Example 6
Source File: TileDao.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Determine if the tiles are in the XYZ tile coordinate format
 * 
 * @return true if XYZ tile format
 * @since 3.5.0
 */
public boolean isXYZTiles() {

	// Convert the bounding box to wgs84
	BoundingBox boundingBox = tileMatrixSet.getBoundingBox();
	BoundingBox wgs84BoundingBox = boundingBox
			.transform(projection.getTransformation(
					ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM));

	boolean xyzTiles = false;

	// Verify the bounds are the entire world
	if (wgs84BoundingBox
			.getMinLatitude() <= ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE
			&& wgs84BoundingBox
					.getMaxLatitude() >= ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE
			&& wgs84BoundingBox
					.getMinLongitude() <= -ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH
			&& wgs84BoundingBox
					.getMaxLongitude() >= ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH) {

		xyzTiles = true;

		// Verify each tile matrix is the correct width and height
		for (TileMatrix tileMatrix : tileMatrices) {
			long zoomLevel = tileMatrix.getZoomLevel();
			long tilesPerSide = TileBoundingBoxUtils
					.tilesPerSide((int) zoomLevel);
			if (tileMatrix.getMatrixWidth() != tilesPerSide
					|| tileMatrix.getMatrixHeight() != tilesPerSide) {
				xyzTiles = false;
				break;
			}
		}
	}

	return xyzTiles;
}
 
Example 7
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 8
Source File: TileDaoUtils.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * Get the zoom level for the provided width and height in the default units
 * 
 * @param widths
 *            sorted widths
 * @param heights
 *            sorted heights
 * @param tileMatrices
 *            tile matrices
 * @param width
 *            width in default units
 * @param height
 *            height in default units
 * @param lengthChecks
 *            perform length checks for values too far away from the zoom
 *            level
 * @return tile matrix zoom level
 * @since 1.2.1
 */
private static Long getZoomLevel(double[] widths, double[] heights,
		List<TileMatrix> tileMatrices, double width, double height,
		boolean lengthChecks) {

	Long zoomLevel = null;

	// Find where the width and height fit in
	int widthIndex = Arrays.binarySearch(widths, width);
	if (widthIndex < 0) {
		widthIndex = (widthIndex + 1) * -1;
	}
	int heightIndex = Arrays.binarySearch(heights, height);
	if (heightIndex < 0) {
		heightIndex = (heightIndex + 1) * -1;
	}

	// Find the closest width or verify it isn't too small or large
	if (widthIndex == 0) {
		if (lengthChecks && width < getMinLength(widths)) {
			widthIndex = -1;
		}
	} else if (widthIndex == widths.length) {
		if (lengthChecks && width >= getMaxLength(widths)) {
			widthIndex = -1;
		} else {
			widthIndex = widthIndex - 1;
		}
	} else if (closerToZoomIn(widths, width, widthIndex)) {
		widthIndex--;
	}

	// Find the closest height or verify it isn't too small or large
	if (heightIndex == 0) {
		if (lengthChecks && height < getMinLength(heights)) {
			heightIndex = -1;
		}
	} else if (heightIndex == heights.length) {
		if (lengthChecks && height >= getMaxLength(heights)) {
			heightIndex = -1;
		} else {
			heightIndex = heightIndex - 1;
		}
	} else if (closerToZoomIn(heights, height, heightIndex)) {
		heightIndex--;
	}

	if (widthIndex >= 0 || heightIndex >= 0) {

		// Use one zoom size smaller if possible
		int index;
		if (widthIndex < 0) {
			index = heightIndex;
		} else if (heightIndex < 0) {
			index = widthIndex;
		} else {
			index = Math.min(widthIndex, heightIndex);
		}

		TileMatrix tileMatrix = getTileMatrixAtLengthIndex(tileMatrices,
				index);
		zoomLevel = tileMatrix.getZoomLevel();
	}

	return zoomLevel;
}