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