Example usage for java.awt.image RenderedImage getTileHeight

List of usage examples for java.awt.image RenderedImage getTileHeight

Introduction

In this page you can find the example usage for java.awt.image RenderedImage getTileHeight.

Prototype

int getTileHeight();

Source Link

Document

Returns the tile height in pixels.

Usage

From source file:com.bc.ceres.jai.opimage.ReinterpretOpImage.java

static RenderedImage create(RenderedImage source, double factor, double offset, ScalingType scalingType,
        InterpretationType interpretationType, Map<Object, Object> config) {
    final ImageLayout imageLayout;
    if (config != null && config.get(JAI.KEY_IMAGE_LAYOUT) instanceof ImageLayout) {
        imageLayout = (ImageLayout) config.get(JAI.KEY_IMAGE_LAYOUT);
    } else {/*from www .ja  va2  s.c o  m*/
        final int targetDataType = ReinterpretDescriptor.getTargetDataType(
                source.getSampleModel().getDataType(), factor, offset, scalingType, interpretationType);
        final PixelInterleavedSampleModel sampleModel = new PixelInterleavedSampleModel(targetDataType,
                source.getTileWidth(), source.getTileHeight(), 1, source.getTileWidth(), new int[] { 0 });
        imageLayout = ReinterpretDescriptor.createTargetImageLayout(source, sampleModel);
    }

    return new ReinterpretOpImage(source, imageLayout, config, factor, offset, scalingType, interpretationType);
}

From source file:it.geosolutions.geobatch.destination.vulnerability.VulnerabilityComputation.java

/**
 * This method calculates the vulnerability for the levels 1 and 2
 * // ww  w  . j a  va 2  s . c o  m
 * @param currentImage
 * @param currentBPT
 * @param keySet
 * @param targetID
 * @param minTileX
 * @param maxTileX
 * @param minTileY
 * @param maxTileY
 * @param skipArcs
 * @param xStart
 * @param yStart
 * @param xStop
 * @param yStop
 * @param idStart
 * @param bbox
 * @param outFeatureName
 * @param trace
 * @param vse
 * @param statsMap
 * @param transaction
 * @param vulnerabilityObj
 * @param concreteOperation
 * @param monitor
 * @param inputFeature
 * @param allDistances
 * @param reportingLoopStep
 * @param geoName
 * @param total
 * @throws NoninvertibleTransformException
 * @throws TransformException
 * @throws IOException
 */
private void vulnerabilityLevel12(RenderedImage currentImage, Map<Integer, TargetInfo> currentBPT,
        String targetID, int minTileX, int maxTileX, int minTileY, int maxTileY, boolean skipArcs,
        Integer xStart, Integer yStart, Integer xStop, Integer yStop, String idStart, Envelope2D bbox,
        String outFeatureName, int trace, VulnerabilityStatsEngine vse, Transaction transaction,
        OutputObject vulnerabilityObj, VulnerabilityOperation concreteOperation, VulnerabilityMonitor monitor,
        List<Double> allDistances, int reportingLoopStep, String geoName,
        ConcurrentSkipListSet<BigDecimal> arcIdsSet)
        throws NoninvertibleTransformException, TransformException, IOException {

    // Preliminary checks
    if (minTileX > maxTileX) {
        int temp = minTileX;
        minTileX = maxTileX;
        maxTileX = temp;
    }
    if (minTileY > maxTileY) {
        int temp = minTileY;
        minTileY = maxTileY;
        maxTileY = temp;
    }

    // Load the Transformation associated with the selected
    // target and calculate the inverse
    TargetInfo firstInfo = currentBPT.get(0);
    MathTransform w2g = firstInfo.getGG2D().getCRSToGrid2D(PixelOrientation.UPPER_LEFT);
    MathTransform g2w = w2g.inverse();
    // Load the target dimensions for modifying the spatial
    // filter

    // Definition of the dimensions associated to the input image
    int tileWidth = currentImage.getTileWidth();
    int tileHeight = currentImage.getTileHeight();
    int tileGridX = currentImage.getTileGridXOffset();
    int tileGridY = currentImage.getTileGridYOffset();
    // Variables used for mapping the tile in the model space

    // Iteration on image tiles
    for (int x = minTileX; x < maxTileX; x++) {

        // For each tile, the points are transformed in the
        // world crs
        int minX = PlanarImage.tileXToX(x, tileGridX, tileWidth);

        if (xStart != null && xStart > x) {
            continue;
        }

        if (xStop != null && xStop < x) {
            continue;
        }

        for (int y = minTileY; y < maxTileY; y++) {

            int minY = PlanarImage.tileYToY(y, tileGridY, tileHeight);

            if (yStart != null && yStart > y) {
                continue;
            }

            if (yStop != null && yStop < y) {
                continue;
            }

            Envelope2D worldEnvelope = calculateWorldEnvelope(minX, minY, tileWidth, tileHeight, g2w);
            calculateTile(worldEnvelope, bbox, x, y, xStart, yStart, idStart, concreteOperation, monitor,
                    arcIdsSet, vse, currentBPT, allDistances, currentImage, targetID, outFeatureName,
                    vulnerabilityObj);
        }
    }

}

From source file:org.geoserver.wcs.responses.GeoTiffWriterHelper.java

private GeoTiffWriteParams buildWriteParams(GridCoverage2D coverage) {
    final RenderedImage renderedImage = coverage.getRenderedImage();
    int tileWidth = renderedImage.getTileWidth();
    int tileHeight = renderedImage.getTileHeight();

    // avoid tiles bigger than the image
    final GridEnvelope gr = coverage.getGridGeometry().getGridRange();
    if (gr.getSpan(0) < tileWidth) {
        tileWidth = gr.getSpan(0);/*from w  w  w . ja v a2s . c  o  m*/
    }
    if (gr.getSpan(1) < tileHeight) {
        tileHeight = gr.getSpan(1);
    }

    GeoTiffWriteParams writeParams = new GeoTiffWriteParams();
    writeParams.setTilingMode(GeoToolsWriteParams.MODE_EXPLICIT);
    writeParams.setTiling(tileWidth, tileHeight);
    return writeParams;
}

From source file:org.geoserver.wcs.responses.GeoTiffWriterHelper.java

public void write(OutputStream stream) throws IOException {
    if (sourceFile != null) {
        FileUtils.copyFile(sourceFile, stream);
    } else {//w  w  w.  jav a 2  s.  c om
        CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem();
        boolean unreferenced = crs == null || crs instanceof EngineeringCRS;

        if (unreferenced) {
            RenderedImage ri = coverage.getRenderedImage();
            int tileWidth, tileHeight;
            if (imageIoWriteParams.getTilingMode() == GeoToolsWriteParams.MODE_EXPLICIT) {
                tileWidth = imageIoWriteParams.getTileWidth();
                tileHeight = imageIoWriteParams.getTileHeight();
            } else {
                tileWidth = ri.getTileWidth();
                tileHeight = ri.getTileHeight();
            }

            new ImageWorker(ri).writeTIFF(stream, null, 0.75f, tileWidth, tileHeight);
        } else {
            final GeneralParameterValue[] wps = (GeneralParameterValue[]) geotoolsWriteParams.values()
                    .toArray(new GeneralParameterValue[geotoolsWriteParams.values().size()]);

            // write out the coverage
            AbstractGridCoverageWriter writer = (AbstractGridCoverageWriter) TIFF_FORMAT.getWriter(stream);
            if (writer == null)
                throw new ServiceException(
                        "Could not find the GeoTIFF writer, please check it's in the classpath");
            try {
                writer.write(coverage, wps);
            } finally {
                try {
                    writer.dispose();
                } catch (Exception e) {
                    // swallow, silent close
                }
            }
        }
    }
}

From source file:org.mrgeo.rasterops.GeoTiffExporter.java

public static void export(final RenderedImage image, final Bounds bounds, final OutputStream os,
        final boolean replaceNan, final String xmp, final Number nodata) throws IOException {
    OpImageRegistrar.registerMrGeoOps();

    final TIFFEncodeParam param = new TIFFEncodeParam();
    // The version of GDAL that Legion is using requires a tile size > 1
    param.setTileSize(image.getTileWidth(), image.getTileHeight());
    param.setWriteTiled(true);//  w  w w .  j a va 2 s  .  c o m

    // if the image only has 1 pixel, the value of this pixel changes after compressing (especially
    // if this pixel is no data value. e.g -9999 changes to -8192 when read the image back).
    // So don't do compress if the image has only 1 pixel.
    if (image.getWidth() > 1 && image.getHeight() > 1) {
        // Deflate lossless compression (also known as "Zip-in-TIFF")
        param.setCompression(TIFFEncodeParam.COMPRESSION_DEFLATE);
        param.setDeflateLevel(Deflater.BEST_COMPRESSION);
    }

    final GeoTIFFDirectory dir = new GeoTIFFDirectory();

    // GTModelTypeGeoKey : using geographic coordinate system.
    dir.addGeoKey(new XTIFFField(1024, XTIFFField.TIFF_SHORT, 1, new char[] { 2 }));
    // GTRasterTypeGeoKey : pixel is point
    dir.addGeoKey(new XTIFFField(1025, XTIFFField.TIFF_SHORT, 1, new char[] { 1 }));
    // GeographicTypeGeoKey : 4326 WGS84
    dir.addGeoKey(new XTIFFField(2048, XTIFFField.TIFF_SHORT, 1, new char[] { 4326 }));
    dir.addGeoKey(new XTIFFField(2049, XTIFFField.TIFF_ASCII, 7, new String[] { "WGS 84" }));
    // GeogAngularUnitsGeoKey : Angular Degree
    dir.addGeoKey(new XTIFFField(2054, XTIFFField.TIFF_SHORT, 1, new char[] { 9102 }));
    if (xmp != null) {
        final byte[] b = xmp.getBytes("UTF8");
        dir.addField(new XTIFFField(700, XTIFFField.TIFF_BYTE, b.length, b));
    }
    dir.getFields();

    final double[] tiePoints = new double[6];
    tiePoints[0] = 0.0;
    tiePoints[1] = 0.0;
    tiePoints[2] = 0.0;
    tiePoints[3] = bounds.getMinX();
    tiePoints[4] = bounds.getMaxY();
    tiePoints[5] = 0.0;
    dir.setTiepoints(tiePoints);
    final double[] pixelScale = new double[3];
    pixelScale[0] = bounds.getWidth() / image.getWidth();
    pixelScale[1] = bounds.getHeight() / image.getHeight();
    pixelScale[2] = 0;
    dir.setPixelScale(pixelScale);

    final Vector<TIFFField> fields = toTiffField(dir.getFields());

    RenderedImage output = image;

    final String[] nullValues = new String[1];
    switch (image.getSampleModel().getDataType()) {
    case DataBuffer.TYPE_DOUBLE:
        nullValues[0] = Double.toString(nodata.doubleValue());
        if (replaceNan) {
            output = ReplaceNanDescriptor.create(image, nodata.doubleValue());
        }
        // Tiff exporter doesn't handle doubles. Yuck!
        output = ConvertToFloatDescriptor.create(output);

        // Double.NaN (our default nodata on ingest) should not be written out as nodata on export
        // (i.e. GeoTiffs imported without NODATA metadata field should be exported as such)
        if (!Double.isNaN(nodata.doubleValue())) {
            fields.add(new TIFFField(NULL_TAG, XTIFFField.TIFF_ASCII, 1, nullValues));
        }
        break;
    case DataBuffer.TYPE_FLOAT:
        nullValues[0] = Double.toString(nodata.floatValue());
        if (replaceNan) {
            output = ReplaceNanDescriptor.create(image, nodata.floatValue());
        }
        // Float.NaN (our default nodata on ingest) should not be written out as nodata on export
        // (i.e. GeoTiffs imported without NODATA metadata field should be exported as such)
        if (!Float.isNaN(nodata.floatValue())) {
            fields.add(new TIFFField(NULL_TAG, XTIFFField.TIFF_ASCII, 1, nullValues));
        }
        break;
    case DataBuffer.TYPE_INT:
    case DataBuffer.TYPE_USHORT:
    case DataBuffer.TYPE_SHORT:
    case DataBuffer.TYPE_BYTE:
        nullValues[0] = Integer.toString(nodata.intValue());
        fields.add(new TIFFField(NULL_TAG, XTIFFField.TIFF_ASCII, 1, nullValues));
        break;
    }

    param.setExtraFields(fields.toArray(new TIFFField[0]));

    EncodeDescriptor.create(output, os, "TIFF", param, null);
}