use of org.geotoolkit.storage.coverage.DefiningGridCoverageResource in project geotoolkit by Geomatys.
the class PyramidalModelStoreNDTest method getCoverageStore.
private DataStore getCoverageStore() throws Exception {
if (store != null) {
return store;
}
// create a small pyramid
store = createStore();
final WritableAggregate agg = (WritableAggregate) store;
final CoordinateReferenceSystem horizontal = CommonCRS.WGS84.normalizedGeographic();
final CoordinateReferenceSystem vertical = CommonCRS.Vertical.ELLIPSOIDAL.crs();
crs = new GeodeticObjectBuilder().addName("3dcrs").createCompoundCRS(horizontal, vertical);
final GenericName name = NamesExt.create("test");
ref = (T) agg.add(new DefiningGridCoverageResource(name));
// prepare expected colors
int color = 0;
for (int v = 0; v < CORNER_V.length; v++) {
colors[v][0] = new int[2][2];
colors[v][1] = new int[4][3];
colors[v][0][0][0] = color++;
colors[v][0][1][0] = color++;
colors[v][0][0][1] = color++;
colors[v][0][1][1] = color++;
colors[v][1][0][0] = color++;
colors[v][1][1][0] = color++;
colors[v][1][2][0] = color++;
colors[v][1][3][0] = color++;
colors[v][1][0][1] = color++;
colors[v][1][1][1] = color++;
colors[v][1][2][1] = color++;
colors[v][1][3][1] = color++;
colors[v][1][0][2] = color++;
colors[v][1][1][2] = color++;
colors[v][1][2][2] = color++;
colors[v][1][3][2] = color++;
}
final TileMatrixSet pyramid = (TileMatrixSet) ref.createTileMatrixSet(new DefiningTileMatrixSet(crs));
for (int v = 0; v < CORNER_V.length; v++) {
final TileMatrix mosaic_s0 = pyramid.createTileMatrix(new DefiningTileMatrix(null, createCorner(CORNER_LONG, CORNER_LAT, CORNER_V[v]), 1, new Dimension(10, 10), new Dimension(2, 2)));
final TileMatrix mosaic_s1 = pyramid.createTileMatrix(new DefiningTileMatrix(null, createCorner(CORNER_LONG, CORNER_LAT, CORNER_V[v]), 0.5, new Dimension(10, 10), new Dimension(4, 3)));
// insert tiles
mosaic_s0.writeTiles(Stream.of(new DefaultImageTile(createImage(colors[v][0][0][0]), 0, 0), new DefaultImageTile(createImage(colors[v][0][1][0]), 1, 0), new DefaultImageTile(createImage(colors[v][0][0][1]), 0, 1), new DefaultImageTile(createImage(colors[v][0][1][1]), 1, 1)), null);
mosaic_s1.writeTiles(Stream.of(new DefaultImageTile(createImage(colors[v][1][0][0]), 0, 0), new DefaultImageTile(createImage(colors[v][1][1][0]), 1, 0), new DefaultImageTile(createImage(colors[v][1][2][0]), 2, 0), new DefaultImageTile(createImage(colors[v][1][3][0]), 3, 0), new DefaultImageTile(createImage(colors[v][1][0][1]), 0, 1), new DefaultImageTile(createImage(colors[v][1][1][1]), 1, 1), new DefaultImageTile(createImage(colors[v][1][2][1]), 2, 1), new DefaultImageTile(createImage(colors[v][1][3][1]), 3, 1), new DefaultImageTile(createImage(colors[v][1][0][2]), 0, 2), new DefaultImageTile(createImage(colors[v][1][1][2]), 1, 2), new DefaultImageTile(createImage(colors[v][1][2][2]), 2, 2), new DefaultImageTile(createImage(colors[v][1][3][2]), 3, 2)), null);
}
crs = pyramid.getCoordinateReferenceSystem();
return store;
}
use of org.geotoolkit.storage.coverage.DefiningGridCoverageResource in project geotoolkit by Geomatys.
the class FileCoverageStore method add.
@Override
public GridCoverageResource add(org.apache.sis.storage.Resource resource) throws DataStoreException {
if (!(resource instanceof DefiningGridCoverageResource)) {
throw new DataStoreException("Unsupported resource " + resource);
}
final DefiningGridCoverageResource cr = (DefiningGridCoverageResource) resource;
final GenericName name = cr.getName();
final Collection<GenericName> names = DataStores.getNames(this, true, DataSet.class);
if (names.contains(name)) {
throw new IllegalNameException("Coverage " + name + " already exist in this datastore.");
}
final String fileName = name.tip().toString();
final URI filePath = rootPath.resolve(fileName + ".tiff");
final FileCoverageResource fcr = new FileCoverageResource(this, name, Paths.get(filePath));
resources.add(fcr);
return fcr;
}
use of org.geotoolkit.storage.coverage.DefiningGridCoverageResource in project geotoolkit by Geomatys.
the class XMLCoverageStore method add.
@Override
public GridCoverageResource add(org.apache.sis.storage.Resource resource) throws DataStoreException {
if (!(resource instanceof DefiningGridCoverageResource)) {
throw new DataStoreException("Unsupported resource " + resource);
}
final DefiningGridCoverageResource cr = (DefiningGridCoverageResource) resource;
final GenericName name = cr.getName();
return create(name, null, null);
}
use of org.geotoolkit.storage.coverage.DefiningGridCoverageResource in project geotoolkit by Geomatys.
the class InMemoryAggregate method add.
@Override
public synchronized Resource add(Resource resource) throws DataStoreException {
Resource newr;
if (resource instanceof FeatureSet) {
final FeatureSet fs = (FeatureSet) resource;
final InMemoryFeatureSet newres = new InMemoryFeatureSet(fs.getType());
try (Stream<Feature> stream = fs.features(false)) {
newres.add(stream.iterator());
}
newr = newres;
} else if (resource instanceof DefiningTiledGridCoverageResource) {
final DefiningTiledGridCoverageResource cr = (DefiningTiledGridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryTiledGridCoverageResource(name);
} else if (resource instanceof GridCoverageResource && resource instanceof TiledResource) {
final GridCoverageResource cr = (GridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryTiledGridCoverageResource(name);
} else if (resource instanceof GridCoverageResource) {
final GridCoverageResource cr = (GridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
final InMemoryGridCoverageResource newres = new InMemoryGridCoverageResource(name);
newres.write(cr.read(null));
newr = newres;
} else if (resource instanceof DefiningGridCoverageResource) {
final DefiningGridCoverageResource cr = (DefiningGridCoverageResource) resource;
final GenericName name = cr.getIdentifier().orElse(null);
newr = new InMemoryGridCoverageResource(name);
} else if (resource instanceof Aggregate) {
final Aggregate agg = (Aggregate) resource;
final InMemoryAggregate newres = new InMemoryAggregate(agg.getIdentifier().orElse(null));
for (Resource r : agg.components()) {
newres.add(r);
}
newr = newres;
} else {
throw new DataStoreException("Unsupported resource type " + resource);
}
resources.add(newr);
listeners.fire(new AggregationEvent(this, AggregationEvent.TYPE_ADD, newr), AggregationEvent.class);
return newr;
}
Aggregations