mil.nga.geopackage.tiles.matrix.TileMatrix Java Examples

The following examples show how to use mil.nga.geopackage.tiles.matrix.TileMatrix. 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: TileDaoUtils.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Adjust the tile matrix lengths if needed. Check if the tile matrix width
 * and height need to expand to account for pixel * number of pixels fitting
 * into the tile matrix lengths
 * 
 * @param tileMatrixSet
 *            tile matrix set
 * @param tileMatrices
 *            tile matrices
 */
public static void adjustTileMatrixLengths(TileMatrixSet tileMatrixSet,
		List<TileMatrix> tileMatrices) {
	double tileMatrixWidth = tileMatrixSet.getMaxX()
			- tileMatrixSet.getMinX();
	double tileMatrixHeight = tileMatrixSet.getMaxY()
			- tileMatrixSet.getMinY();
	for (TileMatrix tileMatrix : tileMatrices) {
		int tempMatrixWidth = (int) (tileMatrixWidth / (tileMatrix
				.getPixelXSize() * tileMatrix.getTileWidth()));
		int tempMatrixHeight = (int) (tileMatrixHeight / (tileMatrix
				.getPixelYSize() * tileMatrix.getTileHeight()));
		if (tempMatrixWidth > tileMatrix.getMatrixWidth()) {
			tileMatrix.setMatrixWidth(tempMatrixWidth);
		}
		if (tempMatrixHeight > tileMatrix.getMatrixHeight()) {
			tileMatrix.setMatrixHeight(tempMatrixHeight);
		}
	}
}
 
Example #2
Source File: TileCreator.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Get the tile row results of tiles needed to draw the requested bounding box tile
 *
 * @param projectedRequestBoundingBox bounding box projected to the tiles
 * @param tileMatrix
 * @return tile cursor results or null
 */
private TileCursor retrieveTileResults(BoundingBox projectedRequestBoundingBox, TileMatrix tileMatrix) {

    TileCursor tileResults = null;

    if (tileMatrix != null) {

        // Get the tile grid
        TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
                tileSetBoundingBox, tileMatrix.getMatrixWidth(),
                tileMatrix.getMatrixHeight(), projectedRequestBoundingBox);

        // Query for matching tiles in the tile grid
        tileResults = tileDao.queryByTileGrid(tileGrid,
                tileMatrix.getZoomLevel());

    }

    return tileResults;
}
 
Example #3
Source File: XYZGeoPackageTileRetriever.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GeoPackageTile getTile(int x, int y, int zoom) {

    GeoPackageTile tile = null;

    TileRow tileRow = retrieveTileRow(x, y, zoom);
    if (tileRow != null) {
        TileMatrix tileMatrix = tileDao.getTileMatrix(zoom);
        int tileWidth = (int) tileMatrix.getTileWidth();
        int tileHeight = (int) tileMatrix.getTileHeight();
        tile = new GeoPackageTile(tileWidth, tileHeight, tileRow.getTileData());
    }

    return tile;
}
 
Example #4
Source File: TileCreator.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Get the tile row results of tiles needed to draw the requested bounding
 * box tile
 *
 * @param projectedRequestBoundingBox
 *            bounding box projected to the tiles
 * @param tileMatrix
 * @return tile cursor results or null
 */
private TileResultSet retrieveTileResults(
		BoundingBox projectedRequestBoundingBox, TileMatrix tileMatrix) {

	TileResultSet tileResults = null;

	if (tileMatrix != null) {

		// Get the tile grid
		TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
				tileSetBoundingBox, tileMatrix.getMatrixWidth(),
				tileMatrix.getMatrixHeight(), projectedRequestBoundingBox);

		// Query for matching tiles in the tile grid
		tileResults = tileDao.queryByTileGrid(tileGrid,
				tileMatrix.getZoomLevel());

	}

	return tileResults;
}
 
Example #5
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 #6
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 #7
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 or out as needed from
 * the provided tile matrix to find values
 * 
 * @param requestProjectedBoundingBox
 *            request projected bounding box
 * @param tileMatrix
 *            tile matrix
 * @param overlappingPixels
 *            overlapping request pixels
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResultsZoom(
		BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix,
		int overlappingPixels) {

	CoverageDataTileMatrixResults results = null;

	if (zoomIn && zoomInBeforeOut) {
		results = getResultsZoomIn(requestProjectedBoundingBox, tileMatrix,
				overlappingPixels);
	}
	if (results == null && zoomOut) {
		results = getResultsZoomOut(requestProjectedBoundingBox,
				tileMatrix, overlappingPixels);
	}
	if (results == null && zoomIn && !zoomInBeforeOut) {
		results = getResultsZoomIn(requestProjectedBoundingBox, tileMatrix,
				overlappingPixels);
	}

	return results;
}
 
Example #8
Source File: CoverageData.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Get the coverage data tile results for a specified tile matrix
 * 
 * @param requestProjectedBoundingBox
 *            request projected bounding box
 * @param tileMatrix
 *            tile matrix
 * @param overlappingPixels
 *            number of overlapping pixels used by the algorithm
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResults(
		BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix,
		int overlappingPixels) {
	CoverageDataTileMatrixResults results = null;
	BoundingBox paddedBoundingBox = padBoundingBox(tileMatrix,
			requestProjectedBoundingBox, overlappingPixels);
	TileResultSet tileResults = retrieveSortedTileResults(
			paddedBoundingBox, tileMatrix);
	if (tileResults != null) {
		if (tileResults.getCount() > 0) {
			results = new CoverageDataTileMatrixResults(tileMatrix,
					tileResults);
		} else {
			tileResults.close();
		}
	}
	return results;
}
 
Example #9
Source File: CoverageData.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Get the coverage data tile results by finding the tile matrix with values
 * 
 * @param request
 *            coverage data request
 * @param requestProjectedBoundingBox
 *            request projected bounding box
 * @param overlappingPixels
 *            overlapping request pixels
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResults(
		CoverageDataRequest request,
		BoundingBox requestProjectedBoundingBox, int overlappingPixels) {
	// Try to get the coverage data from the current zoom level
	TileMatrix tileMatrix = getTileMatrix(request);
	CoverageDataTileMatrixResults results = null;
	if (tileMatrix != null) {
		results = getResults(requestProjectedBoundingBox, tileMatrix,
				overlappingPixels);

		// Try to zoom in or out to find a matching coverage data
		if (results == null) {
			results = getResultsZoom(requestProjectedBoundingBox,
					tileMatrix, overlappingPixels);
		}
	}
	return results;
}
 
Example #10
Source File: GeoPackageTextOutput.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * Text output from a Tile Matrix
 * 
 * @param tileMatrix
 *            tile matrix
 * @return text
 */
public String textOutput(TileMatrix tileMatrix) {
	StringBuilder output = new StringBuilder();
	output.append("\t" + TileMatrix.COLUMN_TABLE_NAME + ": "
			+ tileMatrix.getTableName());
	output.append("\n\t" + TileMatrix.COLUMN_ZOOM_LEVEL + ": "
			+ tileMatrix.getZoomLevel());
	output.append("\n\t" + TileMatrix.COLUMN_MATRIX_WIDTH + ": "
			+ tileMatrix.getMatrixWidth());
	output.append("\n\t" + TileMatrix.COLUMN_MATRIX_HEIGHT + ": "
			+ tileMatrix.getMatrixHeight());
	output.append("\n\t" + TileMatrix.COLUMN_TILE_WIDTH + ": "
			+ tileMatrix.getTileWidth());
	output.append("\n\t" + TileMatrix.COLUMN_TILE_HEIGHT + ": "
			+ tileMatrix.getTileHeight());
	output.append("\n\t" + TileMatrix.COLUMN_PIXEL_X_SIZE + ": "
			+ tileMatrix.getPixelXSize());
	output.append("\n\t" + TileMatrix.COLUMN_PIXEL_Y_SIZE + ": "
			+ tileMatrix.getPixelYSize());
	return output.toString();
}
 
Example #11
Source File: CoverageData.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Get the tile row results of coverage data tiles needed to create the
 * requested bounding box coverage data, sorted by row and then column
 *
 * @param projectedRequestBoundingBox bounding box projected to the coverage data
 * @param tileMatrix                  tile matrix
 * @return tile results or null
 */
private TileCursor retrieveSortedTileResults(
        BoundingBox projectedRequestBoundingBox, TileMatrix tileMatrix) {

    TileCursor tileResults = null;

    if (tileMatrix != null) {

        // Get the tile grid
        TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
                coverageBoundingBox, tileMatrix.getMatrixWidth(),
                tileMatrix.getMatrixHeight(), projectedRequestBoundingBox);

        // Query for matching tiles in the tile grid
        tileResults = tileDao.queryByTileGrid(tileGrid,
                tileMatrix.getZoomLevel(), TileTable.COLUMN_TILE_ROW + ","
                        + TileTable.COLUMN_TILE_COLUMN);

    }

    return tileResults;
}
 
Example #12
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 #13
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 #14
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 or out as needed from the
 * provided tile matrix to find values
 *
 * @param requestProjectedBoundingBox request projected bounding box
 * @param tileMatrix                  tile matrix
 * @param overlappingPixels           overlapping request pixels
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResultsZoom(
        BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix,
        int overlappingPixels) {

    CoverageDataTileMatrixResults results = null;

    if (zoomIn && zoomInBeforeOut) {
        results = getResultsZoomIn(requestProjectedBoundingBox, tileMatrix,
                overlappingPixels);
    }
    if (results == null && zoomOut) {
        results = getResultsZoomOut(requestProjectedBoundingBox,
                tileMatrix, overlappingPixels);
    }
    if (results == null && zoomIn && !zoomInBeforeOut) {
        results = getResultsZoomIn(requestProjectedBoundingBox, tileMatrix,
                overlappingPixels);
    }

    return results;
}
 
Example #15
Source File: CoverageData.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Get the coverage data tile results for a specified tile matrix
 *
 * @param requestProjectedBoundingBox request projected bounding box
 * @param tileMatrix                  tile matrix
 * @param overlappingPixels           number of overlapping pixels used by the algorithm
 * @return tile matrix results
 */
private CoverageDataTileMatrixResults getResults(
        BoundingBox requestProjectedBoundingBox, TileMatrix tileMatrix,
        int overlappingPixels) {
    CoverageDataTileMatrixResults results = null;
    BoundingBox paddedBoundingBox = padBoundingBox(tileMatrix,
            requestProjectedBoundingBox, overlappingPixels);
    TileCursor tileResults = retrieveSortedTileResults(
            paddedBoundingBox, tileMatrix);
    if (tileResults != null) {
        if (tileResults.getCount() > 0) {
            results = new CoverageDataTileMatrixResults(tileMatrix,
                    tileResults);
        } else {
            tileResults.close();
        }
    }
    return results;
}
 
Example #16
Source File: TileDaoUtils.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Get the approximate zoom level for the provided width and height in the
 * default units. Tiles may or may not exist for the returned zoom level.
 * The approximate zoom level is determined using a factor of 2 from the
 * zoom levels with tiles.
 * 
 * @param widths
 *            sorted widths
 * @param heights
 *            sorted heights
 * @param tileMatrices
 *            tile matrices
 * @param width
 *            width in default units
 * @param height
 *            height in default units
 * @return actual or approximate tile matrix zoom level
 * @since 2.0.2
 */
public static Long getApproximateZoomLevel(double[] widths,
		double[] heights, List<TileMatrix> tileMatrices, double width,
		double height) {

	Long widthZoomLevel = getApproximateZoomLevel(widths, tileMatrices,
			width);
	Long heightZoomLevel = getApproximateZoomLevel(heights, tileMatrices,
			height);

	Long expectedZoomLevel;
	if (widthZoomLevel == null) {
		expectedZoomLevel = heightZoomLevel;
	} else if (heightZoomLevel == null) {
		expectedZoomLevel = widthZoomLevel;
	} else {
		expectedZoomLevel = Math.max(widthZoomLevel, heightZoomLevel);
	}

	return expectedZoomLevel;
}
 
Example #17
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createTileMatrixTable() {
	verifyWritable();

	boolean created = false;
	TileMatrixDao dao = getTileMatrixDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createTileMatrix() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + TileMatrix.class.getSimpleName()
						+ " table exists and create it",
				e);
	}
	return created;
}
 
Example #18
Source File: GeoPackageDaoManager.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * Unregister all GeoPackage DAO with the connection source
 * 
 * @param connectionSource
 *            connection source
 */
public static void unregisterDaos(ConnectionSource connectionSource) {
	// TODO when ormlite-core version > 5.1 is released, replace with:
	// "DaoManager.unregisterDaos(connectionSource);"
	// See https://github.com/j256/ormlite-core/pull/149
	unregisterDao(connectionSource, Contents.class,
			SpatialReferenceSystem.class,
			SpatialReferenceSystemSfSql.class,
			SpatialReferenceSystemSqlMm.class, Extensions.class,
			GriddedCoverage.class, GriddedTile.class, GeometryIndex.class,
			TableIndex.class, FeatureTileLink.class,
			ExtendedRelation.class, TileScaling.class,
			GeometryColumns.class, GeometryColumnsSfSql.class,
			GeometryColumnsSqlMm.class, Metadata.class,
			MetadataReference.class, DataColumns.class,
			DataColumnConstraints.class, TileMatrix.class,
			TileMatrixSet.class, ContentsId.class);
}
 
Example #19
Source File: CoverageDataCore.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Pad the bounding box with extra space for the overlapping pixels
 * 
 * @param tileMatrix
 *            tile matrix
 * @param boundingBox
 *            bounding box
 * @param overlap
 *            overlapping pixels
 * @return padded bounding box
 */
protected BoundingBox padBoundingBox(TileMatrix tileMatrix,
		BoundingBox boundingBox, int overlap) {
	double lonPixelPadding = tileMatrix.getPixelXSize() * overlap;
	double latPixelPadding = tileMatrix.getPixelYSize() * overlap;
	BoundingBox paddedBoundingBox = new BoundingBox(
			boundingBox.getMinLongitude() - lonPixelPadding,
			boundingBox.getMinLatitude() - latPixelPadding,
			boundingBox.getMaxLongitude() + lonPixelPadding,
			boundingBox.getMaxLatitude() + latPixelPadding);
	return paddedBoundingBox;
}
 
Example #20
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 #21
Source File: TileDao.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the bounding box of tiles
 * 
 * @param zoomLevel
 *            zoom level
 * @return bounding box of zoom level, or null if no tiles
 * @since 1.1.1
 */
public BoundingBox getBoundingBox(long zoomLevel) {
	BoundingBox boundingBox = null;
	TileMatrix tileMatrix = getTileMatrix(zoomLevel);
	if (tileMatrix != null) {
		TileGrid tileGrid = queryForTileGrid(zoomLevel);
		if (tileGrid != null) {
			BoundingBox matrixSetBoundingBox = getBoundingBox();
			boundingBox = TileBoundingBoxUtils.getBoundingBox(
					matrixSetBoundingBox, tileMatrix, tileGrid);
		}

	}
	return boundingBox;
}
 
Example #22
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 #23
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 #24
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 #25
Source File: CoverageData.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the tile matrix for the zoom level as defined by the area of the
 * request
 *
 * @param request coverage data request
 * @return tile matrix or null
 */
private TileMatrix getTileMatrix(CoverageDataRequest request) {

    TileMatrix tileMatrix = null;

    // Check if the request overlaps coverage data bounding box
    if (request.overlap(coverageBoundingBox) != null) {

        // Get the tile distance
        BoundingBox projectedBoundingBox = request
                .getProjectedBoundingBox();
        double distanceWidth = projectedBoundingBox.getMaxLongitude()
                - projectedBoundingBox.getMinLongitude();
        double distanceHeight = projectedBoundingBox.getMaxLatitude()
                - projectedBoundingBox.getMinLatitude();

        // Get the zoom level to request based upon the tile size
        Long zoomLevel = tileDao.getClosestZoomLevel(distanceWidth,
                distanceHeight);

        // If there is a matching zoom level
        if (zoomLevel != null) {
            tileMatrix = tileDao.getTileMatrix(zoomLevel);
        }
    }

    return tileMatrix;
}
 
Example #26
Source File: TileDao.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the bounding box of tiles
 *
 * @param zoomLevel zoom level
 * @return bounding box of zoom level, or null if no tiles
 * @since 1.1.1
 */
public BoundingBox getBoundingBox(long zoomLevel) {
    BoundingBox boundingBox = null;
    TileMatrix tileMatrix = getTileMatrix(zoomLevel);
    if (tileMatrix != null) {
        TileGrid tileGrid = queryForTileGrid(zoomLevel);
        if (tileGrid != null) {
            BoundingBox matrixSetBoundingBox = getBoundingBox();
            boundingBox = TileBoundingBoxUtils.getBoundingBox(
                    matrixSetBoundingBox, tileMatrix, tileGrid);
        }

    }
    return boundingBox;
}
 
Example #27
Source File: ContentsDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get or create a Tile Matrix DAO
 * 
 * @return tile matrix dao
 * @throws SQLException
 *             upon dao creation failure
 */
private TileMatrixDao getTileMatrixDao() throws SQLException {
	if (tileMatrixDao == null) {
		tileMatrixDao = DaoManager.createDao(connectionSource,
				TileMatrix.class);
	}
	return tileMatrixDao;
}
 
Example #28
Source File: CoverageData.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the tile matrix for the zoom level as defined by the area of the
 * request
 *
 * @param request
 *            coverage data request
 * @return tile matrix or null
 */
private TileMatrix getTileMatrix(CoverageDataRequest request) {

	TileMatrix tileMatrix = null;

	// Check if the request overlaps coverage data bounding box
	if (request.overlap(coverageBoundingBox) != null) {

		// Get the tile distance
		BoundingBox projectedBoundingBox = request
				.getProjectedBoundingBox();
		double distanceWidth = projectedBoundingBox.getMaxLongitude()
				- projectedBoundingBox.getMinLongitude();
		double distanceHeight = projectedBoundingBox.getMaxLatitude()
				- projectedBoundingBox.getMinLatitude();

		// Get the zoom level to request based upon the tile size
		Long zoomLevel = tileDao.getClosestZoomLevel(distanceWidth,
				distanceHeight);

		// If there is a matching zoom level
		if (zoomLevel != null) {
			tileMatrix = tileDao.getTileMatrix(zoomLevel);
		}
	}

	return tileMatrix;
}
 
Example #29
Source File: TestSetupTeardown.java    From geopackage-android-map with MIT License 4 votes vote down vote up
/**
 * Set up create for tiles test
 * 
 * @param testContext
 * @param geoPackage
 * @throws SQLException
 * @throws IOException
 */
private static void setUpCreateTiles(Context testContext,
		GeoPackage geoPackage) throws SQLException, IOException {

	// Get existing SRS objects
	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();

	SpatialReferenceSystem epsgSrs = srsDao.queryForId(4326l);

	TestCase.assertNotNull(epsgSrs);

	// Create the Tile Matrix Set and Tile Matrix tables
	geoPackage.createTileMatrixSetTable();
	geoPackage.createTileMatrixTable();

	// Create new Contents
	ContentsDao contentsDao = geoPackage.getContentsDao();

	Contents contents = new Contents();
	contents.setTableName("test_tiles");
	contents.setDataType(ContentsDataType.TILES);
	contents.setIdentifier("test_tiles");
	// contents.setDescription("");
	// contents.setLastChange(new Date());
	contents.setMinX(-180.0);
	contents.setMinY(-90.0);
	contents.setMaxX(180.0);
	contents.setMaxY(90.0);
	contents.setSrs(epsgSrs);

	// Create the user tile table
	TileTable tileTable = TestUtils.buildTileTable(contents.getTableName());
	geoPackage.createTileTable(tileTable);

	// Create the contents
	contentsDao.create(contents);

	// Create new Tile Matrix Set
	TileMatrixSetDao tileMatrixSetDao = geoPackage.getTileMatrixSetDao();

	TileMatrixSet tileMatrixSet = new TileMatrixSet();
	tileMatrixSet.setContents(contents);
	tileMatrixSet.setSrs(contents.getSrs());
	tileMatrixSet.setMinX(contents.getMinX());
	tileMatrixSet.setMinY(contents.getMinY());
	tileMatrixSet.setMaxX(contents.getMaxX());
	tileMatrixSet.setMaxY(contents.getMaxY());
	tileMatrixSetDao.create(tileMatrixSet);

	// Create new Tile Matrix rows
	TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

	int matrixWidthAndHeight = 2;
	double pixelXSize = 69237.2;
	double pixelYSize = 68412.1;

	// Read the asset tile to bytes and convert to bitmap
	byte[] assetTileData = TestUtils.getAssetFileBytes(testContext,
			TestConstants.TILE_FILE_NAME);
	Bitmap bitmap = BitmapConverter.toBitmap(assetTileData);

	// Get the width and height of the bitmap
	final int tileWidth = bitmap.getWidth();
	final int tileHeight = bitmap.getHeight();

	// Compress the bitmap back to bytes and use those for the test
	byte[] tileData = BitmapConverter.toBytes(bitmap, CompressFormat
			.valueOf(TestConstants.TILE_FILE_NAME_EXTENSION.toUpperCase()));

	for (int zoom = 0; zoom < CREATE_TILE_MATRIX_COUNT; zoom++) {

		TileMatrix tileMatrix = new TileMatrix();
		tileMatrix.setContents(contents);
		tileMatrix.setZoomLevel(zoom);
		tileMatrix.setMatrixWidth(matrixWidthAndHeight);
		tileMatrix.setMatrixHeight(matrixWidthAndHeight);
		tileMatrix.setTileWidth(tileWidth);
		tileMatrix.setTileHeight(tileHeight);
		tileMatrix.setPixelXSize(pixelXSize);
		tileMatrix.setPixelYSize(pixelYSize);
		tileMatrixDao.create(tileMatrix);

		matrixWidthAndHeight *= 2;
		pixelXSize /= 2.0;
		pixelYSize /= 2.0;

		// Populate the tile table with rows
		TestUtils.addRowsToTileTable(geoPackage, tileMatrix, tileData);
	}

}
 
Example #30
Source File: TestUtils.java    From geopackage-java 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);
		}

	}

}