From: Martin S. <ema...@gm...> - 2009-03-23 16:32:55
|
Hello users, I'm beginner with Geotools. I would like to work with Coverages. So I downloaded from internet example FloatRasterDemo.java a defined libraries (jars). But during running I received exception and I don't know where is the problem. Can anybody help me? This is FloatRaterDemo.java code package org.geotools.demo.coverage; // J2SE and JAI dependencies import java.awt.Color; import java.awt.image.DataBuffer; import java.awt.image.WritableRaster; import javax.media.jai.RasterFactory; //jai-core-1.1.3.jar // GeoAPI dependencies import org.opengis.coverage.grid.GridCoverage; //geoapi.jar //import org.opengis.spatialschema.geometry.Envelope; import org.opengis.geometry.Envelope; //geoapi.jar import org.opengis.referencing.crs.CoordinateReferenceSystem; //geoapi.jar // Geotools dependencies import org.geotools.geometry.Envelope2D; //gt2-referencing-2.5-M1.jar import org.geotools.coverage.grid.GridCoverage2D; //gt2-coverage-2.5-M1.jar import org.geotools.coverage.grid.GridCoverageFactory; //gt2-coverage-2.5-M1.jar import org.geotools.referencing.crs.DefaultGeographicCRS; //gt2-referencing-2.5-M1.jar import org.geotools.coverage.FactoryFinder; //gt2-coverage-2.5-M1.jar //implements org.opengis.spatialschema.geometry.Envelope, org.opengis.util.Cloneable /** * A simple demo computing a {@linkplain WritableRaster raster} and displaying it. The raster uses * {@code float} data type with arbitrary sample values. This demo consider the image as one and * only one tile. Consequently, sample values are set directly in the raster (no need to deal for * multi-tiles). * * @source $URL: http://svn.geotools.org/trunk/demo/coverage-use/src/main/java/org/geotools/demo/coverage/FloatRasterDemo.java$ * @version $Id: FloatRasterDemo.java 30570 2008-06-08 11:46:24Z acuster $ * @author Martin Desruisseaux */ public class FloatRasterDemo extends junit.framework.TestCase { /** * Run the demo. */ public static void main(String[] args) { /* * Set the pixel values. Because we use only one tile with one band, the code below * is pretty similar to the code we would have if we were just setting the values in * a matrix. */ final int width = 500; final int height = 500; WritableRaster raster = RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT, width, height, 1, null); for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { raster.setSample(x, y, 0, x+y); } } /* * Set some metadata (the CRS, the geographic envelope, etc.) and display the image. * The display may be slow, since the translation from floating-point values to some * color (or grayscale) is performed on the fly everytime the image is rendered. */ System.out.println("pred 1"); CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84; //org.opengis.spatialschema.geometry.Envelope envelope = (Envelope)new Envelope2D(crs, 0, 0, 30, 30); Envelope2D envelope=new Envelope2D(crs,0,0,30,30); GridCoverageFactory factory = FactoryFinder.getGridCoverageFactory(null); // FactoryFinder.getGridCoverageFactory(null); try { System.out.println("Pred factory.create"); System.out.println(envelope.toString()); GridCoverage gc = factory.create("My grayscale coverage", raster, envelope); ((GridCoverage2D) gc).show(); // Convenience method specific to Geotools. } catch(Exception ex) { System.out.println(ex.getMessage()); } /* * The above example created a grayscale image. The example below creates a new grid * coverage for the same data, but using a specified color map. Note that the factory * used allows more details to be specified, for example units. Setting some of those * arguments to null (as in this example) lets GridCoverage computes automatically a * default value. */ /* Color[] colors = new Color[] {Color.BLUE, Color.CYAN, Color.WHITE, Color.YELLOW, Color.RED}; gc = factory.create("My colored coverage", raster, envelope, null, null, null, new Color[][] {colors}, null); ((GridCoverage2D) gc).geophysics(false).show(); */ } public void testCoverage() { main(null); } } And there is list with jars I used: gt2-covage-2.5-M1.jar gt2-api-2.5-M1.jar jts-1.8.jar gt2-referencing-2.5-M1.jar vecmath-1.3.1.jar commons-pool-1.3.jar gt2-metadata-2.5-M1.jar geoapi-nogenerics-2.1-M8.jar jsr108-0.01.jar concurrent-1.3.4.jar gt2-main-2.5-M1.jar jdom-1.0.jar commons-beanutils-1.7.0.jar commons-logging-1.0.3.jar jai_core-1.1.3.jar junit-3.8.1.jar This is exception message: Exception in thread "main" java.lang.NoClassDefFoundError: com.sun.media.jai.codec.SeekableStream at javax.media.jai.operator.BMPDescriptor.class$(BMPDescriptor.java:86) at javax.media.jai.operator.BMPDescriptor.<clinit>(BMPDescriptor.java:85) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:164) at javax.media.jai.RegistryFileParser.getInstance(RegistryFileParser.java:216) at javax.media.jai.RegistryFileParser.registerDescriptor(RegistryFileParser.java:352) at javax.media.jai.RegistryFileParser.parseFile(RegistryFileParser.java:287) at javax.media.jai.RegistryFileParser.loadOperationRegistry(RegistryFileParser.java:47) at javax.media.jai.OperationRegistry.initializeRegistry(OperationRegistry.java:363) at javax.media.jai.JAI.<clinit>(JAI.java:560) at org.geotools.coverage.GridSampleDimension.<clinit>(GridSampleDimension.java:1569) at org.geotools.coverage.grid.GridCoverageFactory.create(GridCoverageFactory.java:317) at org.geotools.coverage.grid.GridCoverageFactory.create(GridCoverageFactory.java:270) at org.geotools.demo.coverage.FloatRasterDemo.main(FloatRasterDemo.java:72) which occurred at GridCoverage gc = factory.create("My grayscale coverage", raster, envelope); Thank you for everything Martin Striz |