Java Code Examples for mil.nga.geopackage.BoundingBox#transform()

The following examples show how to use mil.nga.geopackage.BoundingBox#transform() . 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-java with MIT License 6 votes vote down vote up
/**
 * Create an expanded bounding box to handle features outside the tile that
 * overlap
 * 
 * @param boundingBox
 *            bounding box
 * @param projection
 *            bounding box projection
 * @return bounding box
 * @since 3.2.0
 */
public BoundingBox expandBoundingBox(BoundingBox boundingBox,
		Projection projection) {

	BoundingBox expandedBoundingBox = boundingBox;

	ProjectionTransform toWebMercator = projection
			.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
	if (!toWebMercator.isSameProjection()) {
		expandedBoundingBox = expandedBoundingBox.transform(toWebMercator);
	}

	expandedBoundingBox = expandBoundingBox(expandedBoundingBox);

	if (!toWebMercator.isSameProjection()) {
		ProjectionTransform fromWebMercator = toWebMercator
				.getInverseTransformation();
		expandedBoundingBox = expandedBoundingBox
				.transform(fromWebMercator);
	}

	return expandedBoundingBox;
}
 
Example 2
Source File: FeatureTileGenerator.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(int zoom) {

    ProjectionTransform projectionToWebMercator = projection
            .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
    BoundingBox webMercatorBoundingBox = boundingBox
            .transform(projectionToWebMercator);

    TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(webMercatorBoundingBox, zoom);
    BoundingBox tileBoundingBox = TileBoundingBoxUtils.getWebMercatorBoundingBox(
            tileGrid.getMinX(), tileGrid.getMinY(), zoom);

    BoundingBox expandedBoundingBox = featureTiles.expandBoundingBox(webMercatorBoundingBox, tileBoundingBox);

    BoundingBox zoomBoundingBox = expandedBoundingBox.transform(projectionToWebMercator.getInverseTransformation());

    return zoomBoundingBox;
}
 
Example 3
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 4
Source File: FeatureTiles.java    From geopackage-android with MIT License 6 votes vote down vote up
/**
 * Create an expanded bounding box to handle features outside the tile that
 * overlap
 *
 * @param boundingBox bounding box
 * @param projection  bounding box projection
 * @return bounding box
 * @since 3.2.0
 */
public BoundingBox expandBoundingBox(BoundingBox boundingBox,
                                     Projection projection) {

    BoundingBox expandedBoundingBox = boundingBox;

    ProjectionTransform toWebMercator = projection
            .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
    if (!toWebMercator.isSameProjection()) {
        expandedBoundingBox = expandedBoundingBox.transform(toWebMercator);
    }

    expandedBoundingBox = expandBoundingBox(expandedBoundingBox);

    if (!toWebMercator.isSameProjection()) {
        ProjectionTransform fromWebMercator = toWebMercator
                .getInverseTransformation();
        expandedBoundingBox = expandedBoundingBox
                .transform(fromWebMercator);
    }

    return expandedBoundingBox;
}
 
Example 5
Source File: FeatureTileGenerator.java    From geopackage-java with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(int zoom) {

	ProjectionTransform projectionToWebMercator = projection
			.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
	BoundingBox webMercatorBoundingBox = boundingBox
			.transform(projectionToWebMercator);

	TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(
			webMercatorBoundingBox, zoom);
	BoundingBox tileBoundingBox = TileBoundingBoxUtils
			.getWebMercatorBoundingBox(tileGrid.getMinX(),
					tileGrid.getMinY(), zoom);

	BoundingBox expandedBoundingBox = featureTiles.expandBoundingBox(
			webMercatorBoundingBox, tileBoundingBox);

	BoundingBox zoomBoundingBox = expandedBoundingBox
			.transform(projectionToWebMercator.getInverseTransformation());

	return zoomBoundingBox;
}
 
Example 6
Source File: FeatureTableCoreIndex.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Query for the feature index bounds and return in the provided projection
 * 
 * @param projection
 *            desired projection
 * @return bounding box
 * @since 3.1.0
 */
public BoundingBox getBoundingBox(Projection projection) {
	BoundingBox boundingBox = getBoundingBox();
	if (boundingBox != null && projection != null) {
		ProjectionTransform projectionTransform = getProjection()
				.getTransformation(projection);
		boundingBox = boundingBox.transform(projectionTransform);
	}
	return boundingBox;
}
 
Example 7
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 8
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 9
Source File: FeatureIndexer.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Get the bounding box in the feature projection from the bounding box in
 * the provided projection
 *
 * @param boundingBox bounding box
 * @param projection  projection
 * @return feature projected bounding box
 */
private BoundingBox getFeatureBoundingBox(BoundingBox boundingBox,
                                          Projection projection) {
    ProjectionTransform projectionTransform = projection
            .getTransformation(featureDao.getProjection());
    BoundingBox featureBoundingBox = boundingBox
            .transform(projectionTransform);
    return featureBoundingBox;
}
 
Example 10
Source File: ManualFeatureQuery.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Manually build the bounds of the feature table in the provided projection
 *
 * @param projection desired projection
 * @return bounding box
 */
public BoundingBox getBoundingBox(Projection projection) {
    BoundingBox boundingBox = getBoundingBox();
    if (boundingBox != null && projection != null) {
        ProjectionTransform projectionTransform = featureDao
                .getProjection().getTransformation(projection);
        boundingBox = boundingBox.transform(projectionTransform);
    }
    return boundingBox;
}
 
Example 11
Source File: RTreeIndexTableDao.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection) {
    BoundingBox boundingBox = getBoundingBox();
    if (boundingBox != null && projection != null) {
        ProjectionTransform projectionTransform = featureDao
                .getProjection().getTransformation(projection);
        boundingBox = boundingBox.transform(projectionTransform);
    }
    return boundingBox;
}
 
Example 12
Source File: BoundedOverlay.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Set the bounding box, provided as the indicated projection
 *
 * @param boundingBox bounding box
 * @param projection  projection
 */
public void setBoundingBox(BoundingBox boundingBox, Projection projection) {
    ProjectionTransform projectionToWebMercator = projection
            .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
    webMercatorBoundingBox = boundingBox
            .transform(projectionToWebMercator);
}
 
Example 13
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 14
Source File: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 5 votes vote down vote up
/**
 * Transform the bounding box in web mercator to the feature projection
 *
 * @param boundingBox bounding box in web mercator
 * @return bounding box in the feature projection
 */
public BoundingBox boundingBoxFromWebMercator(BoundingBox boundingBox) {
    if (projection == null) {
        throw new GeoPackageException("Shape Converter projection is null");
    }
    return boundingBox.transform(fromWebMercator);
}
 
Example 15
Source File: RTreeIndexTableDao.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BoundingBox getBoundingBox(Projection projection) {
	BoundingBox boundingBox = getBoundingBox();
	if (boundingBox != null && projection != null) {
		ProjectionTransform projectionTransform = featureDao.getProjection()
				.getTransformation(projection);
		boundingBox = boundingBox.transform(projectionTransform);
	}
	return boundingBox;
}
 
Example 16
Source File: CoverageDataTiffImportTest.java    From geopackage-java with MIT License 4 votes vote down vote up
/**
 * Test 10 random locations and optionally print
 * 
 * @throws Exception
 */
@Test
public void testRandomLocations() throws Exception {

	BoundingBox projectedBoundingBox = null;

	List<String> coverageDataTables = CoverageDataTiff
			.getTables(geoPackage);
	TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

	for (String coverageTable : coverageDataTables) {

		TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);

		BoundingBox boundingBox = tileMatrixSet.getBoundingBox();
		if (PRINT) {
			System.out.println("Min Latitude: "
					+ boundingBox.getMinLatitude());
			System.out.println("Max Latitude: "
					+ boundingBox.getMaxLatitude());
			System.out.println("Min Longitude: "
					+ boundingBox.getMinLongitude());
			System.out.println("Max Longitude: "
					+ boundingBox.getMaxLongitude());
			System.out.println();
		}
		SpatialReferenceSystemDao srsDao = geoPackage
				.getSpatialReferenceSystemDao();
		long srsId = tileMatrixSet.getSrsId();
		SpatialReferenceSystem srs = srsDao.queryForId(srsId);
		Projection projection = srs.getProjection();
		Projection requestProjection = ProjectionFactory
				.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
		ProjectionTransform coverageToRequest = projection
				.getTransformation(requestProjection);
		projectedBoundingBox = boundingBox.transform(coverageToRequest);

	}
	if (PRINT) {
		System.out.println("Min Latitude: "
				+ projectedBoundingBox.getMinLatitude());
		System.out.println("Max Latitude: "
				+ projectedBoundingBox.getMaxLatitude());
		System.out.println("Min Longitude: "
				+ projectedBoundingBox.getMinLongitude());
		System.out.println("Max Longitude: "
				+ projectedBoundingBox.getMaxLongitude());
		System.out.println();
	}

	double latDistance = projectedBoundingBox.getMaxLatitude()
			- projectedBoundingBox.getMinLatitude();
	double lonDistance = projectedBoundingBox.getMaxLongitude()
			- projectedBoundingBox.getMinLongitude();

	for (int i = 0; i < 10; i++) {

		// Get a random coordinate
		double latitude = latDistance * .9 * Math.random()
				+ projectedBoundingBox.getMinLatitude()
				+ (.05 * latDistance);
		double longitude = lonDistance * .9 * Math.random()
				+ projectedBoundingBox.getMinLongitude()
				+ (.05 * lonDistance);
		testLocation(latitude, longitude);
		if (PRINT) {
			System.out.println();
		}
	}
}
 
Example 17
Source File: TileCreator.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Get the tile from the request bounding box in the request projection
 *
 * @param requestBoundingBox request bounding box in the request projection
 * @return tile
 */
public GeoPackageTile getTile(BoundingBox requestBoundingBox) {

    GeoPackageTile tile = null;

    // Transform to the projection of the tiles
    ProjectionTransform transformRequestToTiles = requestProjection.getTransformation(tilesProjection);
    BoundingBox tilesBoundingBox = requestBoundingBox.transform(transformRequestToTiles);

    List<TileMatrix> tileMatrices = getTileMatrices(tilesBoundingBox);

    for (int i = 0; tile == null && i < tileMatrices.size(); i++) {

        TileMatrix tileMatrix = tileMatrices.get(i);

        TileCursor tileResults = retrieveTileResults(tilesBoundingBox, tileMatrix);
        if (tileResults != null) {

            try {

                if (tileResults.getCount() > 0) {

                    BoundingBox requestProjectedBoundingBox = requestBoundingBox.transform(transformRequestToTiles);

                    // Determine the requested tile dimensions, or use the dimensions of a single tile matrix tile
                    int requestedTileWidth = width != null ? width : (int) tileMatrix
                            .getTileWidth();
                    int requestedTileHeight = height != null ? height : (int) tileMatrix
                            .getTileHeight();

                    // Determine the size of the tile to initially draw
                    int tileWidth = requestedTileWidth;
                    int tileHeight = requestedTileHeight;
                    if (!sameProjection) {
                        tileWidth = (int) Math.round(
                                (requestProjectedBoundingBox.getMaxLongitude() - requestProjectedBoundingBox.getMinLongitude())
                                        / tileMatrix.getPixelXSize());
                        tileHeight = (int) Math.round(
                                (requestProjectedBoundingBox.getMaxLatitude() - requestProjectedBoundingBox.getMinLatitude())
                                        / tileMatrix.getPixelYSize());
                    }

                    // Draw the resulting bitmap with the matching tiles
                    Bitmap tileBitmap = drawTile(tileMatrix, tileResults, requestProjectedBoundingBox, tileWidth, tileHeight);

                    // Create the tile
                    if (tileBitmap != null) {

                        // Project the tile if needed
                        if (!sameProjection) {
                            Bitmap reprojectTile = reprojectTile(tileBitmap, requestedTileWidth, requestedTileHeight, requestBoundingBox, transformRequestToTiles, tilesBoundingBox);
                            tileBitmap.recycle();
                            tileBitmap = reprojectTile;
                        }

                        try {
                            byte[] tileData = BitmapConverter.toBytes(
                                    tileBitmap, COMPRESS_FORMAT);
                            tileBitmap.recycle();
                            tile = new GeoPackageTile(requestedTileWidth, requestedTileHeight, tileData);
                        } catch (IOException e) {
                            Log.e(TileCreator.class.getSimpleName(), "Failed to create tile. min lat: "
                                    + requestBoundingBox.getMinLatitude()
                                    + ", max lat: " + requestBoundingBox.getMaxLatitude()
                                    + ", min lon: " + requestBoundingBox.getMinLongitude() +
                                    ", max lon: " + requestBoundingBox.getMaxLongitude(), e);
                        }
                    }

                }
            } finally {
                tileResults.close();
            }
        }
    }

    return tile;
}
 
Example 18
Source File: CoverageDataPngImportTest.java    From geopackage-android with MIT License 4 votes vote down vote up
/**
 * Test 10 random locations and optionally print
 *
 * @throws Exception
 */
@Test
public void testRandomLocations() throws Exception {

    BoundingBox projectedBoundingBox = null;

    List<String> coverageDataTables = CoverageDataPng.getTables(geoPackage);
    TileMatrixSetDao dao = geoPackage.getTileMatrixSetDao();

    for (String coverageTable : coverageDataTables) {

        TileMatrixSet tileMatrixSet = dao.queryForId(coverageTable);

        BoundingBox boundingBox = tileMatrixSet.getBoundingBox();
        if (PRINT) {
            System.out.println("Min Latitude: "
                    + boundingBox.getMinLatitude());
            System.out.println("Max Latitude: "
                    + boundingBox.getMaxLatitude());
            System.out.println("Min Longitude: "
                    + boundingBox.getMinLongitude());
            System.out.println("Max Longitude: "
                    + boundingBox.getMaxLongitude());
            System.out.println();
        }
        SpatialReferenceSystemDao srsDao = geoPackage
                .getSpatialReferenceSystemDao();
        long srsId = tileMatrixSet.getSrsId();
        SpatialReferenceSystem srs = srsDao.queryForId(srsId);
        Projection projection = srs.getProjection();
        Projection requestProjection = ProjectionFactory
                .getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM);
        ProjectionTransform coverageToRequest = projection
                .getTransformation(requestProjection);
        projectedBoundingBox = boundingBox.transform(coverageToRequest);

    }
    if (PRINT) {
        System.out.println("Min Latitude: "
                + projectedBoundingBox.getMinLatitude());
        System.out.println("Max Latitude: "
                + projectedBoundingBox.getMaxLatitude());
        System.out.println("Min Longitude: "
                + projectedBoundingBox.getMinLongitude());
        System.out.println("Max Longitude: "
                + projectedBoundingBox.getMaxLongitude());
        System.out.println();
    }

    double latDistance = projectedBoundingBox.getMaxLatitude()
            - projectedBoundingBox.getMinLatitude();
    double lonDistance = projectedBoundingBox.getMaxLongitude()
            - projectedBoundingBox.getMinLongitude();

    for (int i = 0; i < 10; i++) {

        // Get a random coordinate
        double latitude = latDistance * .9 * Math.random()
                + projectedBoundingBox.getMinLatitude()
                + (.05 * latDistance);
        double longitude = lonDistance * .9 * Math.random()
                + projectedBoundingBox.getMinLongitude()
                + (.05 * lonDistance);
        testLocation(latitude, longitude);
        if (PRINT) {
            System.out.println();
        }
    }
}
 
Example 19
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 20
Source File: UserCoreDao.java    From geopackage-core-java with MIT License 3 votes vote down vote up
/**
 * Project the provided bounding box in the declared projection to the user
 * DAO projection
 * 
 * @param boundingBox
 *            bounding box
 * @param projection
 *            projection
 * @return projected bounding box
 * @since 3.1.0
 */
public BoundingBox projectBoundingBox(BoundingBox boundingBox,
		Projection projection) {
	ProjectionTransform projectionTransform = projection
			.getTransformation(getProjection());
	BoundingBox projectedBoundingBox = boundingBox
			.transform(projectionTransform);
	return projectedBoundingBox;
}