Package org.geotools.coverage.grid

Examples of org.geotools.coverage.grid.GridCoverage2D


     * {@link org.geotools.coverage.processing.DefaultProcessor}
     * for the {@code "Resample"} operation.
     */
    @SuppressWarnings("unchecked")
    public Coverage doOperation(final ParameterValueGroup parameters, final Hints hints) {
        final GridCoverage2D source = (GridCoverage2D) parameters.parameter("Source").getValue();
        final Interpolation interpolation = ImageUtilities.toInterpolation(
                parameters.parameter("InterpolationType").getValue());
        CoordinateReferenceSystem targetCRS = (CoordinateReferenceSystem)
                parameters.parameter("CoordinateReferenceSystem").getValue();
        if (targetCRS == null) {
            targetCRS = source.getCoordinateReferenceSystem();
        }
        final GridGeometry2D targetGG = GridGeometry2D.wrap(
                (GridGeometry) parameters.parameter("GridGeometry").getValue());
        final Object bgValueParam = parameters.parameter("BackgroundValues");
        final double [] bgValues;
        if (bgValueParam != null && bgValueParam instanceof Parameter<?>){
            bgValues = ((Parameter<double[]>)bgValueParam).getValue();
        } else {
            bgValues = null;
        }
        try {
            return Resampler2D.reproject(source, targetCRS, targetGG, interpolation,
                (hints instanceof Hints) ? hints : new Hints(hints), bgValues);
        } catch (FactoryException exception) {
            throw new CannotReprojectException(Errors.format(
                    ErrorKeys.CANT_REPROJECT_$1, source.getName()), exception);
        } catch (TransformException exception) {
            throw new CannotReprojectException(Errors.format(
                    ErrorKeys.CANT_REPROJECT_$1, source.getName()), exception);
        }
    }
View Full Code Here


        try {
            String[] names = reader.getGridCoverageNames();
            assertNotNull(names);
            assertEquals(2,names.length);
            assertEquals("ROOT/LEVEL1/V2",names[0]);
            GridCoverage2D grid = reader.read("ROOT/LAI", null);
            assertNotNull(grid);
            byte[] byteValue = grid.evaluate(new
                    DirectPosition2D(DefaultGeographicCRS.WGS84, 12, 70 ), new byte[1]);
            assertEquals(20,byteValue[0]);

            byteValue = grid.evaluate(new
                    DirectPosition2D(DefaultGeographicCRS.WGS84, 23, 40), new byte[1]);
            assertEquals(90,byteValue[0]);


        } finally {
View Full Code Here

        try {
            String[] names = reader.getGridCoverageNames();
            assertNotNull(names);
            assertEquals(2,names.length);

            GridCoverage2D grid = reader.read("O3", null);
            assertNotNull(grid);
            float[] value = grid.evaluate((DirectPosition) new
                    DirectPosition2D(DefaultGeographicCRS.WGS84, 5, 45 ), new float[1]);
            assertEquals(47.63341f,value[0],0.00001);

            value = grid.evaluate((DirectPosition) new
                    DirectPosition2D(DefaultGeographicCRS.WGS84, 5, 45.125), new float[1]);
            assertEquals(52.7991f, value[0],0.000001);


        } finally {
View Full Code Here

                        add(450d); // Elevation
                    }
                });

                GeneralParameterValue[] values = new GeneralParameterValue[] { gg, time, elevation };
                GridCoverage2D coverage = reader.read(coverageName, values);
                assertNotNull(coverage);
                if (TestData.isInteractiveTest()) {
                    coverage.show();
                } else {
                    PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
                }
            }
        } catch (Throwable t) {
            throw new RuntimeException(t);
        } finally {
View Full Code Here

                FilterFactory2 FF = FeatureUtilities.DEFAULT_FILTER_FACTORY;
                Filter filter = FF.equals(FF.property("z"), FF.literal(450.0));
                filterParam.setValue(filter);

                GeneralParameterValue[] values = new GeneralParameterValue[] { filterParam };
                GridCoverage2D coverage = reader.read(coverageName, values);
                assertNotNull(coverage);
                if (TestData.isInteractiveTest()) {
                    coverage.show();
                } else {
                    PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
                }
            }
        } catch (Throwable t) {
            throw new RuntimeException(t);
        } finally {
View Full Code Here

                    }
                });

                GeneralParameterValue[] values = coverageName.equalsIgnoreCase("O3") ? new GeneralParameterValue[] { gg, time, elevation } : new GeneralParameterValue[] { gg, time};
               
                GridCoverage2D coverage = reader.read(coverageName, values);
                assertNotNull(coverage);
                if (TestData.isInteractiveTest()) {
                    coverage.show();
                } else {
                    PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
                }
            }
        } catch (Throwable t) {
            throw new RuntimeException(t);
        } finally {
View Full Code Here

                    }
                });

                GeneralParameterValue[] values = coverageName.equalsIgnoreCase("O3") ? new GeneralParameterValue[] { gg, time, elevation } : new GeneralParameterValue[] { gg, time};
               
                GridCoverage2D coverage = reader.read(coverageName, values);
                assertNotNull(coverage);
                if (TestData.isInteractiveTest()) {
                    coverage.show();
                } else {
                    PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
                }
            }
        } catch (Throwable t) {
            throw new RuntimeException(t);
        } finally {
View Full Code Here

                      });
                  }
              }
             
              GeneralParameterValue[] values = new GeneralParameterValue[] { gg, sigmaValue};
              GridCoverage2D coverage = reader.read(coverageName, values);
              assertNotNull(coverage);
              if (TestData.isInteractiveTest()) {
                  coverage.show();
              } else {
                  PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
              }
          }
      } catch (Throwable t) {
          throw new RuntimeException(t);
      } finally {
View Full Code Here

                    });
                }
            }

            GeneralParameterValue[] values = new GeneralParameterValue[] { gg,new_ };
            GridCoverage2D coverage = reader.read(coverageName, values);
            assertNotNull(coverage);
            if (TestData.isInteractiveTest()) {
                coverage.show();
            } else {
                PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();
            }
        } finally {
            if (reader != null) {
                try {
                    reader.dispose();
View Full Code Here

   * @see org.opengis.coverage.grid.GridCoverageWriter#write(org.geotools.gc.GridCoverage,
   *      org.opengis.parameter.GeneralParameterValue[])
   */
  public void write(GridCoverage coverage, GeneralParameterValue[] parameters)
      throws IllegalArgumentException, IOException {
    final GridCoverage2D gc = (GridCoverage2D) coverage;
    // checking parameters
    // if provided we have to use them
    // specifically this is one of the way we can provide an output format
    if (parameters != null) {
      this.extension = ((Parameter) parameters[0]).stringValue();
    }
   
    // /////////////////////////////////////////////////////////////////////
    //
    // WorldFile and projection file.
    //
    // ////////////////////////////////////////////////////////////////////
    if (destination instanceof File) {
      // files destinations
      File imageFile = (File) destination;
      final String path = imageFile.getAbsolutePath();
      final int index = path.lastIndexOf(".");
      final String baseFile = index >= 0 ? path.substring(0, index)
          : path;

      // envelope and image
      final RenderedImage image = gc.getRenderedImage();

      // world file
      try {
        createWorldFile(coverage, image, baseFile,extension);
      } catch (TransformException e) {
        final IOException ex = new IOException();
        ex.initCause(e);
        throw ex;
      }

      // projection file
      createProjectionFile(baseFile, coverage
          .getCoordinateReferenceSystem());

    }

    // /////////////////////////////////////////////////////////////////////
    //
    // Encoding of the original coverage
    //
    // ////////////////////////////////////////////////////////////////////
    outStream = ImageIOExt.createImageOutputStream(gc.getRenderedImage(), destination);
    if (outStream == null)
      throw new IOException(
          "WorldImageWriter::write:No image output stream avalaible for the provided destination");
    this.encode(gc, outStream,extension);

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.