mil.nga.geopackage.extension.coverage.GriddedTile Java Examples

The following examples show how to use mil.nga.geopackage.extension.coverage.GriddedTile. 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: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean createGriddedTileTable() {
	verifyWritable();

	boolean created = false;
	GriddedTileDao dao = getGriddedTileDao();
	try {
		if (!dao.isTableExists()) {
			created = tableCreator.createGriddedTile() > 0;
		}
	} catch (SQLException e) {
		throw new GeoPackageException(
				"Failed to check if " + GriddedTile.class.getSimpleName()
						+ " table exists and create it",
				e);
	}
	return created;
}
 
Example #2
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 #3
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 #4
Source File: CreateCoverageDataTiffGeoPackageTestCase.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Draw a coverage data tile with random values
 *
 * @param coverageData
 * @param tileWidth
 * @param tileHeight
 * @param griddedCoverage
 * @param commonGriddedTile
 * @return
 */
private byte[] drawTile(CoverageDataTiff coverageData, int tileWidth,
                        int tileHeight, GriddedCoverage griddedCoverage,
                        GriddedTile commonGriddedTile) {

    coverageDataValues.tilePixels = new float[tileHeight][tileWidth];
    coverageDataValues.coverageData = new Double[tileHeight][tileWidth];
    coverageDataValues.tilePixelsFlat = new float[tileHeight * tileWidth];
    coverageDataValues.coverageDataFlat = new Double[tileHeight
            * tileWidth];

    GriddedTile griddedTile = new GriddedTile();
    griddedTile.setScale(commonGriddedTile.getScale());
    griddedTile.setOffset(commonGriddedTile.getOffset());
    griddedTile.setMin(commonGriddedTile.getMin());
    griddedTile.setMax(commonGriddedTile.getMax());
    griddedTile.setMean(commonGriddedTile.getMean());
    griddedTile.setStandardDeviation(commonGriddedTile
            .getStandardDeviation());

    float minValue = 8850.0f;
    float maxValue = 10994.0f;

    // Create the image and graphics
    for (int x = 0; x < tileWidth; x++) {
        for (int y = 0; y < tileHeight; y++) {
            float value;
            if (allowNulls && Math.random() < .05) {
                value = griddedCoverage.getDataNull().floatValue();
            } else {
                value = (float) ((Math.random() * (maxValue - minValue)) + minValue);
            }

            coverageDataValues.tilePixels[y][x] = value;
            coverageDataValues.coverageData[y][x] = coverageData
                    .getValue(griddedTile, value);

            coverageDataValues.tilePixelsFlat[(y * tileWidth) + x] = coverageDataValues.tilePixels[y][x];
            coverageDataValues.coverageDataFlat[(y * tileWidth) + x] = coverageDataValues.coverageData[y][x];
        }
    }

    byte[] imageData = coverageData
            .drawTileData(coverageDataValues.tilePixels);

    // GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
    // .drawTileData(griddedTile, coverageDataValues.coverageData));
    GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
            .drawTileData(coverageDataValues.tilePixelsFlat, tileWidth,
                    tileHeight));
    // GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
    // .drawTileData(griddedTile, coverageDataValues.coverageDataFlat,
    // tileWidth, tileHeight));

    return imageData;
}
 
Example #5
Source File: GeoPackageExample.java    From geopackage-android with MIT License 4 votes vote down vote up
private static void createCoverageDataPngExtension(GeoPackage geoPackage)
        throws SQLException {

    BoundingBox bbox = new BoundingBox(-11667347.997449303,
            4824705.2253603265, -11666125.00499674, 4825928.217812888);

    int contentsEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;
    int tileMatrixSetEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;

    SpatialReferenceSystemDao srsDao = geoPackage
            .getSpatialReferenceSystemDao();
    srsDao.getOrCreateFromEpsg(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM_GEOGRAPHICAL_3D);

    SpatialReferenceSystem contentsSrs = srsDao
            .getOrCreateFromEpsg(contentsEpsg);
    SpatialReferenceSystem tileMatrixSetSrs = srsDao
            .getOrCreateFromEpsg(tileMatrixSetEpsg);

    ProjectionTransform transform = tileMatrixSetSrs.getProjection()
            .getTransformation(contentsSrs.getProjection());
    BoundingBox contentsBoundingBox = bbox;
    if (!transform.isSameProjection()) {
        contentsBoundingBox = bbox.transform(transform);
    }

    CoverageDataPng coverageData = CoverageDataPng
            .createTileTableWithMetadata(geoPackage, "coverage_png",
                    contentsBoundingBox, contentsSrs.getId(), bbox,
                    tileMatrixSetSrs.getId());
    TileDao tileDao = coverageData.getTileDao();
    TileMatrixSet tileMatrixSet = coverageData.getTileMatrixSet();

    GriddedCoverageDao griddedCoverageDao = coverageData
            .getGriddedCoverageDao();

    GriddedCoverage griddedCoverage = new GriddedCoverage();
    griddedCoverage.setTileMatrixSet(tileMatrixSet);
    griddedCoverage.setDataType(GriddedCoverageDataType.INTEGER);
    griddedCoverage.setDataNull(new Double(Short.MAX_VALUE
            - Short.MIN_VALUE));
    griddedCoverage
            .setGridCellEncodingType(GriddedCoverageEncodingType.CENTER);
    griddedCoverageDao.create(griddedCoverage);

    GriddedTileDao griddedTileDao = coverageData.getGriddedTileDao();

    int width = 1;
    int height = 1;
    int tileWidth = 3;
    int tileHeight = 3;

    short[][] tilePixels = new short[tileHeight][tileWidth];

    tilePixels[0][0] = (short) 1661.95;
    tilePixels[0][1] = (short) 1665.40;
    tilePixels[0][2] = (short) 1668.19;
    tilePixels[1][0] = (short) 1657.18;
    tilePixels[1][1] = (short) 1663.39;
    tilePixels[1][2] = (short) 1669.65;
    tilePixels[2][0] = (short) 1654.78;
    tilePixels[2][1] = (short) 1660.31;
    tilePixels[2][2] = (short) 1666.44;

    byte[] imageBytes = coverageData.drawTileData(tilePixels);

    TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

    TileMatrix tileMatrix = new TileMatrix();
    tileMatrix.setContents(tileMatrixSet.getContents());
    tileMatrix.setMatrixHeight(height);
    tileMatrix.setMatrixWidth(width);
    tileMatrix.setTileHeight(tileHeight);
    tileMatrix.setTileWidth(tileWidth);
    tileMatrix.setPixelXSize((bbox.getMaxLongitude() - bbox
            .getMinLongitude()) / width / tileWidth);
    tileMatrix
            .setPixelYSize((bbox.getMaxLatitude() - bbox.getMinLatitude())
                    / height / tileHeight);
    tileMatrix.setZoomLevel(15);
    tileMatrixDao.create(tileMatrix);

    TileRow tileRow = tileDao.newRow();
    tileRow.setTileColumn(0);
    tileRow.setTileRow(0);
    tileRow.setZoomLevel(tileMatrix.getZoomLevel());
    tileRow.setTileData(imageBytes);

    long tileId = tileDao.create(tileRow);

    GriddedTile griddedTile = new GriddedTile();
    griddedTile.setContents(tileMatrixSet.getContents());
    griddedTile.setTableId(tileId);

    griddedTileDao.create(griddedTile);

}
 
Example #6
Source File: CreateCoverageDataGeoPackageTestCase.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Draw an coverage data tile with random values
 *
 * @param coverageData
 * @param tileWidth
 * @param tileHeight
 * @param griddedCoverage
 * @param commonGriddedTile
 * @return
 */
private byte[] drawTile(CoverageDataPng coverageData, int tileWidth,
                        int tileHeight, GriddedCoverage griddedCoverage,
                        GriddedTile commonGriddedTile) {

    coverageDataValues.tilePixels = new short[tileHeight][tileWidth];
    coverageDataValues.tileUnsignedPixels = new int[tileHeight][tileWidth];
    coverageDataValues.coverageData = new Double[tileHeight][tileWidth];
    coverageDataValues.tilePixelsFlat = new short[tileHeight * tileWidth];
    coverageDataValues.tileUnsignedPixelsFlat = new int[tileHeight
            * tileWidth];
    coverageDataValues.coverageDataFlat = new Double[tileHeight
            * tileWidth];

    GriddedTile griddedTile = new GriddedTile();
    griddedTile.setScale(commonGriddedTile.getScale());
    griddedTile.setOffset(commonGriddedTile.getOffset());
    griddedTile.setMin(commonGriddedTile.getMin());
    griddedTile.setMax(commonGriddedTile.getMax());
    griddedTile.setMean(commonGriddedTile.getMean());
    griddedTile.setStandardDeviation(commonGriddedTile
            .getStandardDeviation());

    // Create the image and graphics
    for (int x = 0; x < tileWidth; x++) {
        for (int y = 0; y < tileHeight; y++) {
            int unsignedValue;
            if (allowNulls && Math.random() < .05) {
                unsignedValue = griddedCoverage.getDataNull().intValue();
            } else {
                unsignedValue = Short.MAX_VALUE - Short.MIN_VALUE - 1;
                unsignedValue = (int) Math.floor(Math.random()
                        * unsignedValue);
            }
            short value = (short) unsignedValue;

            coverageDataValues.tilePixels[y][x] = value;
            coverageDataValues.tileUnsignedPixels[y][x] = unsignedValue;
            coverageDataValues.coverageData[y][x] = coverageData
                    .getValue(griddedTile, value);

            coverageDataValues.tilePixelsFlat[(y * tileWidth) + x] = coverageDataValues.tilePixels[y][x];
            coverageDataValues.tileUnsignedPixelsFlat[(y * tileWidth) + x] = coverageDataValues.tileUnsignedPixels[y][x];
            coverageDataValues.coverageDataFlat[(y * tileWidth) + x] = coverageDataValues.coverageData[y][x];
        }
    }

    byte[] imageData = coverageData
            .drawTileData(coverageDataValues.tilePixels);

    GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
            .drawTileData(coverageDataValues.tileUnsignedPixels));
    GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
            .drawTileData(griddedTile, coverageDataValues.coverageData));
    GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
            .drawTileData(coverageDataValues.tilePixelsFlat, tileWidth,
                    tileHeight));
    GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
            .drawTileData(coverageDataValues.tileUnsignedPixelsFlat,
                    tileWidth, tileHeight));
    GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
            .drawTileData(griddedTile,
                    coverageDataValues.coverageDataFlat, tileWidth,
                    tileHeight));

    return imageData;
}
 
Example #7
Source File: GeoPackageExtensions.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * Copy the Gridded Coverage extensions for the table
 * 
 * @param geoPackage
 *            GeoPackage
 * @param table
 *            table name
 * @param newTable
 *            new table name
 * @since 3.3.0
 */
public static void copyGriddedCoverage(GeoPackageCore geoPackage,
		String table, String newTable) {

	try {

		if (geoPackage.isTableType(ContentsDataType.GRIDDED_COVERAGE,
				table)) {

			ExtensionsDao extensionsDao = geoPackage.getExtensionsDao();

			if (extensionsDao.isTableExists()) {

				List<Extensions> extensions = extensionsDao
						.queryByExtension(CoverageDataCore.EXTENSION_NAME,
								table);

				if (!extensions.isEmpty()) {

					Extensions extension = extensions.get(0);
					extension.setTableName(newTable);
					extensionsDao.create(extension);

					GriddedCoverageDao griddedCoverageDao = geoPackage
							.getGriddedCoverageDao();
					if (griddedCoverageDao.isTableExists()) {

						CoreSQLUtils.transferTableContent(
								geoPackage.getDatabase(),
								GriddedCoverage.TABLE_NAME,
								GriddedCoverage.COLUMN_TILE_MATRIX_SET_NAME,
								newTable, table, GriddedCoverage.COLUMN_ID);

					}

					GriddedTileDao griddedTileDao = geoPackage
							.getGriddedTileDao();
					if (griddedTileDao.isTableExists()) {

						CoreSQLUtils.transferTableContent(
								geoPackage.getDatabase(),
								GriddedTile.TABLE_NAME,
								GriddedTile.COLUMN_TABLE_NAME, newTable,
								table, GriddedTile.COLUMN_ID);

					}
				}
			}
		}

	} catch (Exception e) {
		logger.log(Level.WARNING,
				"Failed to create Gridded Coverage for table: " + newTable
						+ ", copied from table: " + table,
				e);
	}

}
 
Example #8
Source File: GeoPackageCoreImpl.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public GriddedTileDao getGriddedTileDao() {
	return createDao(GriddedTile.class);
}
 
Example #9
Source File: CreateCoverageDataTiffGeoPackageTestCase.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Draw a coverage data tile with random values
 * 
 * @param coverageData
 * @param tileWidth
 * @param tileHeight
 * @param griddedCoverage
 * @param commonGriddedTile
 * @return
 */
private byte[] drawTile(CoverageDataTiff coverageData, int tileWidth,
		int tileHeight, GriddedCoverage griddedCoverage,
		GriddedTile commonGriddedTile) {

	coverageDataValues.tilePixels = new float[tileHeight][tileWidth];
	coverageDataValues.coverageData = new Double[tileHeight][tileWidth];
	coverageDataValues.tilePixelsFlat = new float[tileHeight * tileWidth];
	coverageDataValues.coverageDataFlat = new Double[tileHeight * tileWidth];

	GriddedTile griddedTile = new GriddedTile();
	griddedTile.setScale(commonGriddedTile.getScale());
	griddedTile.setOffset(commonGriddedTile.getOffset());
	griddedTile.setMin(commonGriddedTile.getMin());
	griddedTile.setMax(commonGriddedTile.getMax());
	griddedTile.setMean(commonGriddedTile.getMean());
	griddedTile.setStandardDeviation(commonGriddedTile
			.getStandardDeviation());

	float minValue = 8850.0f;
	float maxValue = 10994.0f;

	// Create the image and graphics
	for (int x = 0; x < tileWidth; x++) {
		for (int y = 0; y < tileHeight; y++) {
			float value;
			if (allowNulls && Math.random() < .05) {
				value = griddedCoverage.getDataNull().floatValue();
			} else {
				value = (float) ((Math.random() * (maxValue - minValue)) + minValue);
			}

			coverageDataValues.tilePixels[y][x] = value;
			coverageDataValues.coverageData[y][x] = coverageData.getValue(
					griddedTile, value);

			coverageDataValues.tilePixelsFlat[(y * tileWidth) + x] = coverageDataValues.tilePixels[y][x];
			coverageDataValues.coverageDataFlat[(y * tileWidth) + x] = coverageDataValues.coverageData[y][x];
		}
	}

	byte[] imageData = coverageData
			.drawTileData(coverageDataValues.tilePixels);

	// GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
	// .drawTileData(griddedTile, coverageDataValues.coverageData));
	GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
			.drawTileData(coverageDataValues.tilePixelsFlat, tileWidth,
					tileHeight));
	// GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
	// .drawTileData(griddedTile, coverageDataValues.coverageDataFlat,
	// tileWidth, tileHeight));

	return imageData;
}
 
Example #10
Source File: GeoPackageExample.java    From geopackage-java with MIT License 4 votes vote down vote up
private static void createCoverageDataPngExtension(GeoPackage geoPackage)
		throws SQLException {

	BoundingBox bbox = new BoundingBox(-11667347.997449303,
			4824705.2253603265, -11666125.00499674, 4825928.217812888);

	int contentsEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;
	int tileMatrixSetEpsg = ProjectionConstants.EPSG_WEB_MERCATOR;

	SpatialReferenceSystemDao srsDao = geoPackage
			.getSpatialReferenceSystemDao();
	srsDao.getOrCreateFromEpsg(
			ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM_GEOGRAPHICAL_3D);

	SpatialReferenceSystem contentsSrs = srsDao
			.getOrCreateFromEpsg(contentsEpsg);
	SpatialReferenceSystem tileMatrixSetSrs = srsDao
			.getOrCreateFromEpsg(tileMatrixSetEpsg);

	ProjectionTransform transform = tileMatrixSetSrs.getProjection()
			.getTransformation(contentsSrs.getProjection());
	BoundingBox contentsBoundingBox = bbox;
	if (!transform.isSameProjection()) {
		contentsBoundingBox = bbox.transform(transform);
	}

	CoverageDataPng coverageData = CoverageDataPng
			.createTileTableWithMetadata(geoPackage, "coverage_png",
					contentsBoundingBox, contentsSrs.getId(), bbox,
					tileMatrixSetSrs.getId());
	TileDao tileDao = coverageData.getTileDao();
	TileMatrixSet tileMatrixSet = coverageData.getTileMatrixSet();

	GriddedCoverageDao griddedCoverageDao = coverageData
			.getGriddedCoverageDao();

	GriddedCoverage griddedCoverage = new GriddedCoverage();
	griddedCoverage.setTileMatrixSet(tileMatrixSet);
	griddedCoverage.setDataType(GriddedCoverageDataType.INTEGER);
	griddedCoverage
			.setDataNull(new Double(Short.MAX_VALUE - Short.MIN_VALUE));
	griddedCoverage
			.setGridCellEncodingType(GriddedCoverageEncodingType.CENTER);
	griddedCoverageDao.create(griddedCoverage);

	GriddedTileDao griddedTileDao = coverageData.getGriddedTileDao();

	int width = 1;
	int height = 1;
	int tileWidth = 3;
	int tileHeight = 3;

	short[][] tilePixels = new short[tileHeight][tileWidth];

	tilePixels[0][0] = (short) 1661.95;
	tilePixels[0][1] = (short) 1665.40;
	tilePixels[0][2] = (short) 1668.19;
	tilePixels[1][0] = (short) 1657.18;
	tilePixels[1][1] = (short) 1663.39;
	tilePixels[1][2] = (short) 1669.65;
	tilePixels[2][0] = (short) 1654.78;
	tilePixels[2][1] = (short) 1660.31;
	tilePixels[2][2] = (short) 1666.44;

	byte[] imageBytes = coverageData.drawTileData(tilePixels);

	TileMatrixDao tileMatrixDao = geoPackage.getTileMatrixDao();

	TileMatrix tileMatrix = new TileMatrix();
	tileMatrix.setContents(tileMatrixSet.getContents());
	tileMatrix.setMatrixHeight(height);
	tileMatrix.setMatrixWidth(width);
	tileMatrix.setTileHeight(tileHeight);
	tileMatrix.setTileWidth(tileWidth);
	tileMatrix
			.setPixelXSize((bbox.getMaxLongitude() - bbox.getMinLongitude())
					/ width / tileWidth);
	tileMatrix.setPixelYSize((bbox.getMaxLatitude() - bbox.getMinLatitude())
			/ height / tileHeight);
	tileMatrix.setZoomLevel(15);
	tileMatrixDao.create(tileMatrix);

	TileRow tileRow = tileDao.newRow();
	tileRow.setTileColumn(0);
	tileRow.setTileRow(0);
	tileRow.setZoomLevel(tileMatrix.getZoomLevel());
	tileRow.setTileData(imageBytes);

	long tileId = tileDao.create(tileRow);

	GriddedTile griddedTile = new GriddedTile();
	griddedTile.setContents(tileMatrixSet.getContents());
	griddedTile.setTableId(tileId);

	griddedTileDao.create(griddedTile);

}
 
Example #11
Source File: CreateCoverageDataGeoPackageTestCase.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Draw a coverage data tile with random values
 * 
 * @param coverage
 *            data
 * @param tileWidth
 * @param tileHeight
 * @param griddedCoverage
 * @param commonGriddedTile
 * @return
 */
private byte[] drawTile(CoverageDataPng coverageData, int tileWidth,
		int tileHeight, GriddedCoverage griddedCoverage,
		GriddedTile commonGriddedTile) {

	coverageDataValues.tilePixels = new short[tileHeight][tileWidth];
	coverageDataValues.tileUnsignedPixels = new int[tileHeight][tileWidth];
	coverageDataValues.coverageData = new Double[tileHeight][tileWidth];
	coverageDataValues.tilePixelsFlat = new short[tileHeight * tileWidth];
	coverageDataValues.tileUnsignedPixelsFlat = new int[tileHeight
			* tileWidth];
	coverageDataValues.coverageDataFlat = new Double[tileHeight * tileWidth];

	GriddedTile griddedTile = new GriddedTile();
	griddedTile.setScale(commonGriddedTile.getScale());
	griddedTile.setOffset(commonGriddedTile.getOffset());
	griddedTile.setMin(commonGriddedTile.getMin());
	griddedTile.setMax(commonGriddedTile.getMax());
	griddedTile.setMean(commonGriddedTile.getMean());
	griddedTile.setStandardDeviation(commonGriddedTile
			.getStandardDeviation());

	// Create the image and graphics
	for (int x = 0; x < tileWidth; x++) {
		for (int y = 0; y < tileHeight; y++) {
			int unsignedValue;
			if (allowNulls && Math.random() < .05) {
				unsignedValue = griddedCoverage.getDataNull().intValue();
			} else {
				unsignedValue = Short.MAX_VALUE - Short.MIN_VALUE - 1;
				unsignedValue = (int) Math.floor(Math.random()
						* unsignedValue);
			}
			short value = (short) unsignedValue;

			coverageDataValues.tilePixels[y][x] = value;
			coverageDataValues.tileUnsignedPixels[y][x] = unsignedValue;
			coverageDataValues.coverageData[y][x] = coverageData.getValue(
					griddedTile, value);

			coverageDataValues.tilePixelsFlat[(y * tileWidth) + x] = coverageDataValues.tilePixels[y][x];
			coverageDataValues.tileUnsignedPixelsFlat[(y * tileWidth) + x] = coverageDataValues.tileUnsignedPixels[y][x];
			coverageDataValues.coverageDataFlat[(y * tileWidth) + x] = coverageDataValues.coverageData[y][x];
		}
	}

	byte[] imageData = coverageData
			.drawTileData(coverageDataValues.tilePixels);

	GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
			.drawTileData(coverageDataValues.tileUnsignedPixels));
	GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
			.drawTileData(griddedTile, coverageDataValues.coverageData));
	GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
			.drawTileData(coverageDataValues.tilePixelsFlat, tileWidth,
					tileHeight));
	GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
			.drawTileData(coverageDataValues.tileUnsignedPixelsFlat,
					tileWidth, tileHeight));
	GeoPackageGeometryDataUtils.compareByteArrays(imageData, coverageData
			.drawTileData(griddedTile, coverageDataValues.coverageDataFlat,
					tileWidth, tileHeight));

	return imageData;
}