use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class IsolineTest method test.
/**
* Test an isoline created arount a central point.
*
* @throws Exception
*/
@Test
public void test() 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, 3), env, GridOrientation.HOMOTHETY));
gcb.setValues(BufferedImages.toDataBuffer1D(new float[][] { { 100, 100, 100 }, { 100, 200, 100 }, { 100, 100, 100 } }), 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[] { 150 });
final org.geotoolkit.process.Process process = desc.createProcess(procparams);
final ParameterValueGroup result = process.call();
final FeatureSet col = (FeatureSet) result.parameter("outFeatureCollection").getValue();
assertEquals(1l, FeatureStoreUtilities.getCount(col, true).longValue());
final Feature feature = col.features(true).findFirst().get();
final LineString geom = (LineString) feature.getPropertyValue(AttributeConvention.GEOMETRY);
assertIsolineEquals("LINESTRING (1 1.5, 1.5 2, 2 1.5, 1.5 1, 1 1.5)", geom);
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class CategorizeTest method test3D.
/**
* Activate back when we'll have a multi-dimensional datasource for testing.
*/
@Ignore
@Test
public void test3D() throws FactoryException, DataStoreException, ProcessException {
final CoordinateReferenceSystem inputCrs = new DefaultCompoundCRS(Collections.singletonMap("name", "toto"), CommonCRS.defaultGeographic(), CommonCRS.Vertical.MEAN_SEA_LEVEL.crs());
final double[][] inputs = { { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 4, 4, 4, 7, 7, 7, 8, 8, 8 } };
final int[][] expectedClassifs = { { 1, 1, 2, 2, 9, 9, 3, 3, 4 }, { 1, 2, 2, 9, 9, 3, 3, 4, 9 }, { 9, 9, 9, 3, 3, 3, 4, 4, 4 } };
WritableGridCoverageResource input = new InMemoryGridCoverageResource();
WritableGridCoverageResource output = new InMemoryGridCoverageResource();
for (int i = 0; i < inputs.length; i++) {
final GeneralEnvelope env = new GeneralEnvelope(inputCrs);
env.setEnvelope(-10, -10, i, 10, 10, i);
final GridCoverageBuilder builder = new GridCoverageBuilder();
builder.setValues(SampleClassifierTest.createGrayScale(3, 3, inputs[i]));
builder.setDomain(env);
final GridCoverage sourceCvg = builder.build();
input.write(sourceCvg, WritableGridCoverageResource.CommonOption.UPDATE);
}
final Categorize process = create(input, output, null);
process.call();
final GeneralEnvelope readEnv = new GeneralEnvelope(inputCrs);
readEnv.setRange(0, -10, 10);
readEnv.setRange(1, -10, 10);
for (int i = 0; i < expectedClassifs.length; i++) {
readEnv.setRange(2, i, i);
final GridCoverage outCvg = output.read(null);
Assert.assertEquals("Output envelope is not conform to source data.", readEnv, outCvg.getGridGeometry().getEnvelope());
final RenderedImage outImage = outCvg.render(null);
final int[] pixels = outImage.getData().getPixels(0, 0, outImage.getWidth(), outImage.getHeight(), (int[]) null);
Assert.assertArrayEquals("Classification result", expectedClassifs[i], pixels);
}
}
use of org.geotoolkit.storage.memory.InMemoryGridCoverageResource in project geotoolkit by Geomatys.
the class CategorizeTest method test2D.
private void test2D(final boolean subset) throws DataStoreException, ProcessException {
final BufferedImage inputImage = SampleClassifierTest.createGrayScale(3, 3, new double[] { 0, 1, 2, 2, 1, 0, 3, 3, 3 });
final int[] expectedClassif;
if (subset) {
expectedClassif = new int[] { 1, 1, 2, 2 };
} else {
expectedClassif = new int[] { 1, 1, 2, 2, 1, 1, 2, 2, 2 };
}
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.defaultGeographic());
env.setEnvelope(-20, -20, 10, 10);
final GridCoverageBuilder builder = new GridCoverageBuilder();
builder.setValues(inputImage);
builder.setDomain(env);
final GridCoverage sourceCvg = builder.build();
WritableGridCoverageResource input = new InMemoryGridCoverageResource(sourceCvg);
WritableGridCoverageResource output = new InMemoryGridCoverageResource(null, null);
final Envelope roi;
final Categorize process;
if (subset) {
final GeneralEnvelope tmpRoi = new GeneralEnvelope(CommonCRS.defaultGeographic());
tmpRoi.setRange(0, -10, 10);
tmpRoi.setRange(1, -20, 0);
roi = tmpRoi;
process = create(input, output, roi);
} else {
roi = sourceCvg.getGridGeometry().getEnvelope();
process = create(input, output, null);
}
process.call();
final GridCoverage outCvg = output.read(null);
final Envelope outEnvelope = outCvg.getGridGeometry().getEnvelope();
Assert.assertEquals("Output envelope is not conform to source data.", GeneralEnvelope.castOrCopy(roi), GeneralEnvelope.castOrCopy(outEnvelope));
final RenderedImage outImage = outCvg.render(null);
final int[] pixels = outImage.getData().getPixels(0, 0, outImage.getWidth(), outImage.getHeight(), (int[]) null);
Assert.assertArrayEquals("Classification result", expectedClassif, pixels);
}
Aggregations