Search in sources :

Example 36 with InMemoryGridCoverageResource

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);
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) GridExtent(org.apache.sis.coverage.grid.GridExtent) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) SampleDimension(org.apache.sis.coverage.SampleDimension) Feature(org.opengis.feature.Feature) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) LineString(org.locationtech.jts.geom.LineString) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor) FeatureSet(org.apache.sis.storage.FeatureSet) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) Test(org.junit.Test)

Example 37 with InMemoryGridCoverageResource

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);
    }
}
Also used : DefaultCompoundCRS(org.apache.sis.referencing.crs.DefaultCompoundCRS) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) WritableGridCoverageResource(org.apache.sis.storage.WritableGridCoverageResource) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) RenderedImage(java.awt.image.RenderedImage) Ignore(org.junit.Ignore) Test(org.junit.Test) SampleClassifierTest(org.geotoolkit.processing.image.sampleclassifier.SampleClassifierTest)

Example 38 with InMemoryGridCoverageResource

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);
}
Also used : GridCoverage(org.apache.sis.coverage.grid.GridCoverage) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageBuilder(org.apache.sis.coverage.grid.GridCoverageBuilder) WritableGridCoverageResource(org.apache.sis.storage.WritableGridCoverageResource) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) Envelope(org.opengis.geometry.Envelope) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) RenderedImage(java.awt.image.RenderedImage) BufferedImage(java.awt.image.BufferedImage)

Aggregations

InMemoryGridCoverageResource (org.geotoolkit.storage.memory.InMemoryGridCoverageResource)38 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)34 Test (org.junit.Test)33 GridExtent (org.apache.sis.coverage.grid.GridExtent)32 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)32 SampleDimension (org.apache.sis.coverage.SampleDimension)28 AffineTransform2D (org.apache.sis.internal.referencing.j2d.AffineTransform2D)27 GridCoverageBuilder (org.apache.sis.coverage.grid.GridCoverageBuilder)26 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)25 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)22 RenderedImage (java.awt.image.RenderedImage)18 BufferedGridCoverage (org.apache.sis.coverage.grid.BufferedGridCoverage)17 WritableRenderedImage (java.awt.image.WritableRenderedImage)16 PixelIterator (org.apache.sis.image.PixelIterator)15 WritablePixelIterator (org.apache.sis.image.WritablePixelIterator)15 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)14 BufferedImage (java.awt.image.BufferedImage)13 Graphics2D (java.awt.Graphics2D)6 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)6 FeatureSet (org.apache.sis.storage.FeatureSet)6