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;
}
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;
}
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();
}
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.");
}
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());
}
}
}
Aggregations