Search in sources :

Example 6 with GeneralParameterValue

use of org.opengis.parameter.GeneralParameterValue in project sis by apache.

the class ParameterValueList method get.

/**
 * Returns the parameter value at the given index. If the parameter at the given index is a
 * mandatory parameter pending creation of the actual value, the value will be created now.
 */
@Override
public GeneralParameterValue get(int index) {
    ArgumentChecks.ensureValidIndex(size, index);
    GeneralParameterValue value = values[index];
    if (value instanceof UninitializedParameter) {
        values[index] = value = value.getDescriptor().createValue();
    }
    return value;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue)

Example 7 with GeneralParameterValue

use of org.opengis.parameter.GeneralParameterValue in project sis by apache.

the class TensorParameters method toMatrix.

/**
 * Constructs a matrix from a group of parameters.
 * This operation is allowed only for tensors of {@linkplain #rank() rank} 2.
 *
 * @param  parameters  the group of parameters.
 * @return a matrix constructed from the specified group of parameters.
 * @throws InvalidParameterNameException if a parameter name was not recognized.
 *
 * @see #createValueGroup(Map, Matrix)
 */
public Matrix toMatrix(final ParameterValueGroup parameters) throws InvalidParameterNameException {
    if (rank() != 2) {
        throw new IllegalStateException();
    }
    ArgumentChecks.ensureNonNull("parameters", parameters);
    if (parameters instanceof TensorValues) {
        // More efficient implementation
        return ((TensorValues) parameters).toMatrix();
    }
    // Fallback on the general case (others implementations)
    final ParameterValue<?> numRow = parameters.parameter(dimensions[0].getName().getCode());
    final ParameterValue<?> numCol = parameters.parameter(dimensions[1].getName().getCode());
    final Matrix matrix = Matrices.createDiagonal(numRow.intValue(), numCol.intValue());
    final List<GeneralParameterValue> values = parameters.values();
    if (values != null) {
        for (final GeneralParameterValue param : values) {
            if (param == numRow || param == numCol) {
                continue;
            }
            final String name = param.getDescriptor().getName().getCode();
            IllegalArgumentException cause = null;
            int[] indices = null;
            try {
                indices = nameToIndices(name);
            } catch (IllegalArgumentException e) {
                cause = e;
            }
            if (indices == null) {
                throw (InvalidParameterNameException) new InvalidParameterNameException(Errors.format(Errors.Keys.UnexpectedParameter_1, name), name).initCause(cause);
            }
            matrix.setElement(indices[0], indices[1], ((ParameterValue<?>) param).doubleValue());
        }
    }
    return matrix;
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) Matrix(org.opengis.referencing.operation.Matrix) InvalidParameterNameException(org.opengis.parameter.InvalidParameterNameException)

Example 8 with GeneralParameterValue

use of org.opengis.parameter.GeneralParameterValue in project OpenTripPlanner by opentripplanner.

the class Renderer method generateStreamingGeotiffResponse.

private static Response generateStreamingGeotiffResponse(final GridCoverage2D coverage) {
    StreamingOutput streamingOutput = new StreamingOutput() {

        public void write(OutputStream outStream) {
            try {
                long t0 = System.currentTimeMillis();
                GeoTiffWriteParams wp = new GeoTiffWriteParams();
                wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
                wp.setCompressionType("LZW");
                ParameterValueGroup params = new GeoTiffFormat().getWriteParameters();
                params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);
                new GeoTiffWriter(outStream).write(coverage, (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1]));
                // new GeoTiffWriter(outStream).write(coverage, null); //wasn't this line writing twice and trashing compressed version?
                long t1 = System.currentTimeMillis();
                LOG.debug("wrote geotiff in {}msec", t1 - t0);
            } catch (Exception e) {
                LOG.error("exception while preparing geotiff : {}", e.getMessage());
                throw new WebApplicationException(e);
            }
        }
    };
    CacheControl cc = new CacheControl();
    cc.setMaxAge(3600);
    cc.setNoCache(false);
    return Response.ok(streamingOutput).type("image/geotiff").cacheControl(cc).build();
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GeoTiffFormat(org.geotools.gce.geotiff.GeoTiffFormat) WebApplicationException(javax.ws.rs.WebApplicationException) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) OutputStream(java.io.OutputStream) GeoTiffWriteParams(org.geotools.gce.geotiff.GeoTiffWriteParams) StreamingOutput(javax.ws.rs.core.StreamingOutput) GeoTiffWriter(org.geotools.gce.geotiff.GeoTiffWriter) CacheControl(javax.ws.rs.core.CacheControl) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 9 with GeneralParameterValue

use of org.opengis.parameter.GeneralParameterValue in project OpenTripPlanner by opentripplanner.

the class RasterPopulation method writeGeotiff.

public void writeGeotiff(String fileName, ResultSet results) {
    LOG.info("writing geotiff.");
    float[][] imagePixelData = new float[rows][cols];
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            int index = row * cols + col;
            float pixel = (float) (results.results[index]);
            if (unitySeconds > 0)
                pixel /= unitySeconds;
            imagePixelData[row][col] = pixel;
        }
    }
    GridCoverage2D coverage = new GridCoverageFactory().create("OTPAnalyst", imagePixelData, refEnvelope);
    try {
        GeoTiffWriteParams wp = new GeoTiffWriteParams();
        wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
        wp.setCompressionType("LZW");
        ParameterValueGroup params = new GeoTiffFormat().getWriteParameters();
        params.parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString()).setValue(wp);
        GeoTiffWriter writer = new GeoTiffWriter(new File(fileName));
        writer.write(coverage, (GeneralParameterValue[]) params.values().toArray(new GeneralParameterValue[1]));
    } catch (Exception e) {
        LOG.error("exception while writing geotiff.", e);
    }
    LOG.info("done writing geotiff.");
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) GeoTiffFormat(org.geotools.gce.geotiff.GeoTiffFormat) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) GeoTiffWriteParams(org.geotools.gce.geotiff.GeoTiffWriteParams) GeoTiffWriter(org.geotools.gce.geotiff.GeoTiffWriter) File(java.io.File)

Example 10 with GeneralParameterValue

use of org.opengis.parameter.GeneralParameterValue in project sis by apache.

the class ReferencingAssert method assertParameterEquals.

/**
 * Asserts that the given parameter values are equal to the expected ones within
 * a positive delta. Only the elements in the given descriptor are compared, and
 * the comparisons are done in the units declared in the descriptor.
 *
 * @param expected   the expected parameter values.
 * @param actual     the actual parameter values.
 * @param tolerance  the tolerance threshold for comparison of numerical values.
 */
public static void assertParameterEquals(final ParameterValueGroup expected, final ParameterValueGroup actual, final double tolerance) {
    for (final GeneralParameterValue candidate : expected.values()) {
        if (!(candidate instanceof ParameterValue<?>)) {
            throw new UnsupportedOperationException("Not yet implemented.");
        }
        final ParameterValue<?> value = (ParameterValue<?>) candidate;
        final ParameterDescriptor<?> descriptor = value.getDescriptor();
        final String name = descriptor.getName().getCode();
        final Unit<?> unit = descriptor.getUnit();
        final Class<?> valueClass = descriptor.getValueClass();
        final ParameterValue<?> e = expected.parameter(name);
        final ParameterValue<?> a = actual.parameter(name);
        if (unit != null) {
            final double f = e.doubleValue(unit);
            assertEquals(name, f, a.doubleValue(unit), tolerance);
        } else if (valueClass == Float.class || valueClass == Double.class) {
            final double f = e.doubleValue();
            assertEquals(name, f, a.doubleValue(), tolerance);
        } else {
            assertEquals(name, e.getValue(), a.getValue());
        }
    }
}
Also used : GeneralParameterValue(org.opengis.parameter.GeneralParameterValue) ParameterValue(org.opengis.parameter.ParameterValue) GeneralParameterValue(org.opengis.parameter.GeneralParameterValue)

Aggregations

GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)21 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)11 ParameterValue (org.opengis.parameter.ParameterValue)7 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)5 IdentifiedObject (org.opengis.referencing.IdentifiedObject)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)3 Test (org.junit.Test)3 InternationalString (org.opengis.util.InternationalString)3 ArrayList (java.util.ArrayList)2 FormattableObject (org.apache.sis.io.wkt.FormattableObject)2 Formatter (org.apache.sis.io.wkt.Formatter)2 DefaultParameterValue (org.apache.sis.parameter.DefaultParameterValue)2 UnavailableFactoryException (org.apache.sis.referencing.factory.UnavailableFactoryException)2 GeoTiffFormat (org.geotools.gce.geotiff.GeoTiffFormat)2 GeoTiffWriteParams (org.geotools.gce.geotiff.GeoTiffWriteParams)2 GeoTiffWriter (org.geotools.gce.geotiff.GeoTiffWriter)2 Identifier (org.opengis.metadata.Identifier)2 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)2 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)2 OperationMethod (org.opengis.referencing.operation.OperationMethod)2