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

The following examples show how to use org.geotools.geometry.jts.ReferencedEnvelope#getMinY() . 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: DatabaseLasDataManager.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized ReferencedEnvelope3D getEnvelope3D() throws Exception {
    if (referencedEnvelope3D == null) {
        checkOpen();

        List<LasSource> lasSources = LasSourcesTable.getLasSources(spatialDb);
        ReferencedEnvelope total = new ReferencedEnvelope(crs);
        double minZ = Double.POSITIVE_INFINITY;
        double maxZ = Double.NEGATIVE_INFINITY;
        for( LasSource lasSource : lasSources ) {
            Envelope envelopeInternal = lasSource.polygon.getEnvelopeInternal();
            total.expandToInclude(envelopeInternal);
            minZ = Math.min(minZ, lasSource.minElev);
            maxZ = Math.max(maxZ, lasSource.maxElev);
        }
        referencedEnvelope3D = new ReferencedEnvelope3D(total.getMinX(), total.getMaxX(), total.getMinY(), total.getMaxY(),
                minZ, maxZ, crs);
    }
    return referencedEnvelope3D;
}
 
Example 4
Source File: ImageMosaicNwwLayer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public ImageMosaicNwwLayer( File imageMosaicShpFile, Integer tileSize, GeneralParameterValue[] gp,
        boolean removeSameColorImages ) throws Exception {
    super(makeLevels(imageMosaicShpFile, getRenderer(imageMosaicShpFile, gp), tileSize, removeSameColorImages));
    this.layerName = FileUtilities.getNameWithoutExtention(imageMosaicShpFile);

    ReferencedEnvelope envelope = OmsVectorReader.readEnvelope(imageMosaicShpFile.getAbsolutePath());
    ReferencedEnvelope envelopeLL = envelope.transform(DefaultGeographicCRS.WGS84, true);

    double w = envelopeLL.getMinX();
    double s = envelopeLL.getMinY();
    double e = envelopeLL.getMaxX();
    double n = envelopeLL.getMaxY();

    double centerX = w + (e - w) / 2.0;
    double centerY = s + (n - s) / 2.0;

    centerCoordinate = new Coordinate(centerX, centerY);

    this.setUseTransparentTextures(true);

}
 
Example 5
Source File: FeatureLayer.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public FeatureLayer(LayerType layerType, final FeatureCollection<SimpleFeatureType, SimpleFeature> fc,
                    PropertySet configuration) {
    super(layerType, configuration);
    crs = fc.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem();
    if (crs == null) {
        // todo - check me! Why can this happen??? (nf)
        crs = DefaultGeographicCRS.WGS84;
    }
    final ReferencedEnvelope envelope = new ReferencedEnvelope(fc.getBounds(), crs);
    modelBounds = new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(),
                                         envelope.getWidth(), envelope.getHeight());
    mapContext = new DefaultMapContext(crs);
    final Style style = (Style) configuration.getValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE);
    mapContext.addLayer(fc, style);
    renderer = new StreamingRenderer();
    workaroundLabelCacheBug();
    style.accept(new RetrievingStyleVisitor());
    renderer.setContext(mapContext);

}
 
Example 6
Source File: RasterDirectLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void addLoadError(Graphics2D graphics, ImageException imageResult, MapViewport viewport) {
	Bbox imageBounds = imageResult.getRasterImage().getBounds();
	ReferencedEnvelope viewBounds = viewport.getBounds();
	double rasterScale = viewport.getScreenArea().getWidth() / viewport.getBounds().getWidth();
	double width = imageBounds.getWidth();
	double height = imageBounds.getHeight();
	// subtract screen position of lower-left corner
	double x = imageBounds.getX() - rasterScale * viewBounds.getMinX();
	// shift y to lower left corner, flip y to user space and subtract
	// screen position of lower-left
	// corner
	double y = -imageBounds.getY() - imageBounds.getHeight() - rasterScale * viewBounds.getMinY();
	if (log.isDebugEnabled()) {
		log.debug("adding image, width=" + width + ",height=" + height + ",x=" + x + ",y=" + y);
	}
	// opacity
	log.debug("before drawImage");
	graphics.drawString(getNlsString("loaderror.line1"), (int) x, (int) y);
}
 
Example 7
Source File: MaskFormActions.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static Rectangle2D handleVectorMask(Mask mask) {
    VectorDataNode vectorData = Mask.VectorDataType.getVectorData(mask);
    ReferencedEnvelope envelope = vectorData.getEnvelope();
    if (!envelope.isEmpty()) {
        return new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(),
                                      envelope.getWidth(), envelope.getHeight());
    }
    return null;
}
 
Example 8
Source File: RasterDirectLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void addImage(Graphics2D graphics, ImageResult imageResult, MapViewport viewport) throws IOException {
	Rectangle screenArea = viewport.getScreenArea();
	ReferencedEnvelope worldBounds = viewport.getBounds();
	// convert map bounds to application bounds
	double printScale = screenArea.getWidth() / worldBounds.getWidth();
	if (tileScale < 0) {
		tileScale = printScale;
	}
	Envelope applicationBounds = new Envelope((worldBounds.getMinX()) * printScale, (worldBounds.getMaxX())
			* printScale, -(worldBounds.getMinY()) * printScale, -(worldBounds.getMaxY()) * printScale);
	Bbox imageBounds = imageResult.getRasterImage().getBounds();
	// find transform between image bounds and application bounds
	double tx = (imageBounds.getX() * printScale / tileScale - applicationBounds.getMinX());
	double ty = (imageBounds.getY() * printScale / tileScale - applicationBounds.getMinY());
	BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageResult.getImage()));
	double scaleX = imageBounds.getWidth() / image.getWidth() * printScale / tileScale;
	double scaleY = imageBounds.getHeight() / image.getHeight() * printScale / tileScale;
	AffineTransform transform = new AffineTransform();
	transform.translate(tx, ty);
	transform.scale(scaleX, scaleY);
	if (log.isDebugEnabled()) {
		log.debug("adding image, width=" + image.getWidth() + ",height=" + image.getHeight() + ",x=" + tx + ",y="
				+ ty);
	}
	// opacity
	log.debug("before drawImage");
	// create a copy to apply transform
	Graphics2D g = (Graphics2D) graphics.create();
	// apply opacity to image off-graphics to avoid interference with whatever opacity model is used by graphics
	BufferedImage opaqueCopy = makeOpaque(image);
	g.drawImage(opaqueCopy, transform, null);
	log.debug("after drawImage");
}
 
Example 9
Source File: GeopaparazziMapsCreator.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inROI, outFolder);

    SimpleFeatureCollection boundsVector = OmsVectorReader.readVector(inROI);
    ReferencedEnvelope bounds = boundsVector.getBounds();
    // bounds.expandBy(50.0);

    OmsTmsGenerator gen = new OmsTmsGenerator();
    if (inRaster1 != null || inRaster2 != null) {
        List<String> inRasters = new ArrayList<String>();
        if (inRaster1 != null)
            inRasters.add(inRaster1);
        if (inRaster2 != null)
            inRasters.add(inRaster2);
        gen.inRasterFile = FileUtilities.stringListAsTmpFile(inRasters).getAbsolutePath();
    }
    if (inVector1 != null || inVector2 != null || inVector3 != null || inVector4 != null || inVector5 != null) {
        List<String> inVectors = new ArrayList<String>();
        if (inVector1 != null)
            inVectors.add(inVector1);
        if (inVector2 != null)
            inVectors.add(inVector2);
        if (inVector3 != null)
            inVectors.add(inVector3);
        if (inVector4 != null)
            inVectors.add(inVector4);
        if (inVector5 != null)
            inVectors.add(inVector5);
        gen.inVectorFile = FileUtilities.stringListAsTmpFile(inVectors).getAbsolutePath();
    }
    gen.pMinzoom = pMinZoom;
    gen.pMaxzoom = pMaxZoom;
    gen.pName = pName;
    gen.inPath = outFolder;
    gen.pWest = bounds.getMinX();
    gen.pEast = bounds.getMaxX();
    gen.pNorth = bounds.getMaxY();
    gen.pSouth = bounds.getMinY();
    // gen.pEpsg = "EPSG:32632";
    gen.dataCrs = bounds.getCoordinateReferenceSystem();
    gen.doMbtiles = true;

    gen.inZoomLimitVector = inZoomLimitROI;
    gen.pZoomLimit = pZoomLimit;

    switch( pImageType ) {
    case "jpg":
        gen.pImagetype = 1;
        break;
    case "png":
    default:
        gen.pImagetype = 0;
        break;
    }
    gen.pm = pm;
    gen.process();

}