Package org.geotools.coverage.grid

Examples of org.geotools.coverage.grid.GridGeometry2D


                        oldEnvelope.getUpperCorner().getOrdinate(1) });
        cropEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader
                .getFormat()).READ_GRIDGEOMETRY2D.createValue();
        gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0,
                (int) (range.width / 4.0 / cropFactor),
                (int) (range.height / 4.0 / cropFactor))), cropEnvelope));
        gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });
        Assert.assertNotNull(gc);
        // NOTE: in some cases might be too restrictive
        Assert.assertTrue(cropEnvelope.equals(gc.getEnvelope(), XAffineTransform
                .getScale(((AffineTransform) ((GridGeometry2D) gc
                        .getGridGeometry()).getGridToCRS2D())) / 2, true));

        forceDataLoading(gc);

        // /////////////////////////////////////////////////////////////////////
        //
        // Attempt to read an envelope which doesn't intersect the dataset one
        //
        // /////////////////////////////////////////////////////////////////////
        final double translate0 = oldEnvelope.getSpan(0) + 100;
        final double translate1 = oldEnvelope.getSpan(1) + 100;
        final GeneralEnvelope wrongEnvelope = new GeneralEnvelope(new double[] {
                oldEnvelope.getLowerCorner().getOrdinate(0) + translate0,
                oldEnvelope.getLowerCorner().getOrdinate(1) + translate1 },
                new double[] {
                        oldEnvelope.getUpperCorner().getOrdinate(0)
                                + translate0,

                        oldEnvelope.getUpperCorner().getOrdinate(1)
                                + translate1 });
        wrongEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        final ParameterValue gg2 = (ParameterValue) ((AbstractGridFormat) reader
                .getFormat()).READ_GRIDGEOMETRY2D.createValue();
        gg2.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0,
                0, (int) (range.width), (int) (range.height))), wrongEnvelope));

        gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg2 });
        Assert.assertNull("Wrong envelope requested", gc);
    }
View Full Code Here


                });
        cropEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader.getFormat()).READ_GRIDGEOMETRY2D
            .createValue();
        gg.setValue(new GridGeometry2D(
                new GridEnvelope2D(
                    new Rectangle(0, 0, (int) (range.width / 2.0 / cropFactor),
                        (int) (range.height / 2.0 / cropFactor))), cropEnvelope));
        gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });
        forceDataLoading(gc);
View Full Code Here

            oldEnvelope.getUpperCorner().getOrdinate(1) });
    cropEnvelope.setCoordinateReferenceSystem(reader.getCrs());

    final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader
        .getFormat()).READ_GRIDGEOMETRY2D.createValue();
    gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0,
        (int) (range.width / 2.0 / cropFactor),
        (int) (range.height / 2.0 / cropFactor))), cropEnvelope));
    gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });
    forceDataLoading(gc);
  }
View Full Code Here

     */
    private GridCoverage2D affine(GridCoverage2D input, double[] bkgValues) {
     // NOTICE that at this stage the image we get should be 8 bits, either RGB, RGBA, Gray, GrayA
        // either multiband or indexed. It could also be 16 bits indexed!!!!
        final RenderedImage finalImage = input.getRenderedImage();
        final GridGeometry2D preSymbolizerGridGeometry = (input.getGridGeometry());
        // I need to translate half of a pixel since in wms the envelope
        // map to the corners of the raster space not to the center of the
        // pixels.
        final MathTransform2D finalGCTransform=preSymbolizerGridGeometry.getGridToCRS2D(PixelOrientation.UPPER_LEFT);
        if (!(finalGCTransform instanceof AffineTransform)) {
            throw new UnsupportedOperationException(
                    "Non-affine transformations not yet implemented"); // TODO
        }
        final AffineTransform finalGCgridToWorld = new AffineTransform((AffineTransform) finalGCTransform);


        // //
        //
        // I am going to concatenate the final world to grid transform for the
        // screen area with the grid to world transform of the input coverage.
        //
        // This way i right away position the coverage at the right place in the
        // area of interest for the device.
        //
        // //
        final AffineTransform finalRasterTransformation = (AffineTransform) finalWorldToGrid.clone();
        finalRasterTransformation.concatenate(finalGCgridToWorld);
      
        //paranoiac check to avoid that JAI freaks out when computing its internal layouT on images that are too small
        Rectangle2D finalLayout= GridCoverageRendererUtilities.layoutHelper(
                        finalImage,
                        (float)finalRasterTransformation.getScaleX(),
                        (float)finalRasterTransformation.getScaleY(),
                        (float)finalRasterTransformation.getTranslateX(),
                        (float)finalRasterTransformation.getTranslateY(),
                        interpolation);
        if(finalLayout.isEmpty()){
                if(LOGGER.isLoggable(java.util.logging.Level.FINE))
                        LOGGER.fine("Unable to create a granuleDescriptor "+this.toString()+ " due to jai scale bug");
                return null;
        }

        RenderedImage im=null;
        try {
            ImageWorker iw = new ImageWorker(finalImage);
            iw.setRenderingHints(hints);
            iw.affine(finalRasterTransformation, interpolation, bkgValues);
            im = iw.getRenderedImage();
        } finally {
                if(DEBUG){
                    writeRenderedImage(im, "postAffine");
                }
        }       
        // recreate gridCoverage
        int numBands = im.getSampleModel().getNumBands();
        GridSampleDimension[] sd = new GridSampleDimension[numBands];
        for(int i=0;i<numBands;i++) {
            sd[i]= new GridSampleDimension(TypeMap.getColorInterpretation(im.getColorModel(), i).name());
        }
       
        // create a new grid coverage but preserve as much input as possible
       return this.gridCoverageFactory.create(
               input.getName(),
                im,
                new GridGeometry2D(
                        new GridEnvelope2D(PlanarImage.wrapRenderedImage(im).getBounds()),
                        input.getEnvelope()),
                sd,
                new GridCoverage[] { input },
                input.getProperties());   
View Full Code Here

        }
    }

    private GridCoverage2D displaceCoverage(GridCoverage2D coverage, double tx, double ty) {
        // let's compute the new grid geometry
        GridGeometry2D originalGG = coverage.getGridGeometry();
        GridEnvelope gridRange = originalGG.getGridRange();
        Envelope2D envelope = originalGG.getEnvelope2D();
       
        double minx = envelope.getMinX() + tx;
        double miny = envelope.getMinY() + ty;
        double maxx = envelope.getMaxX() + tx;
        double maxy = envelope.getMaxY() + ty;
        ReferencedEnvelope translatedEnvelope = new ReferencedEnvelope(minx, maxx, miny, maxy,
                envelope.getCoordinateReferenceSystem());

        GridGeometry2D translatedGG = new GridGeometry2D(gridRange, translatedEnvelope);

        GridCoverage2D translatedCoverage = gridCoverageFactory.create(coverage.getName(),
                coverage.getRenderedImage(), translatedGG, coverage.getSampleDimensions(),
                new GridCoverage2D[] { coverage }, coverage.getProperties());
        return translatedCoverage;
View Full Code Here

                });
        cropEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader.getFormat()).READ_GRIDGEOMETRY2D
            .createValue();
        gg.setValue(new GridGeometry2D(
                new GridEnvelope2D(
                    new Rectangle(0, 0, (int) (range.width / 2.0 / cropFactor),
                        (int) (range.height / 2.0 / cropFactor))), cropEnvelope));
        gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });
        forceDataLoading(gc);
View Full Code Here

        final JP2MrSIDReader reader = new JP2MrSIDReader(file);
        final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader.getFormat()).READ_GRIDGEOMETRY2D
            .createValue();
        final GeneralEnvelope oldEnvelope = reader.getOriginalEnvelope();
        gg.setValue(new GridGeometry2D(reader.getOriginalGridRange(), oldEnvelope));

        final GridCoverage2D gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });

        Assert.assertNotNull(gc);
View Full Code Here

        final BaseGDALGridCoverage2DReader reader = new JP2KReader(file);
        final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader.getFormat()).READ_GRIDGEOMETRY2D
            .createValue();
        final GeneralEnvelope oldEnvelope = reader.getOriginalEnvelope();
        gg.setValue(new GridGeometry2D(reader.getOriginalGridRange(), oldEnvelope));

        final GridCoverage2D gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });
        forceDataLoading(gc);
       
        if (TestData.isInteractiveTest()) {
View Full Code Here

                        originalEnvelope.getMedian().getOrdinate(1)});
        reducedEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader
                .getFormat()).READ_GRIDGEOMETRY2D.createValue();
        gg.setValue(new GridGeometry2D(new GridEnvelope2D(new Rectangle(0, 0,
                (int) (range.width / 2.0),
                (int) (range.height / 2.0))), reducedEnvelope));
        gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });
        Assert.assertNotNull(gc);
        // NOTE: in some cases might be too restrictive
View Full Code Here

                });
        cropEnvelope.setCoordinateReferenceSystem(reader.getCrs());

        final ParameterValue gg = (ParameterValue) ((AbstractGridFormat) reader.getFormat()).READ_GRIDGEOMETRY2D
            .createValue();
        gg.setValue(new GridGeometry2D(
                new GridEnvelope2D(
                    new Rectangle(0, 0, (int) (range.width / 2.0 / cropFactor),
                        (int) (range.height / 2.0 / cropFactor))), cropEnvelope));
        gc = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg });
        forceDataLoading(gc);
View Full Code Here

TOP

Related Classes of org.geotools.coverage.grid.GridGeometry2D

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.