use of org.apache.sis.storage.WritableAggregate 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.apache.sis.storage.WritableAggregate in project geotoolkit by Geomatys.
the class DataStores method toRawModel.
private static String toRawModel(Resource rs) {
final Map<String, Object> mp = new LinkedHashMap<>();
try {
final GenericName identifier = rs.getIdentifier().orElse(null);
if (identifier != null) {
mp.put("identifier", identifier.toString());
}
} catch (DataStoreException ex) {
mp.put("identifier", "ERROR (" + ex.getMessage() + ")");
}
if (rs instanceof FeatureSet) {
final FeatureSet cdt = (FeatureSet) rs;
final Map<String, Object> map = new LinkedHashMap<>();
mp.put("FeatureSet", map);
try {
final FeatureType type = cdt.getType();
map.put("type name", type.getName().toString());
if (cdt instanceof WritableFeatureSet) {
map.put("writable", Boolean.TRUE);
} else {
map.put("writable", Boolean.FALSE);
}
map.put("type", type.toString());
} catch (DataStoreException ex) {
map.put("type", "ERROR (" + ex.getMessage() + ")");
}
}
if (rs instanceof GridCoverageResource) {
final GridCoverageResource cdt = (GridCoverageResource) rs;
final Map<String, Object> map = new LinkedHashMap<>();
mp.put("GridCoverageResource", map);
try {
final GridGeometry gridGeometry = cdt.getGridGeometry();
map.put("grid geometry", gridGeometry);
} catch (DataStoreException ex) {
map.put("grid geometry", "ERROR (" + ex.getMessage() + ")");
}
try {
final List<SampleDimension> sampleDimensions = cdt.getSampleDimensions();
final List<Map> sds = new ArrayList<>();
for (SampleDimension sd : sampleDimensions) {
final Map<String, Object> tf = new LinkedHashMap<>();
tf.put("name", String.valueOf(sd.getName()));
tf.put("unit", String.valueOf(sd.getUnits().orElse(Units.UNITY).getSymbol()));
tf.put("background", String.valueOf(sd.getBackground().orElse(null)));
final List<Map> cats = new ArrayList<>();
for (Category cat : sd.getCategories()) {
final Map<String, Object> cf = new LinkedHashMap<>();
cf.put("name", cat.getName().toString());
cf.put("quantitative", cat.isQuantitative());
cats.add(cf);
}
tf.put("categories", cats);
sds.add(tf);
}
map.put("sample dimensions", StringUtilities.toStringTree("", sampleDimensions));
} catch (DataStoreException ex) {
map.put("sample dimensions", "ERROR (" + ex.getMessage() + ")");
}
}
if (rs instanceof TiledResource) {
final TiledResource cdt = (TiledResource) rs;
final TileFormat tileFormat = cdt.getTileFormat();
final Map<String, Object> map = new LinkedHashMap<>();
mp.put("MultiResolutionResource", map);
if (tileFormat != null) {
final Map<String, Object> tf = new LinkedHashMap<>();
map.put("tile format", tf);
tf.put("mime type", tileFormat.getMimeType());
tf.put("provider id", tileFormat.getProviderId());
tf.put("compression", tileFormat.getCompression().name());
}
try {
final Collection<? extends TileMatrixSet> models = cdt.getTileMatrixSets();
final List<String> mms = new ArrayList<>();
for (TileMatrixSet mrm : models) {
mms.add(mrm.toString());
}
map.put("models", StringUtilities.toStringTree("", mms));
} catch (DataStoreException ex) {
map.put("models", "ERROR (" + ex.getMessage() + ")");
}
}
if (rs instanceof Aggregate) {
final Aggregate cdt = (Aggregate) rs;
final Map<String, Object> map = new LinkedHashMap<>();
mp.put("Aggregate", map);
if (cdt instanceof WritableAggregate) {
map.put("writable", Boolean.TRUE);
} else {
map.put("writable", Boolean.FALSE);
}
try {
final Collection<? extends Resource> components = cdt.components();
map.put("nb components", components.size());
int i = 0;
for (Resource r : components) {
map.put("component[" + i++ + "]", toRawModel(r));
}
} catch (DataStoreException ex) {
map.put("models", "ERROR (" + ex.getMessage() + ")");
}
}
if (rs instanceof ProgressiveResource) {
final ProgressiveResource pr = (ProgressiveResource) rs;
mp.put("ProgressiveResource", pr.toString());
}
return StringUtilities.toStringTree(Classes.getShortClassName(rs), toList(mp));
}
Aggregations