org.locationtech.proj4j.units.Units Java Examples

The following examples show how to use org.locationtech.proj4j.units.Units. 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: GoogleMapShapeConverter.java    From geopackage-android-map with MIT License 6 votes vote down vote up
/**
 * When the simplify tolerance is set, simplify the points to a similar
 * curve with fewer points.
 *
 * @param points ordered points
 * @return simplified points
 */
private List<Point> simplifyPoints(List<Point> points) {

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

        // Reproject to web mercator if not in meters
        if (projection != null && !projection.isUnit(Units.METRES)) {
            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)) {
            simplifiedPoints = fromWebMercator.transform(simplifiedPoints);
        }
    } else {
        simplifiedPoints = points;
    }

    return simplifiedPoints;
}
 
Example #2
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 #3
Source File: TileGenerator.java    From geopackage-android with 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 #4
Source File: TileGenerator.java    From geopackage-android with MIT License 5 votes vote down vote up
/**
 * Adjust the tile matrix set and bounds
 *
 * @param boundingBox bounding box
 * @param zoom        zoom
 */
private void adjustBounds(BoundingBox boundingBox,
                          int zoom) {
    // XYZ Tile Format
    if (xyzTiles) {
        adjustXYZBounds();
    } else if (projection.isUnit(Units.DEGREES)) {
        adjustGeoPackageBoundsWGS84(boundingBox, zoom);
    } else {
        adjustGeoPackageBounds(boundingBox, zoom);
    }
}
 
Example #5
Source File: FeatureTiles.java    From geopackage-android with 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 #6
Source File: TileGenerator.java    From geopackage-java with 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;
}
 
Example #7
Source File: TileGenerator.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Adjust the tile matrix set and bounds
 *
 * @param boundingBox
 *            bounding box
 * @param zoom
 *            zoom
 */
private void adjustBounds(BoundingBox boundingBox, int zoom) {
	// XYZ Tile Format
	if (xyzTiles) {
		adjustXYZBounds();
	} else if (projection.isUnit(Units.DEGREES)) {
		adjustGeoPackageBoundsWGS84(boundingBox, zoom);
	} else {
		adjustGeoPackageBounds(boundingBox, zoom);
	}
}
 
Example #8
Source File: FeatureTiles.java    From geopackage-java with 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;
}