Search in sources :

Example 1 with DefiningCoverageResource

use of org.geotoolkit.storage.coverage.DefiningCoverageResource in project geotoolkit by Geomatys.

the class PGPyramidTest method testSampleDimensions.

@Test
public void testSampleDimensions() throws DataStoreException, VersioningException, IOException, TransformException {
    reload();
    final GeneralDirectPosition upperLeft = new GeneralDirectPosition(CommonCRS.WGS84.geographic());
    final Dimension dimension = new Dimension(20, 20);
    upperLeft.setOrdinate(0, -90);
    upperLeft.setOrdinate(1, +180);
    PyramidalCoverageResource cref;
    Pyramid pyramid;
    Mosaic mosaic;
    BufferedImage image;
    final GenericName name = NamesExt.create(null, "sampleTestLayer");
    store.add(new DefiningCoverageResource(name));
    // create version 1 -----------------------------------------------------
    cref = (PyramidalCoverageResource) store.findResource(name.toString());
    assertNotNull(cref);
    // test create pyramid
    pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
    assertEquals(1, cref.getModels().size());
    final List<SampleDimension> dimensions = new LinkedList<>();
    // dim 1
    SampleDimension.Builder b = new SampleDimension.Builder();
    b.addQuantitative("data", NumberRange.create(1, true, 100, true), MeasurementRange.create(-50.0, true, 45.6, true, Units.CELSIUS));
    b.addQualitative(Vocabulary.formatInternational(Vocabulary.Keys.Nodata), Double.NaN);
    final SampleDimension dim1 = b.setName("dim0").build();
    dimensions.add(0, dim1);
    // dim 2
    b.clear();
    b.addQuantitative("data", 1, 55, 2.0, 0.0, Units.METRE);
    b.addQualitative(null, 0);
    final SampleDimension dim2 = b.setName("dim1").build();
    dimensions.add(1, dim2);
    // test create SampleDimensions
    cref.setSampleDimensions(dimensions);
    List<SampleDimension> resultSamples = cref.getSampleDimensions();
    assertNotNull(resultSamples);
    assertEquals(2, resultSamples.size());
    SampleDimension resultDim1 = resultSamples.get(0);
    SampleDimension resultDim2 = resultSamples.get(1);
    assertNotNull(resultDim1);
    assertNotNull(resultDim2);
    assertEquals("dim0", resultDim1.getName().toString());
    assertEquals("dim1", resultDim2.getName().toString());
    assertEquals(Units.CELSIUS, resultDim1.getUnits());
    assertEquals(Units.METRE, resultDim2.getUnits());
    List<Category> resultCat1 = resultDim1.getCategories();
    List<Category> resultCat2 = resultDim2.getCategories();
    assertEquals(2, resultCat1.size());
    assertEquals(2, resultCat2.size());
// assertCategoryEquals(dataCat, resultCat1);
// assertCategoryEquals(nodataCat, resultCat1);
// assertCategoryEquals(dataCat2, resultCat2);
// assertCategoryEquals(nodataCat2, resultCat2);
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) Category(org.apache.sis.coverage.Category) DefiningCoverageResource(org.geotoolkit.storage.coverage.DefiningCoverageResource) SampleDimension(org.apache.sis.coverage.SampleDimension) Dimension(java.awt.Dimension) SampleDimension(org.apache.sis.coverage.SampleDimension) BufferedImage(java.awt.image.BufferedImage) Pyramid(org.geotoolkit.data.multires.Pyramid) DefiningPyramid(org.geotoolkit.data.multires.DefiningPyramid) GenericName(org.opengis.util.GenericName) PyramidalCoverageResource(org.geotoolkit.storage.coverage.PyramidalCoverageResource) DefiningPyramid(org.geotoolkit.data.multires.DefiningPyramid) DefiningMosaic(org.geotoolkit.data.multires.DefiningMosaic) Mosaic(org.geotoolkit.data.multires.Mosaic) Test(org.junit.Test)

Example 2 with DefiningCoverageResource

use of org.geotoolkit.storage.coverage.DefiningCoverageResource in project geotoolkit by Geomatys.

the class PGPyramidTest method testInsertUpdateDelete.

@Test
public void testInsertUpdateDelete() throws DataStoreException, VersioningException, IOException {
    reload();
    final GeneralDirectPosition upperLeft = new GeneralDirectPosition(CommonCRS.WGS84.geographic());
    final Dimension dimension = new Dimension(20, 20);
    upperLeft.setOrdinate(0, -90);
    upperLeft.setOrdinate(1, +180);
    PyramidalCoverageResource cref;
    Pyramid pyramid;
    Mosaic mosaic;
    RenderedImage image;
    final GenericName name = NamesExt.create(null, "versLayer");
    store.add(new DefiningCoverageResource(name));
    // create version 1 -----------------------------------------------------
    cref = (PyramidalCoverageResource) store.findResource(name.toString());
    assertNotNull(cref);
    // test create pyramid
    pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
    assertEquals(1, cref.getModels().size());
    // test create mosaic
    mosaic = pyramid.createMosaic(new DefiningMosaic(null, upperLeft, 1, dimension, new Dimension(1, 4)));
    pyramid = Pyramids.getPyramid(cref, pyramid.getIdentifier());
    assertEquals(1, pyramid.getMosaics().size());
    // test insert tile
    mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.RED), new Point(0, 0)), new DefaultImageTile(createImage(dimension, Color.GREEN), new Point(0, 1)), new DefaultImageTile(createImage(dimension, Color.BLUE), new Point(0, 2)), new DefaultImageTile(createImage(dimension, Color.YELLOW), new Point(0, 3))), null);
    image = ((ImageTile) mosaic.getTile(0, 0)).getImage();
    assertImageColor(image, Color.RED);
    image = ((ImageTile) mosaic.getTile(0, 1)).getImage();
    assertImageColor(image, Color.GREEN);
    image = ((ImageTile) mosaic.getTile(0, 2)).getImage();
    assertImageColor(image, Color.BLUE);
    image = ((ImageTile) mosaic.getTile(0, 3)).getImage();
    assertImageColor(image, Color.YELLOW);
    // test delete tile
    mosaic.deleteTile(0, 1);
    assertNotNull(((ImageTile) mosaic.getTile(0, 2)).getInput());
    mosaic.deleteTile(0, 2);
    assertNull(((ImageTile) mosaic.getTile(0, 2)).getInput());
    // test update tile
    mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.PINK), new Point(0, 3))), null);
    image = ((ImageTile) mosaic.getTile(0, 3)).getImageReader().read(3);
    assertImageColor(image, Color.PINK);
    // test delete mosaic
    pyramid.deleteMosaic(mosaic.getIdentifier());
    pyramid = Pyramids.getPyramid(cref, pyramid.getIdentifier());
    assertTrue(pyramid.getMosaics().isEmpty());
    // test delete pyramid
    cref.removeModel(pyramid.getIdentifier());
    assertTrue(cref.getModels().isEmpty());
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) DefiningCoverageResource(org.geotoolkit.storage.coverage.DefiningCoverageResource) DefiningMosaic(org.geotoolkit.data.multires.DefiningMosaic) DefaultImageTile(org.geotoolkit.storage.coverage.DefaultImageTile) SampleDimension(org.apache.sis.coverage.SampleDimension) Dimension(java.awt.Dimension) Point(java.awt.Point) Pyramid(org.geotoolkit.data.multires.Pyramid) DefiningPyramid(org.geotoolkit.data.multires.DefiningPyramid) GenericName(org.opengis.util.GenericName) DefaultImageTile(org.geotoolkit.storage.coverage.DefaultImageTile) ImageTile(org.geotoolkit.storage.coverage.ImageTile) PyramidalCoverageResource(org.geotoolkit.storage.coverage.PyramidalCoverageResource) DefiningPyramid(org.geotoolkit.data.multires.DefiningPyramid) RenderedImage(java.awt.image.RenderedImage) DefiningMosaic(org.geotoolkit.data.multires.DefiningMosaic) Mosaic(org.geotoolkit.data.multires.Mosaic) Test(org.junit.Test)

Example 3 with DefiningCoverageResource

use of org.geotoolkit.storage.coverage.DefiningCoverageResource in project geotoolkit by Geomatys.

the class PGCVersioningTest method testVersioning.

@Test
public void testVersioning() throws DataStoreException, VersioningException {
    reload();
    final GeneralDirectPosition upperLeft = new GeneralDirectPosition(CommonCRS.WGS84.geographic());
    final Dimension dimension = new Dimension(20, 20);
    final Calendar calendar = Calendar.getInstance(GMT0);
    upperLeft.setOrdinate(0, -90);
    upperLeft.setOrdinate(1, +180);
    List<Version> versions;
    Version version;
    PyramidalCoverageResource cref;
    Pyramid pyramid;
    Mosaic mosaic;
    GridCoverage coverage;
    final GenericName name = NamesExt.create(null, "versLayer");
    store.add(new DefiningCoverageResource(name));
    final VersionControl vc = store.getVersioning(name);
    versions = vc.list();
    assertTrue(versions.isEmpty());
    // create version 1 -----------------------------------------------------
    calendar.setTimeInMillis(0);
    final Date date1 = calendar.getTime();
    version = vc.createVersion(date1);
    cref = (PyramidalCoverageResource) store.findResource(name, version);
    assertNotNull(cref);
    // we need to create a pyramid otherwise the version not really be created
    pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
    mosaic = pyramid.createMosaic(new DefiningMosaic(null, upperLeft, 1, dimension, new Dimension(1, 1)));
    mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.RED), new Point(0, 0))), null);
    versions = vc.list();
    assertEquals(1, versions.size());
    assertEquals(versions.get(0).getDate().getTime(), 0);
    assertEquals(date1.getTime(), versions.get(0).getDate().getTime());
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.RED);
    // create version 2 -----------------------------------------------------
    calendar.setTimeInMillis(50000);
    final Date date2 = calendar.getTime();
    version = vc.createVersion(date2);
    cref = (PyramidalCoverageResource) store.findResource(name, version);
    assertNotNull(cref);
    // we need to create a pyramid otherwise the version not really be created
    pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
    mosaic = pyramid.createMosaic(new DefiningMosaic(null, upperLeft, 1, dimension, new Dimension(1, 1)));
    mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.BLUE), new Point(0, 0))), null);
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.BLUE);
    versions = vc.list();
    assertEquals(2, versions.size());
    assertEquals(versions.get(0).getDate().getTime(), 0);
    assertEquals(versions.get(1).getDate().getTime(), 50000);
    // create version 3 -----------------------------------------------------
    calendar.setTimeInMillis(20000);
    final Date date3 = calendar.getTime();
    version = vc.createVersion(date3);
    cref = (PyramidalCoverageResource) store.findResource(name, version);
    assertNotNull(cref);
    // we need to create a pyramid otherwise the version not really be created
    pyramid = (Pyramid) cref.createModel(new DefiningPyramid(CommonCRS.WGS84.geographic()));
    mosaic = pyramid.createMosaic(new DefiningMosaic(null, upperLeft, 1, dimension, new Dimension(1, 1)));
    mosaic.writeTiles(Stream.of(new DefaultImageTile(createImage(dimension, Color.BLUE), new Point(0, 0))), null);
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.GREEN);
    versions = vc.list();
    assertEquals(3, versions.size());
    assertEquals(versions.get(0).getDate().getTime(), 0);
    assertEquals(versions.get(1).getDate().getTime(), 20000);
    assertEquals(versions.get(2).getDate().getTime(), 50000);
    // try accesing different version ---------------------------------------
    cref = (PyramidalCoverageResource) store.findResource(name.toString());
    // we should have the blue image
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.BLUE);
    // grab by version
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(0));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.RED);
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(1));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.GREEN);
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(2));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.BLUE);
    // drop some versions ---------------------------------------------------
    vc.dropVersion(versions.get(1));
    versions = vc.list();
    assertEquals(2, versions.size());
    assertEquals(versions.get(0).getDate().getTime(), 0);
    assertEquals(versions.get(1).getDate().getTime(), 50000);
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(0));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.RED);
    cref = (PyramidalCoverageResource) store.findResource(name, versions.get(1));
    coverage = cref.read(null);
    assertImageColor(coverage.render(null), Color.BLUE);
}
Also used : GeneralDirectPosition(org.apache.sis.geometry.GeneralDirectPosition) Calendar(java.util.Calendar) DefiningCoverageResource(org.geotoolkit.storage.coverage.DefiningCoverageResource) DefiningMosaic(org.geotoolkit.data.multires.DefiningMosaic) DefaultImageTile(org.geotoolkit.storage.coverage.DefaultImageTile) Dimension(java.awt.Dimension) Point(java.awt.Point) VersionControl(org.geotoolkit.version.VersionControl) Date(java.util.Date) Pyramid(org.geotoolkit.data.multires.Pyramid) DefiningPyramid(org.geotoolkit.data.multires.DefiningPyramid) GenericName(org.opengis.util.GenericName) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) Version(org.geotoolkit.version.Version) PyramidalCoverageResource(org.geotoolkit.storage.coverage.PyramidalCoverageResource) DefiningPyramid(org.geotoolkit.data.multires.DefiningPyramid) DefiningMosaic(org.geotoolkit.data.multires.DefiningMosaic) Mosaic(org.geotoolkit.data.multires.Mosaic) Test(org.junit.Test)

Example 4 with DefiningCoverageResource

use of org.geotoolkit.storage.coverage.DefiningCoverageResource in project geotoolkit by Geomatys.

the class PGCoverageStore method add.

@Override
public org.apache.sis.storage.Resource add(org.apache.sis.storage.Resource resource) throws DataStoreException {
    if (!(resource instanceof DefiningCoverageResource)) {
        throw new DataStoreException("Unsupported resource " + resource);
    }
    final DefiningCoverageResource cr = (DefiningCoverageResource) resource;
    final GenericName name = cr.getName();
    final StringBuilder query = new StringBuilder();
    query.append("INSERT INTO ");
    query.append(encodeTableName("Layer"));
    query.append("(name) VALUES ('");
    query.append(name.tip());
    query.append("')");
    Connection cnx = null;
    Statement stmt = null;
    ResultSet rs = null;
    try {
        cnx = source.getConnection();
        cnx.setReadOnly(false);
        stmt = cnx.createStatement();
        stmt.executeUpdate(query.toString());
    } catch (SQLException ex) {
        throw new DataStoreException(ex);
    } finally {
        closeSafe(cnx, stmt, rs);
    }
    fireCoverageAdded(name);
    return (GridCoverageResource) findResource(name.tip().toString());
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) GenericName(org.opengis.util.GenericName) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DefiningCoverageResource(org.geotoolkit.storage.coverage.DefiningCoverageResource) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) GridCoverageResource(org.geotoolkit.storage.coverage.GridCoverageResource)

Aggregations

DefiningCoverageResource (org.geotoolkit.storage.coverage.DefiningCoverageResource)4 GenericName (org.opengis.util.GenericName)4 Dimension (java.awt.Dimension)3 GeneralDirectPosition (org.apache.sis.geometry.GeneralDirectPosition)3 DefiningMosaic (org.geotoolkit.data.multires.DefiningMosaic)3 DefiningPyramid (org.geotoolkit.data.multires.DefiningPyramid)3 Mosaic (org.geotoolkit.data.multires.Mosaic)3 Pyramid (org.geotoolkit.data.multires.Pyramid)3 PyramidalCoverageResource (org.geotoolkit.storage.coverage.PyramidalCoverageResource)3 Test (org.junit.Test)3 Point (java.awt.Point)2 SampleDimension (org.apache.sis.coverage.SampleDimension)2 DefaultImageTile (org.geotoolkit.storage.coverage.DefaultImageTile)2 BufferedImage (java.awt.image.BufferedImage)1 RenderedImage (java.awt.image.RenderedImage)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Calendar (java.util.Calendar)1