|
|
|
César Martínez Izquierdo-3
|
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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
mbedward
|
Hi Oliver,
You can create very large GeoTiffs by creating the image such that you don't try to hold all of it in memory at one time. The standard approach is to use a tiled image. The example below uses the JAI "Constant" operation to create the tiles for a large image. This is then wrapped in a GridCoverage2D object and written to file as a GeoTiff. You might also be interested in the jai-tools project which has a tiled image class that can use both disk and memory storage for working with images too large to fit into available memory. This is a good option when, unlike in the example below, the image is costly to generate, e.g. the product of a complex and time-consuming calculation. http://code.google.com/p/jai-tools/wiki/DiskMemImage Hope this helps, Michael /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.geotools.demo.coverage; import java.awt.Rectangle; import java.awt.RenderingHints; import java.awt.image.Raster; import java.io.File; import javax.media.jai.ImageLayout; import javax.media.jai.JAI; import javax.media.jai.ParameterBlockJAI; import javax.media.jai.RenderedOp; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; import org.geotools.gce.geotiff.GeoTiffWriter; import org.geotools.geometry.jts.ReferencedEnvelope; import org.geotools.swing.data.JFileDataStoreChooser; /** * This example illustrates creating a large coverage, avoiding the need to hold * all of the data in memory at one time. * * @author Michael Bedward */ public class BigCoverage { private static final int IMAGE_WIDTH = 10000; private static final int IMAGE_HEIGHT = 10000; public static void main(String[] args) throws Exception { JFileDataStoreChooser chooser = new JFileDataStoreChooser("tif"); chooser.setDialogTitle("Create GeoTiff file"); File file = null; if (chooser.showSaveDialog(null) == JFileDataStoreChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } if (file == null) { return; } ParameterBlockJAI pb = new ParameterBlockJAI("Constant"); pb.setParameter("width", (float)IMAGE_WIDTH); pb.setParameter("height", (float)IMAGE_HEIGHT); pb.setParameter("bandValues", new Double[]{0.0d}); final int tileWidth = 512; ImageLayout layout = new ImageLayout(); layout.setTileWidth(tileWidth); layout.setTileHeight(tileWidth); RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); RenderedOp image = JAI.create("Constant", pb, hints); for (int y = 0; y < image.getNumYTiles(); y++) { for (int x = 0; x < image.getNumXTiles(); x++) { Raster tile = image.getTile(x, y); System.out.println(String.format("calling getTile(%d, %d): %s", x, y, tile.getBounds().toString())); } } GeoTiffWriter writer = new GeoTiffWriter(file, null); GridCoverageFactory factory = new GridCoverageFactory(); ReferencedEnvelope env = new ReferencedEnvelope( new Rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT), null); GridCoverage2D coverage = factory.create("coverage", image, env); writer.write(coverage, null); } } ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
|
mbedward
|
Sigh...
Here's the example again with the unnecessary loops and call to getTile omitted. I quickly hacked the example from something else but not carefully enough. Michael package org.geotools.demo.coverage; import java.awt.Rectangle; import java.awt.RenderingHints; import java.io.File; import javax.media.jai.ImageLayout; import javax.media.jai.JAI; import javax.media.jai.ParameterBlockJAI; import javax.media.jai.RenderedOp; import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverageFactory; import org.geotools.gce.geotiff.GeoTiffWriter; import org.geotools.geometry.jts.ReferencedEnvelope; import org.geotools.swing.data.JFileDataStoreChooser; /** * This example illustrates creating a large coverage, avoiding the need to hold * all of the data in memory at one time. * * @author Michael Bedward */ public class BigCoverage { private static final int IMAGE_WIDTH = 10000; private static final int IMAGE_HEIGHT = 10000; public static void main(String[] args) throws Exception { JFileDataStoreChooser chooser = new JFileDataStoreChooser("tif"); chooser.setDialogTitle("Create GeoTiff file"); File file = null; if (chooser.showSaveDialog(null) == JFileDataStoreChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } if (file == null) { return; } ParameterBlockJAI pb = new ParameterBlockJAI("Constant"); pb.setParameter("width", (float)IMAGE_WIDTH); pb.setParameter("height", (float)IMAGE_HEIGHT); pb.setParameter("bandValues", new Double[]{0.0d}); final int tileWidth = 512; ImageLayout layout = new ImageLayout(); layout.setTileWidth(tileWidth); layout.setTileHeight(tileWidth); RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); RenderedOp image = JAI.create("Constant", pb, hints); GeoTiffWriter writer = new GeoTiffWriter(file, null); GridCoverageFactory factory = new GridCoverageFactory(); ReferencedEnvelope env = new ReferencedEnvelope( new Rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT), null); GridCoverage2D coverage = factory.create("coverage", image, env); writer.write(coverage, null); } } ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
César Martínez Izquierdo-3
|
Hello Michael,
DiskMemImage seems exactly what I was looking for. Thanks for the link and also for writing so useful piece of code. I'll try it right now! César El día 1 de noviembre de 2009 10:56, Michael Bedward <[hidden email]> escribió: > Sigh... > > Here's the example again with the unnecessary loops and call to > getTile omitted. I quickly hacked the example from something else but > not carefully enough. > > Michael > > > package org.geotools.demo.coverage; > > import java.awt.Rectangle; > import java.awt.RenderingHints; > import java.io.File; > import javax.media.jai.ImageLayout; > import javax.media.jai.JAI; > import javax.media.jai.ParameterBlockJAI; > import javax.media.jai.RenderedOp; > import org.geotools.coverage.grid.GridCoverage2D; > import org.geotools.coverage.grid.GridCoverageFactory; > import org.geotools.gce.geotiff.GeoTiffWriter; > import org.geotools.geometry.jts.ReferencedEnvelope; > import org.geotools.swing.data.JFileDataStoreChooser; > > /** > * This example illustrates creating a large coverage, avoiding the need to hold > * all of the data in memory at one time. > * > * @author Michael Bedward > */ > public class BigCoverage { > > private static final int IMAGE_WIDTH = 10000; > private static final int IMAGE_HEIGHT = 10000; > > public static void main(String[] args) throws Exception { > JFileDataStoreChooser chooser = new JFileDataStoreChooser("tif"); > chooser.setDialogTitle("Create GeoTiff file"); > > File file = null; > if (chooser.showSaveDialog(null) == > JFileDataStoreChooser.APPROVE_OPTION) { > file = chooser.getSelectedFile(); > } > > if (file == null) { > return; > } > > ParameterBlockJAI pb = new ParameterBlockJAI("Constant"); > pb.setParameter("width", (float)IMAGE_WIDTH); > pb.setParameter("height", (float)IMAGE_HEIGHT); > pb.setParameter("bandValues", new Double[]{0.0d}); > > final int tileWidth = 512; > > ImageLayout layout = new ImageLayout(); > layout.setTileWidth(tileWidth); > layout.setTileHeight(tileWidth); > > RenderingHints hints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout); > > RenderedOp image = JAI.create("Constant", pb, hints); > > GeoTiffWriter writer = new GeoTiffWriter(file, null); > GridCoverageFactory factory = new GridCoverageFactory(); > ReferencedEnvelope env = new ReferencedEnvelope( > new Rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT), null); > GridCoverage2D coverage = factory.create("coverage", image, env); > writer.write(coverage, null); > } > > } > -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
mbedward
|
Hi César,
Thanks for that - I hope it proves useful. It's quite new code so I'm sure there are plenty of improvements that can be made and probably some bugs to iron out. Please let me know how you go. I'm hoping that some of the jai-tools components will be brought into service within GeoTools 2.7 (e.g. for large coverage support, map algebra, and some new grid coverage operations), though there isn't any proper plan worked out for that yet. Michael ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
César Martínez Izquierdo-3
|
Hello Michael,
I've finally got some time to try this. Should I build the JARs from SVN or is there a generated JAR somewhere? If I need to build from SVN... should I get code from trunk or from a branch? Regards, César El día 2 de noviembre de 2009 09:59, Michael Bedward <[hidden email]> escribió: > Hi César, > > Thanks for that - I hope it proves useful. > > It's quite new code so I'm sure there are plenty of improvements that > can be made and probably some bugs to iron out. Please let me know how > you go. > > I'm hoping that some of the jai-tools components will be brought into > service within GeoTools 2.7 (e.g. for large coverage support, map > algebra, and some new grid coverage operations), though there isn't > any proper plan worked out for that yet. > > Michael > -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
mbedward
|
Hi César,
There are some jars deployed to a toy repo on the jai-tools project site for a couple of milestone releases but there have been some changes to DiskMemImage and the associated tile cache class more recently that I think would be good for you to have. So, if you checkout the code from trunk (1.0-SNAPSHOT) and build that you should be right. It's a bit quicker to build than GeoTools :-) Michael ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
Simone Giannecchini-3
|
In reply to this post
by César Martínez Izquierdo-3
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 <[hidden email]>: > 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 > [hidden email] > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
César Martínez Izquierdo-3
|
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 <[hidden email]> 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 <[hidden email]>: >> 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 >> [hidden email] >> 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
mbedward
|
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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
|
mbedward
|
And of course, as soon as I sent that I noticed a stupid bug in my
modifications ! The section setting values into the image should be this... WritableRectIter iter = RectIterFactory.createWritable(img, null); do { int x = 0; do { iter.setSample(x / tileWidth); x++ ; } while (!iter.nextPixelDone()); iter.startPixels(); } while (!iter.nextLineDone()); Sorry about that. Michael ------------------------------------------------------------------------------ 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 [hidden email] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |