Java Code Examples for mil.nga.sf.proj.ProjectionTransform#isSameProjection()

The following examples show how to use mil.nga.sf.proj.ProjectionTransform#isSameProjection() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FeatureTiles.java    From geopackage-android with MIT License 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: 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 3
Source File: Contents.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get a bounding box 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 transform = getProjection().getTransformation(
				projection);
		if (!transform.isSameProjection()) {
			boundingBox = boundingBox.transform(transform);
		}
	}
	return boundingBox;
}
 
Example 4
Source File: TileMatrixSet.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Get a bounding box in the provided projection
 * 
 * @param projection
 *            desired projection
 * 
 * @return bounding box
 * @since 3.1.0
 */
public BoundingBox getBoundingBox(Projection projection) {
	BoundingBox boundingBox = getBoundingBox();
	if (projection != null) {
		ProjectionTransform transform = getProjection().getTransformation(
				projection);
		if (!transform.isSameProjection()) {
			boundingBox = boundingBox.transform(transform);
		}
	}
	return boundingBox;
}
 
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: 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);

}