Hello Simone and Michael,

Thank you very much for your interest.

I've tried to create a big TIFF (30000 x 28000 pixels) by using
DiskMemImage, but I was not fully successful.
The TIFF file was created, but all the pixels were set to 0 (which was
not my intention). I'm not sure if I was misusing DiskMemImage or
maybe it is not ready yet for such usage.

Some extra notes: the resulting TIFF file didn't have any compression,
despite I tried to set it to "Deflate".

Unfortunately I have other high priority tasks now, so I will no be
able to continue testing these classes for a while.
However I'll need both DiskMemImage and BigTiff support in my project,
so for sure I will come back to you when I have some time to spend on
this.

I paste my code bellow, because I think it may be useful for other
people interested in DiskMemImage.

Best regards,

César


-------- Sample code: ----

// 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);

        ColorSpace cs = ColorSpaceJAI.getInstance(ColorSpaceJAI.CS_GRAY);
        ComponentColorModelJAI cm = new ComponentColorModelJAI(cs, false,
false, ComponentColorModelJAI.OPAQUE, DataBuffer.TYPE_FLOAT);

        int[] bandOffsets = new int[1];
        bandOffsets[0] = 0;

        ComponentSampleModelJAI sampleModel = new
ComponentSampleModelJAI(DataBuffer.TYPE_FLOAT, tileWidth, tileHeight,
1, tileWidth,  bandOffsets);
        DiskMemImage img = new DiskMemImage(width, height, sampleModel, cm);

        for (int j=0, yTiles = img.getMaxTileY(); j<yTiles; j++) {
                for (int i=0, xTiles = img.getMaxTileX(); i<xTiles; i++) {
                        WritableRaster tile = img.getWritableTile(i, j);
                        for (int jj=0, yMax=tile.getHeight(); jj<yMax; jj++) {
                                for (int ii=0, xMax=tile.getWidth(); ii<xMax; 
ii++) {
                                        tile.setSample(ii, jj, 0, i);
                                }
                        }
                        img.releaseWritableTile(i, j);                          
        
                }
        }

        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.parameter(
                        
AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString())
                        .setValue(wp);

        GridCoverageWriter writer = fmt.getWriter(m_sFilename);
        writer.write(gc.geophysics(true), null);
        writer.dispose();
} catch (Exception e) {
        e.printStackTrace();
}


------- end of sampe code ---


El día 8 de noviembre de 2009 19:12, Simone Giannecchini
<[email protected]> escribió:
> Ciao Cesar,
> notice that a geotiff cannot be larger than 4gb. It is a format
> limitation not a geotools limitation.
> We have a student that is trying to extend imageio tiff plugin to
> support bigtiff as well, but for the moment no work should have been
> performed on writing bigtiff. If you are interested I can try to check
> with him next week.
>
> Ciao,
> Simone.
> -------------------------------------------------------
> Ing. Simone Giannecchini
> GeoSolutions S.A.S.
> Founder - Software Engineer
> Via Carignoni 51
> 55041  Camaiore (LU)
> Italy
>
> phone: +39 0584983027
> fax:      +39 0584983027
> mob:    +39 333 8128928
>
>
> http://www.geo-solutions.it
> http://geo-solutions.blogspot.com/
> http://simboss.blogspot.com/
> http://www.linkedin.com/in/simonegiannecchini
>
> -------------------------------------------------------
>
>
>
> 2009/10/30 César Martínez Izquierdo <[email protected]>:
>> Hello list,
>>
>> now that I've solved my problems *reading* big raster data, I'm also
>> trying to *write* them.
>> I've written some testing code:
>>
>>        CoordinateReferenceSystem crs = CRS.decode(crsString);
>>        Envelope envelope = new Envelope2D(crs, 0, 0, 60000, 60000);
>>
>>        Raster m_Raster = 
>> RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT,
>>                60000, 60000, 1, null);
>>
>>        GridCoverageFactory factory =
>> CoverageFactoryFinder.getGridCoverageFactory(null);
>>
>>        GridCoverage2D gc = factory.create("bigtif",
>> (WritableRaster)m_Raster, envelope,
>>                                        null, null, null, null, null);
>>
>>        AbstractGridCoverageWriter writer = new GeoTiffWriter(m_sFilename);
>>        writer.write(gc.geophysics(true), null);
>>        writer.dispose();
>>
>> However, the method createBandedRaster fails (as I was expecting...):
>>  java.lang.IllegalArgumentException: Size of array must be smaller
>> than Integer.MAX_VALUE.
>> at javax.media.jai.RasterFactory.createBandedRaster(RasterFactory.java:307)
>>
>> Is there a better way to achieve this?
>>
>> Regards,
>>
>>
>> César
>>
>>
>> --
>> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>>   César Martínez Izquierdo
>>   GIS developer
>>   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
>>   ETC-LUSI: http://etc-lusi.eionet.europa.eu/
>>   Universitat Autònoma de Barcelona (SPAIN)
>> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>>
>> ------------------------------------------------------------------------------
>> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
>> is the only developer event you need to attend this year. Jumpstart your
>> developing skills, take BlackBerry mobile applications to market and stay
>> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
>> http://p.sf.net/sfu/devconference
>> _______________________________________________
>> Geotools-gt2-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>
>



-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   César Martínez Izquierdo
   GIS developer
   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
   ETC-LUSI: http://etc-lusi.eionet.europa.eu/
   Universitat Autònoma de Barcelona (SPAIN)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

------------------------------------------------------------------------------
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