Search in sources :

Example 1 with Parameter

use of org.geotools.parameter.Parameter in project hortonmachine by TheHortonMachine.

the class CoverageUtilities method createGridGeometryGeneralParameter.

/**
 * Utility method to create read parameters for {@link GridCoverageReader}
 *
 * @param width the needed number of columns.
 * @param height the needed number of columns.
 * @param north the northern boundary.
 * @param south the southern boundary.
 * @param east the eastern boundary.
 * @param west the western boundary.
 * @param crs the {@link CoordinateReferenceSystem}. Can be null, even if it should not.
 * @return the {@link GeneralParameterValue array of parameters}.
 */
public static GeneralParameterValue[] createGridGeometryGeneralParameter(int width, int height, double north, double south, double east, double west, CoordinateReferenceSystem crs) {
    GeneralParameterValue[] readParams = new GeneralParameterValue[1];
    Parameter<GridGeometry2D> readGG = new Parameter<GridGeometry2D>(AbstractGridFormat.READ_GRIDGEOMETRY2D);
    GridEnvelope2D gridEnvelope = new GridEnvelope2D(0, 0, width, height);
    Envelope env;
    if (crs != null) {
        env = new ReferencedEnvelope(west, east, south, north, crs);
    } else {
        DirectPosition2D minDp = new DirectPosition2D(west, south);
        DirectPosition2D maxDp = new DirectPosition2D(east, north);
        env = new Envelope2D(minDp, maxDp);
    }
    GridGeometry2D gridGeometry = new GridGeometry2D(gridEnvelope, env);
    readGG.setValue(gridGeometry);
    readParams[0] = readGG;
    return readParams;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D) Parameter(org.geotools.parameter.Parameter) Envelope(org.opengis.geometry.Envelope) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) DirectPosition2D(org.geotools.geometry.DirectPosition2D) Envelope2D(org.geotools.geometry.Envelope2D) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D)

Example 2 with Parameter

use of org.geotools.parameter.Parameter in project hortonmachine by TheHortonMachine.

the class CoverageUtilities method createGridGeometryGeneralParameter.

/**
 * Utility method to create read parameters for {@link GridCoverageReader}
 *
 * @param regionMap the RegionMap.
 * @param crs the {@link CoordinateReferenceSystem}. Can be null, even if it should not.
 * @return the {@link GeneralParameterValue array of parameters}.
 */
public static GeneralParameterValue[] createGridGeometryGeneralParameter(RegionMap regionMap, CoordinateReferenceSystem crs) {
    GeneralParameterValue[] readParams = new GeneralParameterValue[1];
    Parameter<GridGeometry2D> readGG = new Parameter<GridGeometry2D>(AbstractGridFormat.READ_GRIDGEOMETRY2D);
    GridEnvelope2D gridEnvelope = new GridEnvelope2D(0, 0, regionMap.getCols(), regionMap.getRows());
    Envelope env;
    double north = regionMap.getNorth();
    double south = regionMap.getSouth();
    double east = regionMap.getEast();
    double west = regionMap.getWest();
    if (crs != null) {
        env = new ReferencedEnvelope(west, east, south, north, crs);
    } else {
        DirectPosition2D minDp = new DirectPosition2D(west, south);
        DirectPosition2D maxDp = new DirectPosition2D(east, north);
        env = new Envelope2D(minDp, maxDp);
    }
    readGG.setValue(new GridGeometry2D(gridEnvelope, env));
    readParams[0] = readGG;
    return readParams;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D) Parameter(org.geotools.parameter.Parameter) Envelope(org.opengis.geometry.Envelope) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) DirectPosition2D(org.geotools.geometry.DirectPosition2D) Envelope2D(org.geotools.geometry.Envelope2D) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D)

Example 3 with Parameter

use of org.geotools.parameter.Parameter in project geowave by locationtech.

the class GeoWaveRasterReader method read.

/*
   * (non-Javadoc)
   *
   * @see org.opengis.coverage.grid.GridCoverageReader#read(org.opengis.parameter
   * .GeneralParameterValue [])
   */
@Override
public GridCoverage2D read(final String coverageName, final GeneralParameterValue[] params) throws IOException {
    if (!checkName(coverageName)) {
        LOGGER.warn("Unable to find data adapter for '" + coverageName + "'");
        return null;
    }
    final Date start = new Date();
    // /////////////////////////////////////////////////////////////////////
    // 
    // Checking params
    // 
    // /////////////////////////////////////////////////////////////////////
    Color outputTransparentColor = null;
    Color backgroundColor = null;
    Interpolation interpolation = null;
    Rectangle dim = null;
    GeneralEnvelope requestedEnvelope = null;
    if (params != null) {
        for (final GeneralParameterValue generalParameterValue : params) {
            final Parameter<Object> param = (Parameter<Object>) generalParameterValue;
            if (param.getDescriptor().getName().getCode().equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName().toString())) {
                final GridGeometry2D gg = (GridGeometry2D) param.getValue();
                requestedEnvelope = (GeneralEnvelope) gg.getEnvelope();
                dim = gg.getGridRange2D().getBounds();
            } else if (param.getDescriptor().getName().getCode().equals(GeoWaveGTRasterFormat.OUTPUT_TRANSPARENT_COLOR.getName().toString())) {
                outputTransparentColor = (Color) param.getValue();
            } else if (param.getDescriptor().getName().getCode().equals(AbstractGridFormat.BACKGROUND_COLOR.getName().toString())) {
                backgroundColor = (Color) param.getValue();
            } else if (param.getDescriptor().getName().getCode().equals(AbstractGridFormat.INTERPOLATION.getName().toString())) {
                interpolation = (Interpolation) param.getValue();
            }
        }
    }
    final GridCoverage2D coverage = renderGridCoverage(coverageName, dim, requestedEnvelope, backgroundColor, outputTransparentColor, interpolation);
    LOGGER.info("GeoWave Raster Reader needs : " + ((new Date()).getTime() - start.getTime()) + " millisecs");
    return coverage;
}
Also used : Interpolation(javax.media.jai.Interpolation) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) Color(java.awt.Color) Rectangle(java.awt.Rectangle) Parameter(org.geotools.parameter.Parameter) GeneralEnvelope(org.geotools.geometry.GeneralEnvelope) Date(java.util.Date)

Example 4 with Parameter

use of org.geotools.parameter.Parameter in project hortonmachine by TheHortonMachine.

the class ImageUtilities method imageFromReader.

/**
 * Read an image from a coverage reader.
 *
 * @param reader the reader.
 * @param cols the expected cols.
 * @param rows the expected rows.
 * @param w west bound.
 * @param e east  bound.
 * @param s south bound.
 * @param n north bound.
 * @return the image or <code>null</code> if unable to read it.
 * @throws IOException
 */
public static BufferedImage imageFromReader(AbstractGridCoverage2DReader reader, int cols, int rows, double w, double e, double s, double n, CoordinateReferenceSystem resampleCrs) throws IOException {
    CoordinateReferenceSystem sourceCrs = reader.getCoordinateReferenceSystem();
    GeneralParameterValue[] readParams = new GeneralParameterValue[1];
    Parameter<GridGeometry2D> readGG = new Parameter<GridGeometry2D>(AbstractGridFormat.READ_GRIDGEOMETRY2D);
    GridEnvelope2D gridEnvelope = new GridEnvelope2D(0, 0, cols, rows);
    DirectPosition2D minDp = new DirectPosition2D(sourceCrs, w, s);
    DirectPosition2D maxDp = new DirectPosition2D(sourceCrs, e, n);
    Envelope env = new Envelope2D(minDp, maxDp);
    readGG.setValue(new GridGeometry2D(gridEnvelope, env));
    readParams[0] = readGG;
    GridCoverage2D gridCoverage2D = reader.read(readParams);
    if (gridCoverage2D == null) {
        return null;
    }
    if (resampleCrs != null) {
        gridCoverage2D = (GridCoverage2D) Operations.DEFAULT.resample(gridCoverage2D, resampleCrs);
    }
    RenderedImage image = gridCoverage2D.getRenderedImage();
    return rendereImage2BufferedImage(image);
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GridGeometry2D(org.geotools.coverage.grid.GridGeometry2D) GridCoverage2D(org.geotools.coverage.grid.GridCoverage2D) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D) Parameter(org.geotools.parameter.Parameter) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Envelope(org.opengis.geometry.Envelope) RenderedImage(java.awt.image.RenderedImage) DirectPosition2D(org.geotools.geometry.DirectPosition2D) Envelope2D(org.geotools.geometry.Envelope2D) GridEnvelope2D(org.geotools.coverage.grid.GridEnvelope2D)

Example 5 with Parameter

use of org.geotools.parameter.Parameter in project georchestra by georchestra.

the class WcsReaderRequestTest method testGetParameters.

@Test
public void testGetParameters() throws Exception {
    WcsReaderRequest rq = createRequest();
    GeneralParameterValue[] params = rq.getParameters();
    for (int i = 0; i < params.length; i++) {
        GeneralParameterValue param = params[i];
        String name = param.getDescriptor().getName().getCode();
        if (name.equals(REMOTE_REPROJECT.getName().getCode())) {
            Parameter<?> p = (Parameter<?>) param;
            assertEquals(p.getValue(), rq.remoteReproject);
        } else if (name.equals(USE_COMMANDLINE_GDAL.getName().getCode())) {
            Parameter<?> p = (Parameter<?>) param;
            assertEquals(p.getValue(), rq.useCommandLineGDAL);
        } else if (name.equals(VERSION.getName().getCode())) {
            Parameter<?> p = (Parameter<?>) param;
            assertEquals(p.getValue(), rq.version);
            assertEquals(WcsReaderRequest.getValue(param, String.class), rq.version);
        } else if (name.equals(COVERAGE.getName().getCode())) {
            Parameter<?> p = (Parameter<?>) param;
            assertEquals(p.getValue(), rq.coverage);
        } else if (name.equals(COVERAGE.getName().getCode())) {
            Parameter<?> p = (Parameter<?>) param;
            assertEquals(p.getValue(), rq.coverage);
        } else if (name.equals(FORMAT.getName().getCode())) {
            Parameter<?> p = (Parameter<?>) param;
            assertEquals(p.getValue(), rq.format);
        } else if (name.equals(RES.getName().getCode())) {
            ParameterValueGroup g = (ParameterValueGroup) param;
            assertEquals(g.parameter(RESX.getName().getCode()), rq.groundResolutionX);
            assertEquals(g.parameter(RESY.getName().getCode()), rq.groundResolutionX);
        } else if (name.equals(BBOX.getName().getCode())) {
            ParameterValueGroup g = (ParameterValueGroup) param;
            assertEquals(g.parameter(MINX.getName().getCode()), rq.requestBbox.getMinX());
            assertEquals(g.parameter(MINY.getName().getCode()), rq.requestBbox.getMinY());
            assertEquals(g.parameter(MAXX.getName().getCode()), rq.requestBbox.getMaxX());
            assertEquals(g.parameter(MAXY.getName().getCode()), rq.requestBbox.getMaxY());
        }
    }
    assertTrue(true);
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) Parameter(org.geotools.parameter.Parameter) Test(org.junit.Test)

Aggregations

Parameter (org.geotools.parameter.Parameter)5 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)5 GridGeometry2D (org.geotools.coverage.grid.GridGeometry2D)4 GridEnvelope2D (org.geotools.coverage.grid.GridEnvelope2D)3 DirectPosition2D (org.geotools.geometry.DirectPosition2D)3 Envelope2D (org.geotools.geometry.Envelope2D)3 Envelope (org.opengis.geometry.Envelope)3 GridCoverage2D (org.geotools.coverage.grid.GridCoverage2D)2 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)2 Color (java.awt.Color)1 Rectangle (java.awt.Rectangle)1 RenderedImage (java.awt.image.RenderedImage)1 Date (java.util.Date)1 Interpolation (javax.media.jai.Interpolation)1 GeneralEnvelope (org.geotools.geometry.GeneralEnvelope)1 Test (org.junit.Test)1 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)1 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)1