Package it.geosolutions.imageioimpl.plugins.tiff

Examples of it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader


     */
  private void getGeoJP2(final UUIDBoxMetadataNode uuid) throws IOException {
   
     CoordinateReferenceSystem coordinateReferenceSystem = null;
     final ByteArrayInputStream inputStream = new ByteArrayInputStream(uuid.getData());
         final TIFFImageReader tiffreader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
         tiffreader.setInput(ImageIO.createImageInputStream(inputStream));
         final IIOMetadata tiffmetadata = tiffreader.getImageMetadata(0);
         try {
            final GeoTiffIIOMetadataDecoder metadataDecoder = new GeoTiffIIOMetadataDecoder(tiffmetadata);
            final GeoTiffMetadata2CRSAdapter adapter = new GeoTiffMetadata2CRSAdapter(hints);
             coordinateReferenceSystem = adapter.createCoordinateSystem(metadataDecoder);
             if (coordinateReferenceSystem != null) {
View Full Code Here


    private static GridCoverage2D readInputFile(String filename) throws FileNotFoundException,
            IOException {
        final File tiff = TestData.file(MosaicTest.class, filename + ".tif");
        final File tfw = TestData.file(MosaicTest.class, filename + ".tfw");

        final TIFFImageReader reader = (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader) new TIFFImageReaderSpi()
                .createReaderInstance();
        reader.setInput(ImageIO.createImageInputStream(tiff));
        final BufferedImage image = reader.read(0);
        final MathTransform transform = new WorldFileReader(tfw).getTransform();
        final GridCoverage2D coverage2D = CoverageFactoryFinder.getGridCoverageFactory(null)
                .create("coverage" + filename,
                        image,
                        new GridGeometry2D(new GridEnvelope2D(PlanarImage.wrapRenderedImage(image)
View Full Code Here

    @Test
    public void testPolygonZoneGlobalStats() throws Exception {
        final File tiff = TestData.file(this, "test.tif");
        final File tfw = TestData.file(this, "test.tfw");

        final TIFFImageReader reader = (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader) new TIFFImageReaderSpi()
                .createReaderInstance();
        reader.setInput(ImageIO.createImageInputStream(tiff));
        final BufferedImage image = reader.read(0);
        reader.dispose();

        final MathTransform transform = new WorldFileReader(tfw).getTransform();
        final GridCoverage2D coverage2D = CoverageFactoryFinder.getGridCoverageFactory(null)
                .create("coverage",
                        image,
                        new GridGeometry2D(new GridEnvelope2D(PlanarImage.wrapRenderedImage(image)
                                .getBounds()), transform, DefaultGeographicCRS.WGS84),
                        new GridSampleDimension[] { new GridSampleDimension("coverage") }, null,
                        null);

        final File fileshp = TestData.file(this, "testpolygon.shp");
        final DataStore store = FileDataStoreFinder.getDataStore(fileshp.toURI().toURL());
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = store
                .getFeatureSource(store.getNames().get(0));
        FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = featureSource
                .getFeatures();
        List<SimpleFeature> polygonList = new ArrayList<SimpleFeature>();
        FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
        while (featureIterator.hasNext()) {
            SimpleFeature feature = featureIterator.next();
            polygonList.add(feature);
        }
        featureIterator.close();

        // choose the stats
        Set<Statistic> statsSet = new LinkedHashSet<Statistic>();
        statsSet.add(Statistic.MIN);
        statsSet.add(Statistic.MAX);
        statsSet.add(Statistic.MEAN);
        statsSet.add(Statistic.VARIANCE);
        statsSet.add(Statistic.SDEV);
        statsSet.add(Statistic.RANGE);

        // select the bands to work on
        Integer[] bands = new Integer[] { 0 };
        List<Range<Double>> inclusionRanges = new ArrayList<Range<Double>>();
        inclusionRanges
                .add(new Range<Double>(Double.valueOf(0), false, Double.valueOf(1300), true));
        inclusionRanges.add(new Range<Double>(Double.valueOf(1370), true, Double.valueOf(1600),
                true));

        // create the proper instance
        StatisticsTool statisticsTool = new StatisticsTool(statsSet, coverage2D, bands,
                polygonList, inclusionRanges, Type.INCLUDE, false);

        // do analysis
        statisticsTool.run();

        // get the results
        String id = "testpolygon.1";
        Map<Statistic, List<Result>> statistics = statisticsTool.getStatistics(id);
        LOGGER.info(id + statistics.toString());
        assertEquals(statistics.get(Statistic.RANGE).get(0).getValue().doubleValue(), 343.0, DELTA);
        assertEquals(statistics.get(Statistic.SDEV).get(0).getValue().doubleValue(), 88.7358, DELTA);
        assertEquals(statistics.get(Statistic.MIN).get(0).getValue().doubleValue(), 1255.0, DELTA);
        assertEquals(statistics.get(Statistic.MEAN).get(0).getValue().doubleValue(), 1380.5423,
                DELTA);
        assertEquals(statistics.get(Statistic.VARIANCE).get(0).getValue().doubleValue(), 7874.0598,
                DELTA);
        assertEquals(statistics.get(Statistic.MAX).get(0).getValue().doubleValue(), 1598.0, DELTA);

        id = "testpolygon.2";
        statistics = statisticsTool.getStatistics(id);
        LOGGER.info(id + statistics.toString());
        assertEquals(statistics.get(Statistic.RANGE).get(0).getValue().doubleValue(), 216.0, DELTA);
        assertEquals(statistics.get(Statistic.SDEV).get(0).getValue().doubleValue(), 36.7996, DELTA);
        assertEquals(statistics.get(Statistic.MIN).get(0).getValue().doubleValue(), 1192.0, DELTA);
        assertEquals(statistics.get(Statistic.MEAN).get(0).getValue().doubleValue(), 1248.3870,
                DELTA);
        assertEquals(statistics.get(Statistic.VARIANCE).get(0).getValue().doubleValue(), 1354.2150,
                DELTA);
        assertEquals(statistics.get(Statistic.MAX).get(0).getValue().doubleValue(), 1408.0, DELTA);

        id = "testpolygon.3";
        statistics = statisticsTool.getStatistics(id);
        LOGGER.info(id + statistics.toString());
        assertEquals(statistics.get(Statistic.RANGE).get(0).getValue().doubleValue(), 127.0000,
                DELTA);
        assertEquals(statistics.get(Statistic.SDEV).get(0).getValue().doubleValue(), 30.9412, DELTA);
        assertEquals(statistics.get(Statistic.MIN).get(0).getValue().doubleValue(), 1173.0, DELTA);
        assertEquals(statistics.get(Statistic.MEAN).get(0).getValue().doubleValue(), 1266.3876,
                DELTA);
        assertEquals(statistics.get(Statistic.VARIANCE).get(0).getValue().doubleValue(), 957.3594,
                DELTA);
        assertEquals(statistics.get(Statistic.MAX).get(0).getValue().doubleValue(), 1300.0, DELTA);

        reader.dispose();
        coverage2D.dispose(true);
        image.flush();
    }
View Full Code Here

    @Test
    public void testPolygonZoneLocalStats() throws Exception {
        final File tiff = TestData.file(this, "test.tif");
        final File tfw = TestData.file(this, "test.tfw");

        final TIFFImageReader reader = (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader) new TIFFImageReaderSpi()
                .createReaderInstance();
        reader.setInput(ImageIO.createImageInputStream(tiff));
        final BufferedImage image = reader.read(0);
        reader.dispose();

        final MathTransform transform = new WorldFileReader(tfw).getTransform();
        final GridCoverage2D coverage2D = CoverageFactoryFinder.getGridCoverageFactory(null)
                .create("coverage",
                        image,
                        new GridGeometry2D(new GridEnvelope2D(PlanarImage.wrapRenderedImage(image)
                                .getBounds()), transform, DefaultGeographicCRS.WGS84),
                        new GridSampleDimension[] { new GridSampleDimension("coverage") }, null,
                        null);

        final File fileshp = TestData.file(this, "testpolygon.shp");
        final DataStore store = FileDataStoreFinder.getDataStore(fileshp.toURI().toURL());
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = store
                .getFeatureSource(store.getNames().get(0));
        FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = featureSource
                .getFeatures();
        List<SimpleFeature> polygonList = new ArrayList<SimpleFeature>();
        FeatureIterator<SimpleFeature> featureIterator = featureCollection.features();
        while (featureIterator.hasNext()) {
            SimpleFeature feature = featureIterator.next();
            polygonList.add(feature);
        }
        featureIterator.close();

        // choose the stats
        Set<Statistic> statsSet = new LinkedHashSet<Statistic>();
        statsSet.add(Statistic.MIN);
        statsSet.add(Statistic.MAX);
        statsSet.add(Statistic.MEAN);
        statsSet.add(Statistic.VARIANCE);
        statsSet.add(Statistic.SDEV);
        statsSet.add(Statistic.RANGE);

        // select the bands to work on
        Integer[] bands = new Integer[] { 0 };
        List<Range<Double>> inclusionRanges = new ArrayList<Range<Double>>();
        inclusionRanges
                .add(new Range<Double>(Double.valueOf(0), false, Double.valueOf(1300), true));
        inclusionRanges.add(new Range<Double>(Double.valueOf(1370), true, Double.valueOf(1600),
                true));

        // create the proper instance
        StatisticsTool statisticsTool = new StatisticsTool(statsSet, coverage2D, bands,
                polygonList, inclusionRanges, Range.Type.INCLUDE, true);

        // do analysis
        statisticsTool.run();

        // get the results
        String id = "testpolygon.1";
        Map<Statistic, List<Result>> statistics = statisticsTool.getStatistics(id);
        LOGGER.info(id + statistics.toString());
        assertEquals(statistics.get(Statistic.RANGE).get(0).getValue().doubleValue(), 45.0, DELTA);
        assertEquals(statistics.get(Statistic.RANGE).get(1).getValue().doubleValue(), 228.0, DELTA);
        assertEquals(statistics.get(Statistic.SDEV).get(0).getValue().doubleValue(), 11.7972, DELTA);
        assertEquals(statistics.get(Statistic.SDEV).get(1).getValue().doubleValue(), 63.7335, DELTA);
        assertEquals(statistics.get(Statistic.MIN).get(0).getValue().doubleValue(), 1255.0, DELTA);
        assertEquals(statistics.get(Statistic.MIN).get(1).getValue().doubleValue(), 1370.0, DELTA);
        assertEquals(statistics.get(Statistic.MEAN).get(0).getValue().doubleValue(), 1283.1634,
                DELTA);
        assertEquals(statistics.get(Statistic.MEAN).get(1).getValue().doubleValue(), 1433.8979,
                DELTA);
        assertEquals(statistics.get(Statistic.VARIANCE).get(0).getValue().doubleValue(), 139.1754,
                DELTA);
        assertEquals(statistics.get(Statistic.VARIANCE).get(1).getValue().doubleValue(), 4061.9665,
                DELTA);
        assertEquals(statistics.get(Statistic.MAX).get(0).getValue().doubleValue(), 1300.0, DELTA);
        assertEquals(statistics.get(Statistic.MAX).get(1).getValue().doubleValue(), 1598.0, DELTA);

        reader.dispose();
        coverage2D.dispose(true);
        image.flush();
    }
View Full Code Here

    @Test
    public void simpleZonalStatsProcess() throws Exception {

        DataStore store = null;
        TIFFImageReader reader = null;
        GridCoverage2D coverage2D = null;
        GridCoverage2D covClassificator = null;
        SimpleFeatureIterator iterator = null;
        try {
            // build the feature collection
            final File fileshp = TestData.file(this, "testpolygon.shp");
            store = FileDataStoreFinder.getDataStore(fileshp.toURI().toURL());
            assertNotNull(store);
            assertTrue(store instanceof ShapefileDataStore);
            FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = store
                    .getFeatureSource(store.getNames().get(0));
            SimpleFeatureCollection featureCollection = (SimpleFeatureCollection) featureSource
                    .getFeatures();

            // build the DataFile
            final File tiff = TestData.file(this, "test.tif");
            final File tfw = TestData.file(this, "test.tfw");
            reader = (it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader) new TIFFImageReaderSpi()
                    .createReaderInstance();
            assertNotNull(reader);
            reader.setInput(ImageIO.createImageInputStream(tiff));
            final BufferedImage image = reader.read(0);

            final MathTransform transform = new WorldFileReader(tfw).getTransform();
            coverage2D = CoverageFactoryFinder.getGridCoverageFactory(null).create(
                    "coverage",
                    image,
                    new GridGeometry2D(new GridEnvelope2D(PlanarImage.wrapRenderedImage(image)
                            .getBounds()), transform, DefaultGeographicCRS.WGS84),
                    new GridSampleDimension[] { new GridSampleDimension("coverage") }, null, null);
            assertNotNull(coverage2D);

            // build the classificator
            // generate the classificator image
            final BufferedImage imageClassificator = new BufferedImage(120, 80,
                    BufferedImage.TYPE_BYTE_INDEXED);
            final WritableRaster raster = imageClassificator.getRaster();
            for (int i = raster.getWidth(); --i >= 0;) {
                for (int j = raster.getHeight(); --j >= 0;) {
                    // create a simple raster used for classification
                    int sampleValue = (i % 2 == 0) ? 1 : 2;
                    raster.setSample(i, j, 0, sampleValue);
                }
            }
            // create the coverage for the classification layer
            covClassificator = CoverageFactoryFinder.getGridCoverageFactory(null).create(
                    "coverageClassificator",
                    imageClassificator,
                    new GridGeometry2D(new GridEnvelope2D(PlanarImage.wrapRenderedImage(
                            imageClassificator).getBounds()), coverage2D.getEnvelope()),
                    new GridSampleDimension[] { new GridSampleDimension("coverage") }, null, null);
            assertNotNull(coverage2D);

            // invoke the process
            SimpleFeatureCollection sfc = process.execute(coverage2D, null, featureCollection,
                    covClassificator);

            iterator = sfc.features();
            assertNotNull(iterator);

            while (iterator.hasNext()) {
                SimpleFeature feature = iterator.next();
                assertTrue((feature.toString()).equals(results.get(feature.getID()
                        + feature.getAttribute("classification"))));
            }

        } finally {
            try {
                if (store != null) {
                    store.dispose();
                }
            } catch (Exception e) {
            }
            try {
                if (reader != null) {
                    reader.dispose();
                }
            } catch (Exception e) {
            }
            try {
                if (coverage2D != null) {
View Full Code Here

            FileNotFoundException, IIOException {
        File file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
        FileUtils.writeByteArrayToFile(file, tiffContents);
       
        // TODO: check the tiff structure is the one requested
        final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
        reader.setInput(new FileImageInputStream(file));      
       
        // compression
        final TIFFImageMetadata metadata=(TIFFImageMetadata) reader.getImageMetadata(0);
        assertNotNull(metadata);
        IIOMetadataNode root = (IIOMetadataNode)reader.getImageMetadata(0).getAsTree(TIFFImageMetadata.nativeMetadataFormatName);
        IIOMetadataNode field = getTiffField(root, BaselineTIFFTagSet.TAG_COMPRESSION);
        assertNotNull(field);
        assertEquals("JPEG", field.getFirstChild().getFirstChild().getAttributes().item(1).getNodeValue());
        assertEquals("7", field.getFirstChild().getFirstChild().getAttributes().item(0).getNodeValue());
       
        IIOMetadataNode node = metadata.getStandardDataNode();
        assertNotNull(node);
        assertEquals("PlanarConfiguration", node.getFirstChild().getNodeName());
        assertEquals("PixelInterleaved", node.getFirstChild().getAttributes().item(0).getNodeValue());
       
       
        // clean up
        reader.dispose();
    }
View Full Code Here

        byte[] tiffContents = getBinary(response);
        File file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
        FileUtils.writeByteArrayToFile(file, tiffContents);
       
        // TODO: check the tiff structure is the one requested
        final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
        reader.setInput(new FileImageInputStream(file));      
       
        // compression
        final TIFFImageMetadata metadata=(TIFFImageMetadata) reader.getImageMetadata(0);
        assertNotNull(metadata);
       
        IIOMetadataNode node = metadata.getStandardDataNode();
        assertNotNull(node);
        assertEquals("PlanarConfiguration", node.getFirstChild().getNodeName());
        assertEquals("PixelInterleaved", node.getFirstChild().getAttributes().item(0).getNodeValue());
       
       
        // clean up
        reader.dispose();
       
        //unsupported or wrong
        response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1" +
                "&coverageId=wcs__BlueMarble&interleave=band");
View Full Code Here

        byte[] tiffContents = getBinary(response);
        File file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
        FileUtils.writeByteArrayToFile(file, tiffContents);
       
        // TODO: check the tiff structure is the one requested
        final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
        reader.setInput(new FileImageInputStream(file));      
       
        // compression
        final TIFFImageMetadata metadata=(TIFFImageMetadata) reader.getImageMetadata(0);
        assertNotNull(metadata);
        IIOMetadataNode root = (IIOMetadataNode)reader.getImageMetadata(0).getAsTree(TIFFImageMetadata.nativeMetadataFormatName);
        IIOMetadataNode field = getTiffField(root, BaselineTIFFTagSet.TAG_COMPRESSION);
        assertNotNull(field);
        assertEquals("Deflate", field.getFirstChild().getFirstChild().getAttributes().item(1).getNodeValue());
        assertEquals("32946", field.getFirstChild().getFirstChild().getAttributes().item(0).getNodeValue());
       
        IIOMetadataNode node = metadata.getStandardDataNode();
        assertNotNull(node);
        assertEquals("PlanarConfiguration", node.getFirstChild().getNodeName());
        assertEquals("PixelInterleaved", node.getFirstChild().getAttributes().item(0).getNodeValue());
       
       
        // clean up
        reader.dispose();
    }
View Full Code Here

        byte[] tiffContents = getBinary(response);
        File file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
        FileUtils.writeByteArrayToFile(file, tiffContents);
       
        // TODO: check the tiff structure is the one requested
        final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
        reader.setInput(new FileImageInputStream(file));      
       
        // compression
        final TIFFImageMetadata metadata=(TIFFImageMetadata) reader.getImageMetadata(0);
        assertNotNull(metadata);
        IIOMetadataNode root = (IIOMetadataNode)reader.getImageMetadata(0).getAsTree(TIFFImageMetadata.nativeMetadataFormatName);
        IIOMetadataNode field = getTiffField(root, BaselineTIFFTagSet.TAG_COMPRESSION);
        assertNotNull(field);
        assertEquals("LZW", field.getFirstChild().getFirstChild().getAttributes().item(1).getNodeValue());
        assertEquals("5", field.getFirstChild().getFirstChild().getAttributes().item(0).getNodeValue());
       
        IIOMetadataNode node = metadata.getStandardDataNode();
        assertNotNull(node);
        assertEquals("PlanarConfiguration", node.getFirstChild().getNodeName());
        assertEquals("PixelInterleaved", node.getFirstChild().getAttributes().item(0).getNodeValue());
       
       
        // clean up
        reader.dispose();
    }
View Full Code Here

        byte[] tiffContents = getBinary(response);
        File file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
        FileUtils.writeByteArrayToFile(file, tiffContents);
       
        // TODO: check the tiff structure is the one requested
        final TIFFImageReader reader = (TIFFImageReader) new TIFFImageReaderSpi().createReaderInstance();
        reader.setInput(new FileImageInputStream(file));
       
        // tiling
        assertTrue(reader.isImageTiled(0));
        assertEquals(256, reader.getTileHeight(0));
        assertEquals(256, reader.getTileWidth(0));
       
        IIOMetadataNode node =((TIFFImageMetadata) reader.getImageMetadata(0)).getStandardDataNode();
        assertNotNull(node);
        assertEquals("PlanarConfiguration", node.getFirstChild().getNodeName());
        assertEquals("PixelInterleaved", node.getFirstChild().getAttributes().item(0).getNodeValue());

       
        // wrong values
        response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1" +
                "&coverageId=wcs__BlueMarble" +
                "&interleave=pixel&tiling=true&tileheight=13&tilewidth=256");

        assertEquals("application/xml", response.getContentType());
        checkOws20Exception(response, 404, WcsExceptionCode.TilingInvalid.toString(), "13");
       
       
        response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1" +
                "&coverageId=wcs__BlueMarble" +
                "&interleave=pixel&tiling=true&tileheight=13&tilewidth=11");

        assertEquals("application/xml", response.getContentType());
        checkOws20Exception(response, 404, WcsExceptionCode.TilingInvalid.toString(), "11");
       
        // default
        response = getAsServletResponse("wcs?request=GetCoverage&service=WCS&version=2.0.1" +
        "&coverageId=wcs__BlueMarble&tiling=true");

        assertEquals("image/tiff", response.getContentType());
        tiffContents = getBinary(response);
        file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
        FileUtils.writeByteArrayToFile(file, tiffContents);
       
        // TODO: check the tiff structure is the one requested
        reader.setInput(new FileImageInputStream(file));
       
        // tiling
        assertTrue(reader.isImageTiled(0));
        assertEquals(368, reader.getTileHeight(0));
        assertEquals(368, reader.getTileWidth(0));
       
        node =((TIFFImageMetadata) reader.getImageMetadata(0)).getStandardDataNode();
        assertNotNull(node);
        assertEquals("PlanarConfiguration", node.getFirstChild().getNodeName());
        assertEquals("PixelInterleaved", node.getFirstChild().getAttributes().item(0).getNodeValue());
       
        // clean up
        reader.dispose();       
    }
View Full Code Here

TOP

Related Classes of it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.