Search in sources :

Example 1 with TiledResource

use of org.geotoolkit.storage.multires.TiledResource in project geotoolkit by Geomatys.

the class WMTSClientDemo method createContext.

public static MapLayers createContext() throws Exception {
    final MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
    final WebMapTileClient server = new WebMapTileClient(new URL("http://localhost:8080/constellation/WS/wmts/test"), WMTSVersion.v100);
    for (final Resource ref : DataStores.flatten(server, false)) {
        final GenericName n = ref.getIdentifier().get();
        System.out.println(n);
        final MapLayer layer = MapBuilder.createCoverageLayer(ref, new DefaultStyleFactory().style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER));
        TiledResource model = (TiledResource) ref;
        System.out.println(model);
        layer.setTitle(n.tip().toString());
        context.getComponents().add(layer);
    }
    return context;
}
Also used : GenericName(org.opengis.util.GenericName) TiledResource(org.geotoolkit.storage.multires.TiledResource) MapLayer(org.apache.sis.portrayal.MapLayer) Resource(org.apache.sis.storage.Resource) TiledResource(org.geotoolkit.storage.multires.TiledResource) WebMapTileClient(org.geotoolkit.wmts.WebMapTileClient) URL(java.net.URL) DefaultStyleFactory(org.geotoolkit.style.DefaultStyleFactory) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 2 with TiledResource

use of org.geotoolkit.storage.multires.TiledResource in project geotoolkit by Geomatys.

the class TileDebugSymbolizerRenderer method presentations.

@Override
public Stream<Presentation> presentations(MapLayer layer, Resource resource) {
    if (!(resource instanceof TiledResource)) {
        return Stream.empty();
    }
    final TiledResource mrm = (TiledResource) resource;
    final List<Presentation> presentations = new ArrayList<>();
    final Graphics2D graphics = renderingContext.getGraphics();
    final Color textColor = Color.YELLOW;
    final Color bgColor = new Color(0, 0, 0, 150);
    final Stroke stroke = new BasicStroke(1);
    final Font font = new Font("Dialog", Font.BOLD, 12);
    final FontMetrics fontMetrics = graphics.getFontMetrics(font);
    try {
        final Map.Entry<Envelope, List<TileMatrix>> intersect = TileMatrixSetCoverageReader.intersect(mrm, getRenderingContext().getGridGeometry());
        final List<TileMatrix> mosaics = intersect.getValue();
        final Envelope wantedEnv = intersect.getKey();
        for (TileMatrix m : mosaics) {
            final CoordinateReferenceSystem crs = m.getUpperLeftCorner().getCoordinateReferenceSystem();
            final CoordinateReferenceSystem crs2d = CRS.getHorizontalComponent(crs);
            final Rectangle rectangle;
            try {
                rectangle = TileMatrices.getTilesInEnvelope(m, wantedEnv);
            } catch (NoSuchDataException ex) {
                continue;
            }
            for (int x = 0; x < rectangle.width; x++) {
                for (int y = 0; y < rectangle.height; y++) {
                    final GridGeometry gridgeom = TileMatrices.getTileGridGeometry2D(m, new Point(rectangle.x + x, rectangle.y + y), crs2d);
                    Geometry geom = GeometricUtilities.toJTSGeometry(gridgeom.getEnvelope(), GeometricUtilities.WrapResolution.NONE);
                    geom.setUserData(crs2d);
                    geom = org.apache.sis.internal.feature.jts.JTS.transform(geom, renderingContext.getDisplayCRS());
                    Shape shp = new JTSGeometryJ2D(geom);
                    final ShapePresentation border = new ShapePresentation(layer, resource, null);
                    border.stroke = stroke;
                    border.strokePaint = Color.BLACK;
                    border.shape = shp;
                    presentations.add(border);
                    final Rectangle bounds = shp.getBounds();
                    final double centerX = bounds.getCenterX();
                    final double centerY = bounds.getCenterY();
                    String mid = m.getIdentifier();
                    if (mid.length() > 10) {
                        mid = mid.substring(0, 9) + "..";
                    }
                    final String mosaicId = "Z: " + mid;
                    final String mosaicScale = "S: " + new DecimalFormat("#0.00000").format(m.getScale());
                    final String strX = "X: " + (rectangle.x + x);
                    final String strY = "Y: " + (rectangle.y + y);
                    String longest = mosaicId;
                    if (mosaicScale.length() > longest.length())
                        longest = mosaicScale;
                    if (strX.length() > longest.length())
                        longest = strX;
                    if (strY.length() > longest.length())
                        longest = strY;
                    Font ft = font;
                    FontMetrics fm = fontMetrics;
                    while (fm.stringWidth(longest) > bounds.width && ft.getSize() > 8) {
                        ft = new Font(ft.getFamily(), ft.getStyle(), ft.getSize() - 1);
                        fm = graphics.getFontMetrics(ft);
                    }
                    graphics.setFont(ft);
                    final double fntHeight = fm.getHeight();
                    Rectangle2D txtbbox = fm.getStringBounds(mosaicId, g2d);
                    {
                        final AttributedString as = new AttributedString(mosaicId);
                        as.addAttribute(TextAttribute.FONT, ft);
                        as.addAttribute(TextAttribute.BACKGROUND, bgColor);
                        final TextPresentation2 tp = new TextPresentation2(layer, resource, null);
                        tp.forGrid(renderingContext);
                        tp.text = as;
                        tp.paint = textColor;
                        tp.x = (float) (centerX - txtbbox.getWidth() / 2.0);
                        tp.y = (float) (centerY - fntHeight);
                        presentations.add(tp);
                    }
                    {
                        final AttributedString as = new AttributedString(mosaicScale);
                        as.addAttribute(TextAttribute.FONT, ft);
                        as.addAttribute(TextAttribute.BACKGROUND, bgColor);
                        txtbbox = fm.getStringBounds(mosaicScale, g2d);
                        final TextPresentation2 tp = new TextPresentation2(layer, resource, null);
                        tp.forGrid(renderingContext);
                        tp.text = as;
                        tp.paint = textColor;
                        tp.x = (float) (centerX - txtbbox.getWidth() / 2.0);
                        tp.y = (float) (centerY);
                        presentations.add(tp);
                    }
                    {
                        final AttributedString as = new AttributedString(strX);
                        as.addAttribute(TextAttribute.FONT, ft);
                        as.addAttribute(TextAttribute.BACKGROUND, bgColor);
                        txtbbox = fm.getStringBounds(strX, g2d);
                        final TextPresentation2 tp = new TextPresentation2(layer, resource, null);
                        tp.forGrid(renderingContext);
                        tp.text = as;
                        tp.paint = textColor;
                        tp.x = (float) (centerX - txtbbox.getWidth() / 2.0);
                        tp.y = (float) (centerY + fntHeight);
                        presentations.add(tp);
                    }
                    {
                        final AttributedString as = new AttributedString(strY);
                        as.addAttribute(TextAttribute.FONT, ft);
                        as.addAttribute(TextAttribute.BACKGROUND, bgColor);
                        txtbbox = fm.getStringBounds(strY, g2d);
                        final TextPresentation2 tp = new TextPresentation2(layer, resource, null);
                        tp.forGrid(renderingContext);
                        tp.text = as;
                        tp.paint = textColor;
                        tp.x = (float) (centerX - txtbbox.getWidth() / 2.0);
                        tp.y = (float) (centerY + 2 * fntHeight);
                        presentations.add(tp);
                    }
                }
            }
        }
    } catch (DataStoreException | TransformException | FactoryException ex) {
        ExceptionPresentation ep = new ExceptionPresentation(ex);
        ep.setLayer(layer);
        ep.setResource(resource);
        presentations.add(ep);
    }
    return presentations.stream();
}
Also used : BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) FactoryException(org.opengis.util.FactoryException) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) AttributedString(java.text.AttributedString) Envelope(org.opengis.geometry.Envelope) JTSGeometryJ2D(org.geotoolkit.geometry.jts.awt.JTSGeometryJ2D) Font(java.awt.Font) AttributedString(java.text.AttributedString) TiledResource(org.geotoolkit.storage.multires.TiledResource) FontMetrics(java.awt.FontMetrics) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) ArrayList(java.util.ArrayList) List(java.util.List) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) TextPresentation2(org.geotoolkit.display2d.presentation.TextPresentation2) TileMatrix(org.geotoolkit.storage.multires.TileMatrix) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) DataStoreException(org.apache.sis.storage.DataStoreException) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) TransformException(org.opengis.referencing.operation.TransformException) Point(java.awt.Point) ShapePresentation(org.geotoolkit.display2d.presentation.ShapePresentation) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) Presentation(org.apache.sis.internal.map.Presentation) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D) GridGeometry(org.apache.sis.coverage.grid.GridGeometry) Geometry(org.locationtech.jts.geom.Geometry) ShapePresentation(org.geotoolkit.display2d.presentation.ShapePresentation) Map(java.util.Map)

Example 3 with TiledResource

use of org.geotoolkit.storage.multires.TiledResource 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)

Example 4 with TiledResource

use of org.geotoolkit.storage.multires.TiledResource 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;
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) DefiningGridCoverageResource(org.geotoolkit.storage.coverage.DefiningGridCoverageResource) AggregationEvent(org.geotoolkit.storage.event.AggregationEvent) DefiningTiledGridCoverageResource(org.geotoolkit.storage.coverage.DefiningTiledGridCoverageResource) Resource(org.apache.sis.storage.Resource) AbstractResource(org.apache.sis.storage.AbstractResource) TiledResource(org.geotoolkit.storage.multires.TiledResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) DefiningGridCoverageResource(org.geotoolkit.storage.coverage.DefiningGridCoverageResource) DefiningTiledGridCoverageResource(org.geotoolkit.storage.coverage.DefiningTiledGridCoverageResource) Feature(org.opengis.feature.Feature) GenericName(org.opengis.util.GenericName) TiledResource(org.geotoolkit.storage.multires.TiledResource) DefiningTiledGridCoverageResource(org.geotoolkit.storage.coverage.DefiningTiledGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) DefiningGridCoverageResource(org.geotoolkit.storage.coverage.DefiningGridCoverageResource) FeatureSet(org.apache.sis.storage.FeatureSet) WritableAggregate(org.apache.sis.storage.WritableAggregate) Aggregate(org.apache.sis.storage.Aggregate)

Example 5 with TiledResource

use of org.geotoolkit.storage.multires.TiledResource in project geotoolkit by Geomatys.

the class MathCalcProcess method execute.

@Override
protected void execute() throws ProcessException {
    final GridCoverage[] inCoverages = inputParameters.getValue(MathCalcDescriptor.IN_COVERAGES);
    final String inFormula = inputParameters.getValue(MathCalcDescriptor.IN_FORMULA);
    final String[] inMapping = inputParameters.getValue(MathCalcDescriptor.IN_MAPPING);
    final WritableGridCoverageResource outRef = inputParameters.getValue(MathCalcDescriptor.IN_RESULT_COVERAGE);
    final GridGeometry gg;
    try {
        gg = outRef.getGridGeometry();
    } catch (DataStoreException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
    // create expression
    final FilterFactory2 ff = FilterUtilities.FF;
    final Expression exp;
    try {
        exp = CQL.parseExpression(inFormula, ff);
    } catch (CQLException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
    // prepare dynamic pick object
    final MathCalcCoverageEvaluator evaluator;
    try {
        evaluator = new MathCalcCoverageEvaluator(inCoverages, inMapping, exp, gg.getCoordinateReferenceSystem());
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
    final FillCoverage filler = new FillCoverage();
    try {
        if (outRef instanceof TiledResource) {
            filler.fill((TiledResource) outRef, evaluator);
        } else {
            filler.fill(outRef, evaluator, null);
        }
    } catch (DataStoreException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (TransformException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    } catch (FactoryException ex) {
        throw new ProcessException(ex.getMessage(), this, ex);
    }
}
Also used : GridGeometry(org.apache.sis.coverage.grid.GridGeometry) DataStoreException(org.apache.sis.storage.DataStoreException) FactoryException(org.opengis.util.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) ProcessException(org.geotoolkit.process.ProcessException) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) Expression(org.opengis.filter.Expression) TiledResource(org.geotoolkit.storage.multires.TiledResource) WritableGridCoverageResource(org.apache.sis.storage.WritableGridCoverageResource) CQLException(org.apache.sis.cql.CQLException) FilterFactory2(org.geotoolkit.filter.FilterFactory2)

Aggregations

TiledResource (org.geotoolkit.storage.multires.TiledResource)5 DataStoreException (org.apache.sis.storage.DataStoreException)4 GridGeometry (org.apache.sis.coverage.grid.GridGeometry)3 Resource (org.apache.sis.storage.Resource)3 GenericName (org.opengis.util.GenericName)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Aggregate (org.apache.sis.storage.Aggregate)2 FeatureSet (org.apache.sis.storage.FeatureSet)2 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)2 WritableAggregate (org.apache.sis.storage.WritableAggregate)2 BasicStroke (java.awt.BasicStroke)1 Color (java.awt.Color)1 Font (java.awt.Font)1 FontMetrics (java.awt.FontMetrics)1 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 Stroke (java.awt.Stroke)1