Java Code Examples for org.geotools.geometry.jts.ReferencedEnvelope#expandBy()

The following examples show how to use org.geotools.geometry.jts.ReferencedEnvelope#expandBy() . 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: ImageGenerator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draw the map on an image.
 * 
 * @param bounds the area of interest.
 * @param imageWidth the width of the image to produce.
 * @param imageHeight the height of the image to produce.
 * @param buffer the buffer to add around the map bounds in map units. 
 * @return the image.
 */
public BufferedImage drawImage( ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer ) {
    checkMapContent();

    if (buffer > 0.0)
        ref.expandBy(buffer, buffer);

    Rectangle2D refRect = new Rectangle2D.Double(ref.getMinX(), ref.getMinY(), ref.getWidth(), ref.getHeight());
    Rectangle2D imageRect = new Rectangle2D.Double(0, 0, imageWidth, imageHeight);

    GeometryUtilities.scaleToRatio(imageRect, refRect, false);

    ReferencedEnvelope newRef = new ReferencedEnvelope(refRect, ref.getCoordinateReferenceSystem());

    Rectangle imageBounds = new Rectangle(0, 0, imageWidth, imageHeight);
    BufferedImage dumpImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = dumpImage.createGraphics();
    g2d.fillRect(0, 0, imageWidth, imageHeight);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    synchronized (renderer) {
        renderer.paint(g2d, imageBounds, newRef);
    }

    return dumpImage;
}
 
Example 2
Source File: ImageGenerator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public void drawImage( Graphics2D g2d, ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer ) {
    checkMapContent();

    if (buffer > 0.0)
        ref.expandBy(buffer, buffer);

    Rectangle2D refRect = new Rectangle2D.Double(ref.getMinX(), ref.getMinY(), ref.getWidth(), ref.getHeight());
    Rectangle2D imageRect = new Rectangle2D.Double(0, 0, imageWidth, imageHeight);

    GeometryUtilities.scaleToRatio(imageRect, refRect, false);

    ReferencedEnvelope newRef = new ReferencedEnvelope(refRect, ref.getCoordinateReferenceSystem());

    Rectangle imageBounds = new Rectangle(0, 0, imageWidth, imageHeight);
    Color white = Color.white;
    g2d.setColor(new Color(white.getRed(), white.getGreen(), white.getBlue(), 0));
    g2d.fillRect(0, 0, imageWidth, imageHeight);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    synchronized (renderer) {
        content.getViewport().setBounds(newRef);
        renderer.paint(g2d, imageBounds, newRef);
    }
}
 
Example 3
Source File: RenderPanelImpl.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Expand envelope.
 *
 * @param bounds the bounds
 */
private void expandEnvelope(ReferencedEnvelope bounds) {
    Unit<?> unit =
            CRSUtilities.getUnit(bounds.getCoordinateReferenceSystem().getCoordinateSystem());

    double width;
    double height;
    if (unit == NonSI.DEGREE_ANGLE) {
        width =
                (bounds.getWidth() < BOUNDINGBOX_BUFFER_THRESHOLD_ANGLE)
                        ? BOUNDINGBOX_BUFFER_MIN_ANGLE
                        : (bounds.getWidth() * BOUNDINGBOX_BUFFER_ANGLE);
        height =
                (bounds.getHeight() < BOUNDINGBOX_BUFFER_THRESHOLD_ANGLE)
                        ? BOUNDINGBOX_BUFFER_MIN_ANGLE
                        : (bounds.getHeight() * BOUNDINGBOX_BUFFER_ANGLE);
    } else {
        width =
                (bounds.getWidth() < BOUNDINGBOX_BUFFER_THRESHOLD_LINEAR)
                        ? BOUNDINGBOX_BUFFER_MIN_LINEAR
                        : (bounds.getWidth() * BOUNDINGBOX_BUFFER_LINEAR);
        height =
                (bounds.getHeight() < BOUNDINGBOX_BUFFER_THRESHOLD_LINEAR)
                        ? BOUNDINGBOX_BUFFER_MIN_LINEAR
                        : (bounds.getHeight() * BOUNDINGBOX_BUFFER_LINEAR);
    }

    bounds.expandBy(width, height);
}
 
Example 4
Source File: GISFileViewer.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void zoomIn() {
	final ReferencedEnvelope env = pane.getDisplayArea();
	env.expandBy(-env.getWidth() / 10, -env.getHeight() / 10);
	pane.setDisplayArea(env);
}
 
Example 5
Source File: GISFileViewer.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void zoomOut() {
	final ReferencedEnvelope env = pane.getDisplayArea();
	env.expandBy(env.getWidth() / 10, env.getHeight() / 10);
	pane.setDisplayArea(env);
}