use of org.geotoolkit.data.multires.DefiningMosaic 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());
}
use of org.geotoolkit.data.multires.DefiningMosaic 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);
}
Aggregations