Search in sources :

Example 6 with Pyramid

use of org.geotoolkit.data.multires.Pyramid in project geotoolkit by Geomatys.

the class PGVersionControl method dropVersion.

@Override
public void dropVersion(Version version) throws VersioningException {
    try {
        final PyramidalCoverageResource ref = (PyramidalCoverageResource) store.findResource(name, version);
        final Collection<Pyramid> pyramids = Pyramids.getPyramids(ref);
        for (Pyramid p : pyramids) {
            ref.removeModel(p.getIdentifier());
        }
    } catch (DataStoreException ex) {
        throw new VersioningException(ex.getMessage(), ex);
    }
}
Also used : Pyramid(org.geotoolkit.data.multires.Pyramid) DataStoreException(org.apache.sis.storage.DataStoreException) PyramidalCoverageResource(org.geotoolkit.storage.coverage.PyramidalCoverageResource) VersioningException(org.geotoolkit.version.VersioningException)

Example 7 with Pyramid

use of org.geotoolkit.data.multires.Pyramid 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)

Aggregations

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