Search in sources :

Example 1 with WritableAggregate

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;
}
Also used : TileMatrixSet(org.geotoolkit.storage.multires.TileMatrixSet) DefiningTileMatrixSet(org.geotoolkit.storage.multires.DefiningTileMatrixSet) DefiningTileMatrixSet(org.geotoolkit.storage.multires.DefiningTileMatrixSet) DefiningTileMatrix(org.geotoolkit.storage.multires.DefiningTileMatrix) GenericName(org.opengis.util.GenericName) WritableAggregate(org.apache.sis.storage.WritableAggregate) DefiningGridCoverageResource(org.geotoolkit.storage.coverage.DefiningGridCoverageResource) DefaultImageTile(org.geotoolkit.storage.coverage.DefaultImageTile) GeodeticObjectBuilder(org.apache.sis.internal.referencing.GeodeticObjectBuilder) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Dimension(java.awt.Dimension) TileMatrix(org.geotoolkit.storage.multires.TileMatrix) DefiningTileMatrix(org.geotoolkit.storage.multires.DefiningTileMatrix)

Example 2 with WritableAggregate

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));
}
Also used : ProgressiveResource(org.geotoolkit.storage.multires.ProgressiveResource) FeatureType(org.opengis.feature.FeatureType) WritableFeatureSet(org.apache.sis.storage.WritableFeatureSet) Category(org.apache.sis.coverage.Category) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) GenericName(org.opengis.util.GenericName) TiledResource(org.geotoolkit.storage.multires.TiledResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) TileMatrixSet(org.geotoolkit.storage.multires.TileMatrixSet) DataStoreException(org.apache.sis.storage.DataStoreException) TileFormat(org.geotoolkit.storage.multires.TileFormat) ProgressiveResource(org.geotoolkit.storage.multires.ProgressiveResource) Resource(org.apache.sis.storage.Resource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) TiledResource(org.geotoolkit.storage.multires.TiledResource) SampleDimension(org.apache.sis.coverage.SampleDimension) WritableAggregate(org.apache.sis.storage.WritableAggregate) WritableFeatureSet(org.apache.sis.storage.WritableFeatureSet) FeatureSet(org.apache.sis.storage.FeatureSet) WritableAggregate(org.apache.sis.storage.WritableAggregate) Aggregate(org.apache.sis.storage.Aggregate) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

WritableAggregate (org.apache.sis.storage.WritableAggregate)2 TileMatrixSet (org.geotoolkit.storage.multires.TileMatrixSet)2 GenericName (org.opengis.util.GenericName)2 Dimension (java.awt.Dimension)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Category (org.apache.sis.coverage.Category)1 SampleDimension (org.apache.sis.coverage.SampleDimension)1 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)1 GeodeticObjectBuilder (org.apache.sis.internal.referencing.GeodeticObjectBuilder)1 Aggregate (org.apache.sis.storage.Aggregate)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 FeatureSet (org.apache.sis.storage.FeatureSet)1 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)1 Resource (org.apache.sis.storage.Resource)1 WritableFeatureSet (org.apache.sis.storage.WritableFeatureSet)1 DefaultImageTile (org.geotoolkit.storage.coverage.DefaultImageTile)1 DefiningGridCoverageResource (org.geotoolkit.storage.coverage.DefiningGridCoverageResource)1