Package org.geotools.coverage.grid

Examples of org.geotools.coverage.grid.GridCoverage2D


        // Setting of the parameters
        Map<String, String> metadata = new HashMap<String, String>();
        metadata.put("testKey", "testMetadata");
        List<GridCoverage2D> data = new ArrayList<GridCoverage2D>();
        GridCoverage2D cov = new GridCoverageFactory().create(TEST_NAME.getLocalPart(),
                new float[][] { { 1.0f, 1.0f } }, new ReferencedEnvelope(0.0d, 1.0d, 0.0d, 1.0d,
                        null));
        data.add(cov);
        request.setMetadata(metadata);
        request.setData(data);

        // Get the response
        CoverageResponse response = store.update(request, null);

        Collection<? extends Coverage> results = response.getResults(null);
        // Ensure the results are not null and it is not empty
        assertTrue(results != null);
        assertTrue(!results.isEmpty());
        // Get the first result from the collection and ensure it is the same coverage of the input
        GridCoverage2D covOutput = (GridCoverage2D) results.iterator().next();
        assertSame(cov, covOutput);

        // Ensure they have the same metadata
        CoverageUpdateRequest request2 = (CoverageUpdateRequest) response.getRequest();
        assertEquals(metadata.get("testKey"), request2.getMetadata().get("testKey"));
View Full Code Here


   
    // create a response for the provided request
    final RasterLayerResponse response= new RasterLayerResponse(request,this);
   
    // execute the request
    final GridCoverage2D elem = response.createResponse();
    if (elem != null){
      return Collections.singletonList(elem);
    }
    return Collections.emptyList();
   
View Full Code Here

 
    //
    // Abusing of the created ImageMosaicreader for getting a
    // gridcoverage2d, then rename it
    //
    GridCoverage2D mosaicCoverage = reader.read(params);
    if(mosaicCoverage != null) {
        return new GridCoverage2D(coverageName, mosaicCoverage);
    } else {
        // the mosaic can still return null in corner cases, handle that gracefully
        return null;
    }
  }
View Full Code Here

        // Initialization of the helper
        SpatialRequestHelper helper = new SpatialRequestHelper();
        ReferencedEnvelope envelope = new ReferencedEnvelope(-180, 0, -90, 90,
                coverageProperties.getGeographicCRS2D());
        // Creation of a dummy GridCoverage 2D
        GridCoverage2D coverage2 = new GridCoverageFactory(GeoTools.getDefaultHints()).create(
                "testCoverage", image, envelope);
        CoverageProperties coverageProperties2 = new CoverageProperties();
        coverageProperties2.setBbox(new ReferencedEnvelope(coverage2.getEnvelope2D()));
        coverageProperties2.setCrs2D(coverage2.getCoordinateReferenceSystem2D());
        coverageProperties2.setFullResolution(CoverageUtilities
                .getResolution((AffineTransform) coverage2.getGridGeometry().getGridToCRS2D(
                        PixelOrientation.UPPER_LEFT)));
        coverageProperties2.setRasterArea(coverage2.getGridGeometry().getGridRange2D());
        coverageProperties2.setGeographicBBox(new ReferencedEnvelope(coverage2.getEnvelope2D()));
        coverageProperties2.setGeographicCRS2D(coverage2.getCoordinateReferenceSystem2D());
        coverageProperties2.setGridToWorld2D(coverage2.getGridGeometry().getGridToCRS2D(
                PixelOrientation.UPPER_LEFT));
        // Final GridGeometry
        GridEnvelope2D gridRange = new GridEnvelope2D(0, 0, 1024, 1024);
        ReferencedEnvelope envelope2 = new ReferencedEnvelope(1, 180, -90, 90,
                coverageProperties.getGeographicCRS2D());
View Full Code Here

     
      // write down a fake geotiff with non-standard CRS
      GridCoverageFactory factory = new GridCoverageFactory();
            BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_4BYTE_ABGR);
            ReferencedEnvelope envelope = new ReferencedEnvelope(0, 10, 0, 10,DefaultGeographicCRS.WGS84);
            GridCoverage2D test = factory.create("test", bi, envelope);
            GeoTiffWriter writer = new GeoTiffWriter(geotiff);
            writer.write(test, null);
            writer.dispose();
   
            // read
View Full Code Here

    // /////////////////////////////////////////////////////////////////////
    //
    // Read the original coverage.
    //
    // /////////////////////////////////////////////////////////////////////
    GridCoverage2D gc = (GridCoverage2D) reader.read(null);
    if (TestData.isInteractiveTest()) {
      LOGGER.info(new StringBuilder("Coverage before: ").append("\n")
          .append(gc.getCoordinateReferenceSystem().toWKT()).append(
              gc.getEnvelope().toString()).toString());
    }
    final CoordinateReferenceSystem sourceCRS = gc.getCoordinateReferenceSystem2D();
    final GeneralEnvelope sourceEnvelope = (GeneralEnvelope) gc.getEnvelope();
    final GridGeometry2D sourcedGG = (GridGeometry2D) gc.getGridGeometry();
    final MathTransform sourceG2W = sourcedGG.getGridToCRS(PixelInCell.CELL_CENTER);

    // /////////////////////////////////////////////////////////////////////
    //
    //
    // CROP
    //
    //
    // /////////////////////////////////////////////////////////////////////

    // /////////////////////////////////////////////////////////////////////
    //
    // Crop the original coverage.
    //
    // /////////////////////////////////////////////////////////////////////
    double xc = sourceEnvelope.getMedian(0);
    double yc = sourceEnvelope.getMedian(1);
    double xl = sourceEnvelope.getSpan(0);
    double yl = sourceEnvelope.getSpan(1);
    final GeneralEnvelope cropEnvelope = new GeneralEnvelope(new double[] {
        xc - xl / 4.0, yc - yl / 4.0 }, new double[] { xc + xl / 4.0,
        yc + yl / 4.0 });
    final CoverageProcessor processor = CoverageProcessor.getInstance();
    final ParameterValueGroup param = processor
        .getOperation("CoverageCrop").getParameters();
    param.parameter("Source").setValue(gc);
    param.parameter("Envelope").setValue(cropEnvelope);
    final GridCoverage2D cropped = (GridCoverage2D) processor.doOperation(param);

    // /////////////////////////////////////////////////////////////////////
    //
    // Check that we got everything correctly after the crop.
    //
    // /////////////////////////////////////////////////////////////////////
    // checking the ranges of the output image.
    final GridGeometry2D croppedGG = (GridGeometry2D) cropped.getGridGeometry();
    final GridEnvelope croppedGR = croppedGG.getGridRange();
    final MathTransform croppedG2W = croppedGG.getGridToCRS(PixelInCell.CELL_CENTER);
    final GeneralEnvelope croppedEnvelope = (GeneralEnvelope) cropped.getEnvelope();
    assertTrue("min x do not match after crop", 29 == croppedGR.getLow(0));
    assertTrue("min y do not match after crop", 30 == croppedGR.getLow(1));
    assertTrue("max x do not match after crop", 90 == croppedGR.getHigh(0)+1);
    assertTrue("max y do not match after crop", 91 == croppedGR.getHigh(1)+1);
    // check that the affine transform are the same thing
    assertTrue(
        "The Grdi2World tranformations of the original and the cropped covearage do not match",
        sourceG2W.equals(croppedG2W));
    // check that the envelope is correct
    final GeneralEnvelope expectedEnvelope = new GeneralEnvelope(croppedGR,PixelInCell.CELL_CENTER, croppedG2W, cropped.getCoordinateReferenceSystem2D());
    assertTrue("Expected envelope is different from the computed one",expectedEnvelope.equals(croppedEnvelope, XAffineTransform.getScale((AffineTransform) croppedG2W) / 2.0, false));

    //release things
    cropped.dispose(true);
    gc.dispose(true);
    try{
      if(reader!=null)
        reader.dispose();
    }catch (Throwable e) {
    }
    // /////////////////////////////////////////////////////////////////////
    //
    //
    // WRITING AND TESTING
    //
    //
    // /////////////////////////////////////////////////////////////////////
    final File writeFile = new File(new StringBuilder(writedir.getAbsolutePath()).append(File.separatorChar).append(cropped.getName().toString()).append(".tiff").toString());
    final GridCoverageWriter writer = format.getWriter(writeFile);
   
    try{
      writer.write(cropped, null);
    }catch (IOException e) {
    }
    finally{
      try{
        writer.dispose();
      }catch (Throwable e) {
      }
    }
    try{
      reader = new GeoTiffReader(writeFile, null);
      assertNotNull(reader);
      gc = (GridCoverage2D) reader.read(null);
      assertNotNull(gc);
      final CoordinateReferenceSystem targetCRS = gc.getCoordinateReferenceSystem2D();
      assertTrue(
          "Source and Target coordinate reference systems do not match",
          CRS.equalsIgnoreMetadata(sourceCRS, targetCRS));
      assertEquals("Read-back and Cropped envelopes do not match", cropped
          .getEnvelope(), croppedEnvelope);
 
      if (TestData.isInteractiveTest()) {
        LOGGER.info(new StringBuilder("Coverage after: ").append("\n")
            .append(gc.getCoordinateReferenceSystem().toWKT()).append(
View Full Code Here

       
        // getting a reader
        GeoTiffReader reader = new GeoTiffReader(testFile);

        // reading the coverage
        GridCoverage2D coverage = (GridCoverage2D) reader.read(null);

        // check coverage and crs
        assertNotNull(coverage);
        assertNotNull(coverage.getCoordinateReferenceSystem());
        assertEquals(CRS.lookupIdentifier(coverage.getCoordinateReferenceSystem(), true),"EPSG:4267");
        reader.dispose();
       
        // reproject
        coverage=(GridCoverage2D) Operations.DEFAULT.resample(coverage, googleCRS);
       
       
        // get a writer
        final File mercator = new File(TestData.file(GeoTiffReaderTest.class, "."),"wms_900913.tif");
        GeoTiffWriter writer = new GeoTiffWriter(mercator);
       
        writer.write(coverage,null );
        writer.dispose();
       
       
        // getting a reader
        reader = new GeoTiffReader(mercator);
        // reading the coverage
        GridCoverage2D coverageMercator = (GridCoverage2D) reader.read(null);
     // check coverage and crs
        assertNotNull(coverageMercator);
        assertNotNull(coverageMercator.getCoordinateReferenceSystem());
        assertTrue(CRS.equalsIgnoreMetadata(coverage.getCoordinateReferenceSystem(),googleCRS));
        assertTrue(coverage.getEnvelope2D().getFrame().equals(coverageMercator.getEnvelope2D().getFrame()));
        reader.dispose();
        coverage.dispose(true);
        coverage.dispose(true);

               
View Full Code Here

          // getting a reader
          GeoTiffReader reader = new GeoTiffReader(noCrs, hint);

          // reading the coverage
          GridCoverage2D coverage = (GridCoverage2D) reader.read(null);

          // check coverage and crs
          assertNotNull(coverage);
          assertNotNull(coverage.getCoordinateReferenceSystem());
          assertEquals(CRS.lookupIdentifier(coverage.getCoordinateReferenceSystem(), true),
                  "EPSG:32632");
          reader.dispose();
         
         
          // get a writer
          final File noCrsTFW = new File(TestData.file(GeoTiffReaderTest.class, "."),"no_crs_tfw.tif");
          GeoTiffWriter writer = new GeoTiffWriter(noCrsTFW);
         
          final ParameterValue<Boolean> tfw = GeoTiffFormat.WRITE_TFW.createValue();
          tfw.setValue(true);
          writer.write(coverage,new GeneralParameterValue[]{tfw} );
          writer.dispose();
          coverage.dispose(true);
         
          final File finalTFW=new File(noCrsTFW.getParent(),noCrsTFW.getName().replace("tif", "tfw"));
          assertTrue(finalTFW.canRead());
          WorldFileReader worldFileReader = new WorldFileReader(finalTFW);
          assertEquals(656217.52088, worldFileReader.getXULC(), DELTA);
View Full Code Here

        // getting a reader
        GeoTiffReader reader = new GeoTiffReader(input);

        // reading the coverage
        GridCoverage2D coverage = (GridCoverage2D) reader.read(null);

        // check coverage and crs
        assertNotNull(coverage);
        assertNotNull(coverage.getCoordinateReferenceSystem());
        reader.dispose();

        // get a writer
        final File output = new File(TestData.file(GeoTiffReaderTest.class, "."), "outMetadata.tif");
        GeoTiffWriter writer = new GeoTiffWriter(output);
       
        // Setting a COPYRIGHT metadata
        String copyrightInfo = "(C) GEOTOOLS sample writer";
        String software = "GeoTools Coverage Writer test";
       
        writer.setMetadataValue(Integer.toString(BaselineTIFFTagSet.TAG_COPYRIGHT), copyrightInfo);
        writer.setMetadataValue(TagSet.BASELINE + ":" + Integer.toString(BaselineTIFFTagSet.TAG_SOFTWARE), software);
       
        writer.write(coverage,null);
        writer.dispose();
        coverage.dispose(true);
       
        // getting a reader
        reader = new GeoTiffReader(output);

        GeoTiffIIOMetadataDecoder metadata = reader.getMetadata();
View Full Code Here

        // getting a reader
        GeoTiffReader reader = new GeoTiffReader(input);

        // reading the coverage
        GridCoverage2D coverage = (GridCoverage2D) reader.read(null);

        // check coverage and crs
        assertNotNull(coverage);
        assertNotNull(coverage.getCoordinateReferenceSystem());
        reader.dispose();

        // get a writer
        final File output = new File(TestData.file(GeoTiffReaderTest.class, "."), "outMetadata.tif");
        GeoTiffWriter writer = new GeoTiffWriter(output);
       
        // Setting a COPYRIGHT metadata       
        ParameterValue<ProgressListener> listener = GeoTiffFormat.PROGRESS_LISTENER.createValue();
       
        listener.setValue(new ProgressListener(){
                private boolean canceled;

                @Override
                public InternationalString getTask() {
                    // TODO Auto-generated method stub
                    return null;
                }

                @Override
                public String getDescription() {
                    // TODO Auto-generated method stub
                    return null;
                }

                @Override
                public void setTask(InternationalString task) {
                    // TODO Auto-generated method stub
                   
                }

                @Override
                public void setDescription(String description) {
                    // TODO Auto-generated method stub
                   
                }

                @Override
                public void started() {
                    LOGGER.info("started");
                   
                }

                @Override
                public void progress(float percent) {
                    LOGGER.info("progress:"+percent);
                    assertTrue(percent>=0);
                    assertTrue(percent<=100);
                    if(percent>50)
                        setCanceled(true);                   
                       
                   
                }

                @Override
                public float getProgress() {
                    // TODO Auto-generated method stub
                    return 0;
                }

                @Override
                public void complete() {
                    LOGGER.info("complete");
                   
                }

                @Override
                public void dispose() {
                    // TODO Auto-generated method stub
                   
                }

                @Override
                public boolean isCanceled() {
                    return canceled;
                }

                @Override
                public void setCanceled(boolean cancel) {
                    canceled=cancel;
                   
                }

                @Override
                public void warningOccurred(String source, String location, String warning) {
                    // TODO Auto-generated method stub
                   
                }

                @Override
                public void exceptionOccurred(Throwable exception) {
                    // TODO Auto-generated method stub
                   
                }           
        });
        writer.write(coverage,new GeneralParameterValue[]{listener});
        writer.dispose();
        coverage.dispose(true);
       
    }
View Full Code Here

TOP

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

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.