Hi César,

Many thanks for posting your sample code to the list.

Below is a slightly modified version that avoids deprecated classes
and methods.  I haven't tested this yet, but hopefully it will be
useful to you when you get back to it.

All the best
Michael


    public void createBigTiff(File file) {
        /*
         * I first decide if tiling must be used and which size must be used
         * (borrowed from ArcGridsImageReader),
         * then I create the image, then I fill all the image with some useless
         * values, and finally try to create a coverage and write this to disk
         * by using GeoTiffWriter.
         */

        /** Minimum size of a certain file source that neds tiling. */
        final int MIN_SIZE_NEED_TILING = 5242880; // 5 MByte
        /** Defaul tile size. */
        final int DEFAULT_TILE_SIZE = 1048576 / 2; // 1 MByte

        // if the imageSize is bigger than MIN_SIZE_NEED_TILING
        // we proceed to image tiling
        boolean isTiled = false;

        /**
         * Tile width for the underlying raster.
         */
        int tileWidth = -1;

        /**
         * Tile height for the underlying raster.
         */
        int tileHeight = -1;

        /** Image Size */
        long imageSize = -1;

        try {
            CoordinateReferenceSystem crs = CRS.decode("EPSG:3035");
            int width = 30000, height = 28000;
            int sampleSizeByte =
DataBuffer.getDataTypeSize(DataBuffer.TYPE_FLOAT);
            imageSize = (long) width * (long) height * (long) sampleSizeByte;

            /**
             * Setting Tile Dimensions (If Tiling is supported)
             */
            // if the Image Size is greater than a certain dimension
            // (MIN_SIZE_NEED_TILING), the image needs to be tiled
            if (imageSize >= MIN_SIZE_NEED_TILING) {
                isTiled = true;

                // This implementation supposes that tileWidth is
equal to the width
                // of the whole image
                tileWidth = width;


                // actually (need improvements) tileHeight is given by
                // the default tile size divided by the tileWidth
multiplied by the
                // sample size (in byte)
                tileHeight = DEFAULT_TILE_SIZE / (tileWidth * sampleSizeByte);

                // if computed tileHeight is zero, it is setted to 1
as precaution
                if (tileHeight < 1) {
                    tileHeight = 1;
                }
            } else {
                // If no Tiling needed, I set the tile sizes equal to the image
                // sizes
                tileWidth = width;
                tileHeight = height;
            }

            Envelope envelope = new Envelope2D(crs,
                    0, 0,
                    width, height);

            SampleModel sampleModel = new ComponentSampleModel(
                    DataBuffer.TYPE_FLOAT,
                    tileWidth, tileHeight,
                    1, tileWidth,
                    new int[]{0});

            DiskMemImage img = new DiskMemImage(width, height, sampleModel);

            WritableRectIter iter = RectIterFactory.createWritable(img, null);
            do {
                int x = 0;
                do {
                    iter.setSample(x / tileWidth);
                } while (!iter.nextPixelDone());
            } while (!iter.nextLineDone());

            GridCoverageFactory factory =
CoverageFactoryFinder.getGridCoverageFactory(null);

            GridCoverage2D gc = factory.create("bigtif", img, envelope);

            GeoTiffFormat fmt = new GeoTiffFormat();
            //getting the write parameters
            final GeoTiffWriteParams wp = new GeoTiffWriteParams();

            //setting compression to Deflate
            wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
            wp.setCompressionType("Deflate");
            wp.setCompressionQuality(0.75F);

            //setting the tile size to 256X256
            wp.setTilingMode(GeoToolsWriteParams.MODE_EXPLICIT);
            wp.setTiling(256, 256);

            //setting the write parameters for this geotiff
            final ParameterValueGroup[] params = {
                    fmt.getWriteParameters()
            };

            params[0].parameter(

AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);

            AbstractGridCoverageWriter writer = new GeoTiffWriter(file);
            writer.write(gc.view(ViewType.GEOPHYSICS), params);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to