Java Code Examples for mil.nga.sf.proj.ProjectionTransform

The following examples show how to use mil.nga.sf.proj.ProjectionTransform. These examples are extracted from open source projects. 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 Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Bitmap drawTile(int zoom, BoundingBox boundingBox, List<FeatureRow> featureRow) {

    FeatureTileCanvas canvas = new FeatureTileCanvas(tileWidth, tileHeight);

    ProjectionTransform transform = getProjectionToWebMercatorTransform(featureDao.getProjection());
    BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

    boolean drawn = false;
    for (FeatureRow row : featureRow) {
        if (drawFeature(zoom, boundingBox, expandedBoundingBox, transform, canvas, row)) {
            drawn = true;
        }
    }

    Bitmap bitmap = null;
    if (drawn) {
        bitmap = canvas.createBitmap();
        bitmap = checkIfDrawn(bitmap);
    } else {
        canvas.recycle();
    }

    return bitmap;
}
 
Example 2
Source Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: MIT License 6 votes vote down vote up
/**
 * Add the linestring to the path
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param boundingBox       bounding box
 * @param transform         projection transform
 * @param path              path
 * @param lineString        line string
 */
private void addLineString(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, LineString lineString) {

    List<Point> points = lineString.getPoints();

    if (points.size() >= 2) {

        // Try to simplify the number of points in the LineString
        points = simplifyPoints(simplifyTolerance, points);

        for (int i = 0; i < points.size(); i++) {
            Point point = points.get(i);
            Point webMercatorPoint = transform.transform(point);
            float x = TileBoundingBoxUtils.getXPixel(tileWidth, boundingBox,
                    webMercatorPoint.getX());
            float y = TileBoundingBoxUtils.getYPixel(tileHeight, boundingBox,
                    webMercatorPoint.getY());
            if (i == 0) {
                path.moveTo(x, y);
            } else {
                path.lineTo(x, y);
            }
        }
    }
}
 
Example 3
Source Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: MIT License 6 votes vote down vote up
/**
 * Add the polygon on the canvas
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param boundingBox       bounding box
 * @param transform         projection transform
 * @param path              path
 * @param polygon           polygon
 */
private void addPolygon(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, Polygon polygon) {
    List<LineString> rings = polygon.getRings();
    if (!rings.isEmpty()) {

        // Add the polygon points
        LineString polygonLineString = rings.get(0);
        List<Point> polygonPoints = polygonLineString.getPoints();
        if (polygonPoints.size() >= 2) {
            addRing(simplifyTolerance, boundingBox, transform, path, polygonPoints);

            // Add the holes
            for (int i = 1; i < rings.size(); i++) {
                LineString holeLineString = rings.get(i);
                List<Point> holePoints = holeLineString.getPoints();
                if (holePoints.size() >= 2) {
                    addRing(simplifyTolerance, boundingBox, transform, path, holePoints);
                }
            }
        }
    }
}
 
Example 4
Source Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: MIT License 6 votes vote down vote up
/**
 * Add a ring
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param boundingBox       bounding box
 * @param transform         projection transform
 * @param path              path
 * @param points            points
 */
private void addRing(double simplifyTolerance, BoundingBox boundingBox, ProjectionTransform transform, Path path, List<Point> points) {

    // Try to simplify the number of points in the LineString
    points = simplifyPoints(simplifyTolerance, points);

    for (int i = 0; i < points.size(); i++) {
        Point point = points.get(i);
        Point webMercatorPoint = transform.transform(point);
        float x = TileBoundingBoxUtils.getXPixel(tileWidth, boundingBox,
                webMercatorPoint.getX());
        float y = TileBoundingBoxUtils.getYPixel(tileHeight, boundingBox,
                webMercatorPoint.getY());
        if (i == 0) {
            path.moveTo(x, y);
        } else {
            path.lineTo(x, y);
        }
    }
    path.close();
}
 
Example 5
Source Project: geopackage-android   Source File: FeatureTiles.java    License: 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 6
Source Project: geopackage-android   Source File: FeatureTileGenerator.java    License: 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 7
Source Project: geopackage-core-java   Source File: UserCoreDao.java    License: 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 8
Source Project: geopackage-java   Source File: DefaultFeatureTiles.java    License: MIT License 6 votes vote down vote up
/**
 * Get the area of the polygon
 *
 * @param simplifyTolerance
 *            simplify tolerance in meters
 * @param boundingBox
 * @param transform
 * @param lineString
 */
private Area getArea(double simplifyTolerance, BoundingBox boundingBox,
		ProjectionTransform transform, Polygon polygon) {

	Area area = null;

	for (LineString ring : polygon.getRings()) {

		Path2D path = getPath(simplifyTolerance, boundingBox, transform,
				ring);
		Area ringArea = new Area(path);

		if (area == null) {
			area = ringArea;
		} else {
			area.subtract(ringArea);
		}

	}

	return area;
}
 
Example 9
Source Project: geopackage-java   Source File: FeatureTiles.java    License: 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 10
Source Project: geopackage-java   Source File: FeatureTileGenerator.java    License: 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 11
Source Project: geopackage-android-map   Source File: FeatureInfoBuilder.java    License: MIT License 5 votes vote down vote up
/**
 * Project the geometry into the provided projection
 *
 * @param geometryData geometry data
 * @param projection   projection
 */
public void projectGeometry(GeoPackageGeometryData geometryData, Projection projection) {

    if (geometryData.getGeometry() != null) {

        try {
            SpatialReferenceSystemDao srsDao = DaoManager.createDao(featureDao.getDb().getConnectionSource(), SpatialReferenceSystem.class);
            int srsId = geometryData.getSrsId();
            SpatialReferenceSystem srs = srsDao.queryForId((long) srsId);

            if (!projection.equals(srs.getOrganization(), srs.getOrganizationCoordsysId())) {

                Projection geomProjection = srs.getProjection();
                ProjectionTransform transform = geomProjection.getTransformation(projection);

                Geometry projectedGeometry = transform.transform(geometryData.getGeometry());
                geometryData.setGeometry(projectedGeometry);
                SpatialReferenceSystem projectionSrs = srsDao.getOrCreateCode(projection.getAuthority(), Long.parseLong(projection.getCode()));
                geometryData.setSrsId((int) projectionSrs.getSrsId());
            }
        } catch (SQLException e) {
            throw new GeoPackageException("Failed to project geometry to projection with Authority: "
                    + projection.getAuthority() + ", Code: " + projection.getCode(), e);
        }
    }

}
 
Example 12
Source Project: geopackage-android-map   Source File: BoundedOverlay.java    License: 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 Project: geopackage-android-map   Source File: BoundedOverlay.java    License: MIT License 5 votes vote down vote up
/**
 * Get the bounding box as the provided projection
 *
 * @param projection projection
 */
public BoundingBox getBoundingBox(Projection projection) {
    ProjectionTransform webMercatorToProjection = ProjectionFactory
            .getProjection(ProjectionConstants.EPSG_WEB_MERCATOR)
            .getTransformation(projection);
    return webMercatorBoundingBox
            .transform(webMercatorToProjection);
}
 
Example 14
Source Project: geopackage-android   Source File: RTreeIndexTableDao.java    License: 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 15
Source Project: geopackage-android   Source File: ManualFeatureQuery.java    License: 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 16
Source Project: geopackage-android   Source File: FeatureIndexer.java    License: 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 = featureDao.getProjection()
                .getTransformation(projection);
        boundingBox = boundingBox.transform(projectionTransform);
    }
    return boundingBox;
}
 
Example 17
Source Project: geopackage-android   Source File: FeatureIndexer.java    License: 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 18
Source Project: geopackage-android   Source File: TileGenerator.java    License: MIT License 5 votes vote down vote up
/**
 * Get the tile count of tiles to be generated
 *
 * @return tile count
 */
public int getTileCount() {
    if (tileCount == null) {
        long count = 0;

        boolean degrees = projection.isUnit(Units.DEGREES);
        ProjectionTransform transformToWebMercator = null;
        if (!degrees) {
            transformToWebMercator = projection.getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
        }

        for (int zoom = minZoom; zoom <= maxZoom; zoom++) {

            BoundingBox expandedBoundingBox = getBoundingBox(zoom);

            // Get the tile grid that includes the entire bounding box
            TileGrid tileGrid = null;
            if (degrees) {
                tileGrid = TileBoundingBoxUtils.getTileGridWGS84(expandedBoundingBox, zoom);
            } else {
                tileGrid = TileBoundingBoxUtils.getTileGrid(expandedBoundingBox.transform(transformToWebMercator), zoom);
            }

            count += tileGrid.count();
            tileGrids.put(zoom, tileGrid);
            tileBounds.put(zoom, expandedBoundingBox);
        }

        tileCount = (int) Math.min(count, Integer.MAX_VALUE);
    }
    return tileCount;
}
 
Example 19
Source Project: geopackage-android   Source File: TileGenerator.java    License: MIT License 5 votes vote down vote up
/**
 * Adjust the tile matrix set and web mercator bounds for XYZ tile format
 */
private void adjustXYZBounds() {
    // Set the tile matrix set bounding box to be the world
    BoundingBox standardWgs84Box = new BoundingBox(-ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH,
            ProjectionConstants.WEB_MERCATOR_MIN_LAT_RANGE,
            ProjectionConstants.WGS84_HALF_WORLD_LON_WIDTH,
            ProjectionConstants.WEB_MERCATOR_MAX_LAT_RANGE);
    ProjectionTransform wgs84ToWebMercatorTransform = ProjectionFactory.getProjection(ProjectionConstants.EPSG_WORLD_GEODETIC_SYSTEM)
            .getTransformation(ProjectionConstants.EPSG_WEB_MERCATOR);
    tileGridBoundingBox = standardWgs84Box.transform(wgs84ToWebMercatorTransform);
}
 
Example 20
Source Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Bitmap drawTile(int zoom, BoundingBox boundingBox, FeatureIndexResults results) {

    FeatureTileCanvas canvas = new FeatureTileCanvas(tileWidth, tileHeight);

    ProjectionTransform transform = getProjectionToWebMercatorTransform(featureDao.getProjection());
    BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

    boolean drawn = false;
    for (FeatureRow featureRow : results) {
        if (drawFeature(zoom, boundingBox, expandedBoundingBox, transform, canvas, featureRow)) {
            drawn = true;
        }
    }
    results.close();

    Bitmap bitmap = null;
    if (drawn) {
        bitmap = canvas.createBitmap();
        bitmap = checkIfDrawn(bitmap);
    } else {
        canvas.recycle();
    }

    return bitmap;
}
 
Example 21
Source Project: geopackage-android   Source File: DefaultFeatureTiles.java    License: MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Bitmap drawTile(int zoom, BoundingBox boundingBox, FeatureCursor cursor) {

    FeatureTileCanvas canvas = new FeatureTileCanvas(tileWidth, tileHeight);

    ProjectionTransform transform = getProjectionToWebMercatorTransform(featureDao.getProjection());
    BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

    boolean drawn = false;
    while (cursor.moveToNext()) {
        FeatureRow row = cursor.getRow();
        if (drawFeature(zoom, boundingBox, expandedBoundingBox, transform, canvas, row)) {
            drawn = true;
        }
    }
    cursor.close();

    Bitmap bitmap = null;
    if (drawn) {
        bitmap = canvas.createBitmap();
        bitmap = checkIfDrawn(bitmap);
    } else {
        canvas.recycle();
    }

    return bitmap;
}
 
Example 22
Source Project: geopackage-android   Source File: FeatureTiles.java    License: MIT License 5 votes vote down vote up
/**
 * When the simplify tolerance is set, simplify the points to a similar
 * curve with fewer points.
 *
 * @param simplifyTolerance simplify tolerance in meters
 * @param points            ordered points
 * @return simplified points
 * @since 2.0.0
 */
protected List<Point> simplifyPoints(double simplifyTolerance,
                                     List<Point> points) {

    List<Point> simplifiedPoints = null;
    if (simplifyGeometries) {

        // Reproject to web mercator if not in meters
        if (projection != null && !projection.isUnit(Units.METRES)) {
            ProjectionTransform toWebMercator = projection
                    .getTransformation(WEB_MERCATOR_PROJECTION);
            points = toWebMercator.transform(points);
        }

        // Simplify the points
        simplifiedPoints = GeometryUtils.simplifyPoints(points,
                simplifyTolerance);

        // Reproject back to the original projection
        if (projection != null && !projection.isUnit(Units.METRES)) {
            ProjectionTransform fromWebMercator = WEB_MERCATOR_PROJECTION
                    .getTransformation(projection);
            simplifiedPoints = fromWebMercator.transform(simplifiedPoints);
        }
    } else {
        simplifiedPoints = points;
    }

    return simplifiedPoints;
}
 
Example 23
Source Project: geopackage-android   Source File: GeoPackageExample.java    License: 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 24
Source Project: geopackage-core-java   Source File: FeatureTableCoreIndex.java    License: 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 25
Source Project: geopackage-core-java   Source File: Contents.java    License: 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 26
Source Project: geopackage-core-java   Source File: TileMatrixSet.java    License: 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 27
Source Project: geopackage-core-java   Source File: TileBoundingBoxUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Get the Projected tile bounding box from the XYZ tile grid and zoom level
 *
 * @param projection
 *            projection
 * @param tileGrid
 *            tile grid
 * @param zoom
 *            zoom level
 * @return bounding box
 */
public static BoundingBox getProjectedBoundingBox(Projection projection,
		TileGrid tileGrid, int zoom) {

	BoundingBox boundingBox = getWebMercatorBoundingBox(tileGrid, zoom);

	if (projection != null) {
		ProjectionTransform transform = webMercator
				.getTransformation(projection);
		boundingBox = boundingBox.transform(transform);
	}

	return boundingBox;
}
 
Example 28
Source Project: geopackage-java   Source File: RTreeIndexTableDao.java    License: 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 29
Source Project: geopackage-java   Source File: ManualFeatureQuery.java    License: 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 30
Source Project: geopackage-java   Source File: TileGenerator.java    License: MIT License 5 votes vote down vote up
/**
 * Get the tile count of tiles to be generated
 *
 * @return tile count
 */
public int getTileCount() {
	if (tileCount == null) {
		int count = 0;

		boolean degrees = projection.isUnit(Units.DEGREES);
		ProjectionTransform transformToWebMercator = null;
		if (!degrees) {
			transformToWebMercator = projection.getTransformation(
					ProjectionConstants.EPSG_WEB_MERCATOR);
		}

		for (int zoom = minZoom; zoom <= maxZoom; zoom++) {

			BoundingBox expandedBoundingBox = getBoundingBox(zoom);

			// Get the tile grid that includes the entire bounding box
			TileGrid tileGrid = null;
			if (degrees) {
				tileGrid = TileBoundingBoxUtils
						.getTileGridWGS84(expandedBoundingBox, zoom);
			} else {
				tileGrid = TileBoundingBoxUtils
						.getTileGrid(expandedBoundingBox
								.transform(transformToWebMercator), zoom);
			}

			count += tileGrid.count();
			tileGrids.put(zoom, tileGrid);
			tileBounds.put(zoom, expandedBoundingBox);
		}

		tileCount = count;
	}
	return tileCount;
}