use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class CoverageTileGeneratorTest method fullAreaGenerateTest.
/**
* Test tile generation produces the expected results.
*/
@Test
public void fullAreaGenerateTest() throws DataStoreException, InterruptedException, IOException, TransformException {
final BufferedImage image = new BufferedImage(180, 90, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = image.createGraphics();
g.setColor(Color.RED);
g.fillRect(0, 0, 180, 90);
g.dispose();
final CoordinateReferenceSystem crs = CommonCRS.WGS84.normalizedGeographic();
final GeneralEnvelope dataEnvelope = new GeneralEnvelope(crs);
dataEnvelope.setRange(0, 0, 180);
dataEnvelope.setRange(1, 0, 90);
final GridGeometry gridGeom = new GridGeometry(new GridExtent(180, 90), dataEnvelope, GridOrientation.HOMOTHETY);
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setValues(image);
gcb.setDomain(gridGeom);
final GridCoverage coverage = gcb.build();
final CoverageTileGenerator generator = new CoverageTileGenerator(new InMemoryGridCoverageResource(coverage));
generator.setCoverageIsHomogeneous(false);
final InMemoryTiledGridCoverageResource ipr = new InMemoryTiledGridCoverageResource(Names.createLocalName(null, null, "test"));
final TileMatrixSet tileMatrixSet = (TileMatrixSet) ipr.createTileMatrixSet(TileMatrices.createWorldWGS84Template(4));
generator.generate(tileMatrixSet, null, null, null);
compare(generator, tileMatrixSet, null);
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class ReferenceToGridCoverageResourceConverter method convert.
/**
* {@inheritDoc}
*
* @return GridCoverageResource.
*/
@Override
public GridCoverageResource convert(final Reference source, final Map<String, Object> params) throws UnconvertibleObjectException {
final InputStream stream = getInputStreamFromReference(source);
String encoding = null;
if (params != null && params.get(ENCODING) != null) {
encoding = (String) params.get(ENCODING);
}
ImageInputStream imageStream = null;
try {
// decode form base64 stream
if (encoding != null && encoding.equals(WPSEncoding.BASE64.getValue())) {
final String encodedImage = IOUtilities.toString(stream);
final byte[] byteData = Base64.getDecoder().decode(encodedImage.trim());
if (byteData != null && byteData.length > 0) {
try (InputStream is = new ByteArrayInputStream(byteData)) {
imageStream = ImageIO.createImageInputStream(is);
}
}
} else {
imageStream = ImageIO.createImageInputStream(stream);
}
if (imageStream != null) {
final ImageReader reader;
if (source.getMimeType() != null) {
reader = XImageIO.getReaderByMIMEType(source.getMimeType(), imageStream, null, null);
} else {
reader = XImageIO.getReader(imageStream, null, Boolean.FALSE);
}
ImageCoverageReader imgReader = CoverageIO.createSimpleReader(reader);
GridCoverage cov2d = imgReader.read(new GridCoverageReadParam());
return new InMemoryGridCoverageResource(cov2d);
} else {
throw new UnconvertibleObjectException("Error during image stream acquisition.");
}
} catch (MalformedURLException ex) {
throw new UnconvertibleObjectException("ReferenceType grid coverage invalid input : Malformed url", ex);
} catch (DataStoreException ex) {
throw new UnconvertibleObjectException("ReferenceType grid coverage invalid input : Can't read coverage", ex);
} catch (IOException ex) {
throw new UnconvertibleObjectException("ReferenceType grid coverage invalid input : IO", ex);
} finally {
if (imageStream != null) {
try {
imageStream.close();
} catch (IOException ex) {
LOGGER.log(Level.WARNING, "Error during release the image stream.", ex);
}
}
}
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class IsolineTest method test3.
@Test
public void test3() throws Exception {
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, 0, 3);
env.setRange(1, 0, 3);
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setDomain(new GridGeometry(new GridExtent(3, 4), PixelInCell.CELL_CORNER, new AffineTransform2D(1, 0, 0, -0.75, 0, 3.0), env.getCoordinateReferenceSystem()));
gcb.setValues(BufferedImages.toDataBuffer1D(new float[][] { { 10, 10, 20 }, { 10, 10, 20 }, { 10, 15, 10 }, { 10, 15, 10 } }), null);
gcb.setRanges(new SampleDimension.Builder().setName(0).build());
final GridCoverage coverage = gcb.build();
final GridCoverageResource ref = new InMemoryGridCoverageResource(coverage);
final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor(GeotkProcessingRegistry.NAME, IsolineDescriptor.NAME);
final ParameterValueGroup procparams = desc.getInputDescriptor().createValue();
procparams.parameter("inCoverageRef").setValue(ref);
procparams.parameter("inIntervals").setValue(new double[] { 15 });
final org.geotoolkit.process.Process process = desc.createProcess(procparams);
final ParameterValueGroup result = process.call();
FeatureSet col = (FeatureSet) result.parameter("outFeatureCollection").getValue();
assertEquals(1, FeatureStoreUtilities.getCount(col, true).longValue());
final Feature feature = col.features(false).iterator().next();
final LineString geom = (LineString) feature.getPropertyValue(AttributeConvention.GEOMETRY);
assertIsolineEquals("LINESTRING (2 2.625, 2 1.875, 2.5 1.5)", geom);
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class IsolineTest method test4.
/**
* A single threshold is detected near a no-data border. The algorithm should consider that not enough data is
* available to draw a segment.
*/
@Test
public void test4() throws Exception {
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, 0, 7);
env.setRange(1, 0, 7);
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setDomain(new GridGeometry(new GridExtent(7, 6), PixelInCell.CELL_CORNER, new AffineTransform2D(1, 0, 0, -1.1666666666666667, 0, 7.0), env.getCoordinateReferenceSystem()));
gcb.setValues(BufferedImages.toDataBuffer1D(new float[][] { { Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN }, { Float.NaN, 3.164f, 2.91f, 2.78f, 1.03f, -2.086f, Float.NaN }, { Float.NaN, 3.41f, 5.41f, 4.66f, 4.28f, 0.163f, Float.NaN }, { Float.NaN, 3.78f, 0.41f, -0.83f, -0.83f, 0.663f, Float.NaN }, { Float.NaN, -0.58f, -2.83f, -1.21f, -0.83f, 0.038f, Float.NaN }, { Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN, Float.NaN } }), null);
gcb.setRanges(new SampleDimension.Builder().setName(0).build());
final GridCoverage coverage = gcb.build();
final GridCoverageResource ref = new InMemoryGridCoverageResource(coverage);
double[] intervales = { 3.163 };
final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor(GeotkProcessingRegistry.NAME, IsolineDescriptor.NAME);
final ParameterValueGroup procparams = desc.getInputDescriptor().createValue();
procparams.parameter("inCoverageRef").setValue(ref);
procparams.parameter("inIntervals").setValue(intervales);
final org.geotoolkit.process.Process process = desc.createProcess(procparams);
final ParameterValueGroup result = process.call();
FeatureSet col = (FeatureSet) result.parameter("outFeatureCollection").getValue();
assertEquals(0, FeatureStoreUtilities.getCount(col, true).longValue());
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class IsolineTest method testTiledImage.
/**
* Test isoline creation on a tiled image.
*/
@Test
public void testTiledImage() throws NoSuchIdentifierException, ProcessException, DataStoreException, ParseException {
/* create a tiled image with 4 tiles
0 1 2 3
+-----+-----+
0 | 0 0 | 0 0 |
1 | 0 1 | 1 0 |
+-----+-----+
2 | 0 1 | 1 0 |
3 | 0 0 | 0 0 |
+-----+-----+
Result geometry is an octogone, a square with cutted edges
*/
final BufferedImage tile00 = BufferedImages.createImage(2, 2, 1, DataBuffer.TYPE_DOUBLE);
final BufferedImage tile10 = BufferedImages.createImage(2, 2, 1, DataBuffer.TYPE_DOUBLE);
final BufferedImage tile01 = BufferedImages.createImage(2, 2, 1, DataBuffer.TYPE_DOUBLE);
final BufferedImage tile11 = BufferedImages.createImage(2, 2, 1, DataBuffer.TYPE_DOUBLE);
final WritableRaster raster00 = tile00.getRaster();
final WritableRaster raster10 = tile10.getRaster().createWritableTranslatedChild(2, 0);
final WritableRaster raster01 = tile01.getRaster().createWritableTranslatedChild(0, 2);
final WritableRaster raster11 = tile11.getRaster().createWritableTranslatedChild(2, 2);
raster00.setSample(1 + 0, 1 + 0, 0, 1);
raster10.setSample(0 + 2, 1 + 0, 0, 1);
raster01.setSample(1 + 0, 0 + 2, 0, 1);
raster11.setSample(0 + 2, 0 + 2, 0, 1);
final WritableTiledImage img = new WritableTiledImage(null, tile00.getColorModel(), 4, 4, 0, 0, new WritableRaster[] { raster00, raster10, raster01, raster11 });
final MathTransform gridtoCrs = new AffineTransform2D(1, 0, 0, 1, 0, 0);
final GridCoverageBuilder gcb = new GridCoverageBuilder();
gcb.setDomain(new GridGeometry(new GridExtent(4, 4), PixelInCell.CELL_CENTER, gridtoCrs, CommonCRS.WGS84.normalizedGeographic()));
gcb.setValues(img);
gcb.setRanges(new SampleDimension.Builder().setName(0).build());
final GridCoverage coverage = gcb.build();
final GridCoverageResource ref = new InMemoryGridCoverageResource(coverage);
final ProcessDescriptor desc = ProcessFinder.getProcessDescriptor(GeotkProcessingRegistry.NAME, IsolineDescriptor.NAME);
final ParameterValueGroup procparams = desc.getInputDescriptor().createValue();
procparams.parameter("inCoverageRef").setValue(ref);
procparams.parameter("inIntervals").setValue(new double[] { 0.5 });
final org.geotoolkit.process.Process process = desc.createProcess(procparams);
final ParameterValueGroup result = process.call();
final FeatureSet col = (FeatureSet) result.parameter("outFeatureCollection").getValue();
final List<Feature> features = col.features(false).collect(Collectors.toList());
assertEquals(1L, features.size());
final LineString geom = (LineString) features.get(0).getPropertyValue(AttributeConvention.GEOMETRY);
assertIsolineEquals("LINESTRING (1 0.5, 2 0.5, 2.5 1, 2.5 2, 2 2.5, 1 2.5, 0.5 2, 0.5 1, 1 0.5)", geom);
}
Aggregations