mil.nga.sf.proj.ProjectionTransform Java Examples

The following examples show how to use mil.nga.sf.proj.ProjectionTransform. 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: 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 #3
Source File: DefaultFeatureTiles.java    From geopackage-android with 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 #4
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 #5
Source File: DefaultFeatureTiles.java    From geopackage-java with 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 #6
Source File: DefaultFeatureTiles.java    From geopackage-android with 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 #7
Source File: DefaultFeatureTiles.java    From geopackage-android with 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 #8
Source File: DefaultFeatureTiles.java    From geopackage-android with 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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: FeatureIndexer.java    From geopackage-android 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 = featureDao.getProjection()
                .getTransformation(projection);
        boundingBox = boundingBox.transform(projectionTransform);
    }
    return boundingBox;
}
 
Example #19
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 #20
Source File: TileBoundingBoxUtils.java    From geopackage-core-java with 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 #21
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 #22
Source File: ManualFeatureQuery.java    From geopackage-java 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 #23
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 #24
Source File: TileGenerator.java    From geopackage-java with 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 #25
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BufferedImage drawTile(int zoom, BoundingBox boundingBox,
		CloseableIterator<GeometryIndex> results) {

	FeatureTileGraphics graphics = new FeatureTileGraphics(tileWidth,
			tileHeight);

	// Feature projection to web mercator projection
	ProjectionTransform webMercatorTransform = getWebMercatorTransform();
	BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

	boolean drawn = false;
	while (results.hasNext()) {
		GeometryIndex geometryIndex = results.next();
		FeatureRow featureRow = getFeatureIndex()
				.getFeatureRow(geometryIndex);
		if (drawFeature(zoom, boundingBox, expandedBoundingBox,
				webMercatorTransform, graphics, featureRow)) {
			drawn = true;
		}
	}
	try {
		results.close();
	} catch (IOException e) {
		log.log(Level.WARNING, "Failed to close geometry index results", e);
	}

	BufferedImage image = null;
	if (drawn) {
		image = graphics.createImage();
		image = checkIfDrawn(image);
	} else {
		graphics.dispose();
	}

	return image;
}
 
Example #26
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BufferedImage drawTile(int zoom, BoundingBox boundingBox,
		FeatureResultSet resultSet) {

	FeatureTileGraphics graphics = new FeatureTileGraphics(tileWidth,
			tileHeight);

	ProjectionTransform webMercatorTransform = getWebMercatorTransform();
	BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

	boolean drawn = false;
	while (resultSet.moveToNext()) {
		FeatureRow row = resultSet.getRow();
		if (drawFeature(zoom, boundingBox, expandedBoundingBox,
				webMercatorTransform, graphics, row)) {
			drawn = true;
		}
	}
	resultSet.close();

	BufferedImage image = null;
	if (drawn) {
		image = graphics.createImage();
		image = checkIfDrawn(image);
	} else {
		graphics.dispose();
	}

	return image;
}
 
Example #27
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public BufferedImage drawTile(int zoom, BoundingBox boundingBox,
		List<FeatureRow> featureRow) {

	FeatureTileGraphics graphics = new FeatureTileGraphics(tileWidth,
			tileHeight);

	ProjectionTransform webMercatorTransform = getWebMercatorTransform();
	BoundingBox expandedBoundingBox = expandBoundingBox(boundingBox);

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

	BufferedImage image = null;
	if (drawn) {
		image = graphics.createImage();
		image = checkIfDrawn(image);
	} else {
		graphics.dispose();
	}

	return image;
}
 
Example #28
Source File: DefaultFeatureTiles.java    From geopackage-java with MIT License 5 votes vote down vote up
/**
 * Get the path of the line string
 *
 * @param simplifyTolerance
 *            simplify tolerance in meters
 * @param boundingBox
 * @param transform
 * @param lineString
 */
private Path2D getPath(double simplifyTolerance, BoundingBox boundingBox,
		ProjectionTransform transform, LineString lineString) {

	Path2D path = null;

	// Try to simplify the number of points in the LineString
	List<Point> lineStringPoints = simplifyPoints(simplifyTolerance,
			lineString.getPoints());

	for (Point point : lineStringPoints) {

		Point projectedPoint = transform.transform(point);

		float x = TileBoundingBoxUtils.getXPixel(tileWidth, boundingBox,
				projectedPoint.getX());
		float y = TileBoundingBoxUtils.getYPixel(tileHeight, boundingBox,
				projectedPoint.getY());

		if (path == null) {
			path = new Path2D.Double();
			path.moveTo(x, y);
		} else {
			path.lineTo(x, y);
		}

	}

	return path;
}
 
Example #29
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;
}
 
Example #30
Source File: GeoPackageExample.java    From geopackage-java with MIT License 5 votes vote down vote up
private static void createFeatureTileLinkExtension(GeoPackage geoPackage)
		throws SQLException, IOException {

	List<String> featureTables = geoPackage.getFeatureTables();
	for (String featureTable : featureTables) {

		FeatureDao featureDao = geoPackage.getFeatureDao(featureTable);
		FeatureTiles featureTiles = new DefaultFeatureTiles(geoPackage,
				featureDao);

		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(geoPackage,
				featureTable + "_tiles", featureTiles, minZoom, maxZoom,
				requestBoundingBox, requestProjection);

		tileGenerator.generateTiles();
	}
}