Search in sources :

Example 16 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class MapContextTileGenerator method generate.

@Override
public void generate(TileMatrixSet pyramid, Envelope env, NumberRange resolutions, ProcessListener listener) throws DataStoreException, InterruptedException {
    // check if we can optimize tiles generation
    boolean rasterOptimisation = true;
    search: for (MapLayer layer : MapBuilder.getLayers(sceneDef.getContext())) {
        final Style style = layer.getStyle();
        for (FeatureTypeStyle fts : style.featureTypeStyles()) {
            for (Rule rule : fts.rules()) {
                double scaleMin = rule.getMinScaleDenominator();
                double scaleMax = rule.getMaxScaleDenominator();
                // CanvasUtilities.computeSEScale
                if (scaleMin != 0.0 || scaleMax < 5.0E9) {
                    rasterOptimisation = false;
                    break search;
                }
                for (Symbolizer symbolizer : rule.symbolizers()) {
                    if (symbolizer instanceof RasterSymbolizer || symbolizer instanceof DynamicRangeSymbolizer) {
                    // ok
                    } else if (symbolizer instanceof PolygonSymbolizer) {
                        PolygonSymbolizer ps = (PolygonSymbolizer) symbolizer;
                        // check if we have a plain fill
                        Displacement displacement = ps.getDisplacement();
                        Fill fill = ps.getFill();
                        Stroke stroke = ps.getStroke();
                        Expression perpendicularOffset = ps.getPerpendicularOffset();
                        if (displacement != null) {
                            Double dx = doubleValue(displacement.getDisplacementX());
                            Double dy = doubleValue(displacement.getDisplacementX());
                            if ((dx != null && dx != 0.0) || (dy != null && dy != 0.0)) {
                                rasterOptimisation = false;
                                break search;
                            }
                        }
                        if (perpendicularOffset != null) {
                            Double off = doubleValue(perpendicularOffset);
                            if (off != null && off != 0.0) {
                                rasterOptimisation = false;
                                break search;
                            }
                        }
                        if (stroke != null) {
                            Double op = doubleValue(stroke.getOpacity());
                            Double wd = doubleValue(stroke.getWidth());
                            if ((op == null || op == 0.0) || (wd == null || wd == 0.0)) {
                            // not visible
                            } else {
                                rasterOptimisation = false;
                                break search;
                            }
                        }
                        if (fill != null) {
                            if (fill.getGraphicFill() != null) {
                                rasterOptimisation = false;
                                break search;
                            }
                        }
                    } else {
                        rasterOptimisation = false;
                        break search;
                    }
                }
            }
        }
    }
    if (rasterOptimisation) {
        /*
            We can generate the pyramid starting from the lowest level then going up
            using the previously generated level.
            */
        if (env != null) {
            try {
                CoordinateReferenceSystem targetCrs = pyramid.getCoordinateReferenceSystem();
                Envelope baseEnv = env;
                env = Envelopes.transform(env, targetCrs);
                double[] minres = new double[] { resolutions.getMinDouble(), resolutions.getMinDouble() };
                double[] maxres = new double[] { resolutions.getMaxDouble(), resolutions.getMaxDouble() };
                minres = ReferencingUtilities.convertResolution(baseEnv, minres, targetCrs, null);
                maxres = ReferencingUtilities.convertResolution(baseEnv, maxres, targetCrs, null);
                resolutions = NumberRange.create(minres[0], true, maxres[0], true);
            } catch (TransformException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            }
        }
        // generate lower level from data
        final TileMatrix[] mosaics = pyramid.getTileMatrices().toArray(new TileMatrix[0]);
        Arrays.sort(mosaics, (TileMatrix o1, TileMatrix o2) -> Double.compare(o1.getScale(), o2.getScale()));
        MapLayers parent = sceneDef.getContext();
        Hints hints = sceneDef.getHints();
        final long total = TileMatrices.countTiles(pyramid, env, resolutions);
        final AtomicLong al = new AtomicLong();
        // send an event only every few seconds
        final AtomicLong tempo = new AtomicLong(System.currentTimeMillis());
        final String msg = " / " + NumberFormat.getIntegerInstance(Locale.FRANCE).format(total);
        for (final TileMatrix mosaic : mosaics) {
            if (resolutions == null || resolutions.contains(mosaic.getScale())) {
                final Rectangle rect;
                try {
                    rect = TileMatrices.getTilesInEnvelope(mosaic, env);
                } catch (NoSuchDataException ex) {
                    continue;
                }
                final CanvasDef canvasDef = new CanvasDef();
                canvasDef.setBackground(this.canvasDef.getBackground());
                canvasDef.setEnvelope(mosaic.getEnvelope());
                final SceneDef sceneDef = new SceneDef(parent, hints);
                // one thread per line, the progressive image generates multiple tiles when drawing
                // this approach is more efficient from profiling result then using tile by tile
                // generation
                Stream<Tile> stream = LongStream.range(rect.y, rect.y + rect.height).parallel().boxed().flatMap((Long y) -> {
                    try {
                        final ProgressiveImage img = new ProgressiveImage(canvasDef, sceneDef, mosaic.getGridSize(), mosaic.getTileSize(), mosaic.getScale(), 0);
                        return img.generate(rect.x, rect.x + rect.width, y.intValue(), skipEmptyTiles);
                    } catch (Exception ex) {
                        LOGGER.log(Level.INFO, "Failed to generate a tile {0}", ex.getMessage());
                        LOGGER.log(Level.FINER, "Failed to generate a tile ", ex);
                        return Stream.empty();
                    }
                });
                if (listener != null) {
                    final NumberFormat format = NumberFormat.getIntegerInstance(Locale.FRANCE);
                    stream = stream.map((Tile t) -> {
                        long n = al.incrementAndGet();
                        if (n % 1000 == 0) {
                            final long time = System.currentTimeMillis();
                            if (tempo.updateAndGet((long operand) -> ((time - operand) > 3000) ? time : operand) == time) {
                                listener.progressing(new ProcessEvent(DUMMY, format.format(n) + msg, (float) ((((double) n) / ((double) total)) * 100.0)));
                            }
                        }
                        return t;
                    });
                }
                mosaic.writeTiles(stream, null);
                // last level event
                final NumberFormat format = NumberFormat.getIntegerInstance(Locale.FRANCE);
                long v = al.get();
                if (listener != null) {
                    listener.progressing(new ProcessEvent(DUMMY, format.format(v) + msg, (float) ((((double) v) / ((double) total)) * 100.0)));
                }
                // modify context
                final DefaultTileMatrixSet pm = new DefaultTileMatrixSet(pyramid.getCoordinateReferenceSystem());
                pm.getMosaicsInternal().add(mosaic);
                final InMemoryTiledGridCoverageResource r = new InMemoryTiledGridCoverageResource(NamesExt.create("test"));
                r.setSampleDimensions(sampleDimensions);
                r.getTileMatrixSets().add(pm);
                final MapLayers mc = MapBuilder.createContext();
                mc.getComponents().add(MapBuilder.createLayer(r));
                parent = mc;
                hints = new Hints(hints);
                hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
                hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
            }
        }
    } else {
        super.generate(pyramid, env, resolutions, listener);
    }
}
Also used : InMemoryTiledGridCoverageResource(org.geotoolkit.storage.memory.InMemoryTiledGridCoverageResource) Fill(org.opengis.style.Fill) Hints(org.geotoolkit.factory.Hints) RenderingHints(java.awt.RenderingHints) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) MapLayer(org.apache.sis.portrayal.MapLayer) Rectangle(java.awt.Rectangle) Envelope(org.opengis.geometry.Envelope) DefaultTileMatrixSet(org.geotoolkit.storage.multires.DefaultTileMatrixSet) DynamicRangeSymbolizer(org.geotoolkit.display2d.ext.dynamicrange.DynamicRangeSymbolizer) FeatureTypeStyle(org.opengis.style.FeatureTypeStyle) Style(org.opengis.style.Style) SceneDef(org.geotoolkit.display2d.service.SceneDef) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) TileMatrix(org.geotoolkit.storage.multires.TileMatrix) Stroke(org.opengis.style.Stroke) DataStoreException(org.apache.sis.storage.DataStoreException) ProcessEvent(org.geotoolkit.process.ProcessEvent) TransformException(org.opengis.referencing.operation.TransformException) Tile(org.geotoolkit.storage.multires.Tile) DefaultImageTile(org.geotoolkit.storage.coverage.DefaultImageTile) ImageTile(org.geotoolkit.storage.coverage.ImageTile) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) DynamicRangeSymbolizer(org.geotoolkit.display2d.ext.dynamicrange.DynamicRangeSymbolizer) Symbolizer(org.opengis.style.Symbolizer) Displacement(org.opengis.style.Displacement) PortrayalException(org.geotoolkit.display.PortrayalException) TransformException(org.opengis.referencing.operation.TransformException) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) DataStoreException(org.apache.sis.storage.DataStoreException) IOException(java.io.IOException) RasterSymbolizer(org.opengis.style.RasterSymbolizer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Expression(org.opengis.filter.Expression) AtomicLong(java.util.concurrent.atomic.AtomicLong) FeatureTypeStyle(org.opengis.style.FeatureTypeStyle) Rule(org.opengis.style.Rule) CanvasDef(org.geotoolkit.display2d.service.CanvasDef) MapLayers(org.apache.sis.portrayal.MapLayers) NumberFormat(java.text.NumberFormat)

Example 17 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class DefaultStyleVisitor method visit.

@Override
public Object visit(final RasterSymbolizer rasterSymbolizer, Object data) {
    final ChannelSelection cs = rasterSymbolizer.getChannelSelection();
    if (cs != null) {
        data = cs.accept(this, data);
    }
    final ColorMap cm = rasterSymbolizer.getColorMap();
    if (cm != null) {
        data = cm.accept(this, data);
    }
    final ContrastEnhancement ce = rasterSymbolizer.getContrastEnhancement();
    if (ce != null) {
        data = ce.accept(this, data);
    }
    final Symbolizer sym = rasterSymbolizer.getImageOutline();
    if (sym != null) {
        data = sym.accept(this, data);
    }
    final Expression opa = rasterSymbolizer.getOpacity();
    if (opa != null) {
        visit(opa, data);
    }
    final ShadedRelief shade = rasterSymbolizer.getShadedRelief();
    if (shade != null) {
        data = shade.accept(this, data);
    }
    return data;
}
Also used : ContrastEnhancement(org.opengis.style.ContrastEnhancement) ChannelSelection(org.opengis.style.ChannelSelection) Expression(org.opengis.filter.Expression) ColorMap(org.opengis.style.ColorMap) ShadedRelief(org.opengis.style.ShadedRelief) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) Symbolizer(org.opengis.style.Symbolizer)

Example 18 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class ListingPropertyVisitor method visit.

@Override
public Object visit(final RasterSymbolizer rasterSymbolizer, Object data) {
    visitGeomName(rasterSymbolizer, data);
    final ChannelSelection cs = rasterSymbolizer.getChannelSelection();
    if (cs != null) {
        data = cs.accept(this, data);
    }
    final ColorMap cm = rasterSymbolizer.getColorMap();
    if (cm != null) {
        data = cm.accept(this, data);
    }
    final ContrastEnhancement ce = rasterSymbolizer.getContrastEnhancement();
    if (ce != null) {
        data = ce.accept(this, data);
    }
    final Symbolizer sym = rasterSymbolizer.getImageOutline();
    if (sym != null) {
        data = sym.accept(this, data);
    }
    final Expression opa = rasterSymbolizer.getOpacity();
    if (opa != null) {
        visit(opa, (Collection<String>) data);
    }
    final ShadedRelief shade = rasterSymbolizer.getShadedRelief();
    if (shade != null) {
        data = shade.accept(this, data);
    }
    return data;
}
Also used : ContrastEnhancement(org.opengis.style.ContrastEnhancement) ChannelSelection(org.opengis.style.ChannelSelection) Expression(org.opengis.filter.Expression) ColorMap(org.opengis.style.ColorMap) ShadedRelief(org.opengis.style.ShadedRelief) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) Symbolizer(org.opengis.style.Symbolizer)

Example 19 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class SE100toGTTransformer method visitRule.

/**
 * Trasnform SLD v1.0 rule in GT Rule.
 */
public MutableRule visitRule(final org.geotoolkit.sld.xml.v100.Rule rt) {
    final MutableRule rule = styleFactory.rule();
    rule.setName(rt.getName());
    final InternationalString title = (rt.getTitle() == null) ? null : new SimpleInternationalString(rt.getTitle());
    final InternationalString abs = (rt.getAbstract() == null) ? null : new SimpleInternationalString(rt.getAbstract());
    rule.setDescription(styleFactory.description(title, abs));
    rule.setElseFilter(rt.getElseFilter() != null);
    rule.setFilter(visitFilter(rt.getFilter()));
    rule.setLegendGraphic(visitLegend(rt.getLegendGraphic()));
    rule.setMaxScaleDenominator((rt.getMaxScaleDenominator() == null) ? Double.MAX_VALUE : rt.getMaxScaleDenominator());
    rule.setMinScaleDenominator((rt.getMinScaleDenominator() == null) ? 0 : rt.getMinScaleDenominator());
    if (rt.getSymbolizer() == null || rt.getSymbolizer().isEmpty()) {
    } else {
        for (final JAXBElement<? extends org.geotoolkit.sld.xml.v100.SymbolizerType> jax : rt.getSymbolizer()) {
            final org.geotoolkit.sld.xml.v100.SymbolizerType st = jax.getValue();
            if (st == null) {
                continue;
            }
            if (st instanceof org.geotoolkit.sld.xml.v100.PointSymbolizer) {
                final org.geotoolkit.sld.xml.v100.PointSymbolizer pst = (org.geotoolkit.sld.xml.v100.PointSymbolizer) st;
                rule.symbolizers().add(visit(pst));
            } else if (st instanceof org.geotoolkit.sld.xml.v100.LineSymbolizer) {
                final org.geotoolkit.sld.xml.v100.LineSymbolizer pst = (org.geotoolkit.sld.xml.v100.LineSymbolizer) st;
                rule.symbolizers().add(visit(pst));
            } else if (st instanceof org.geotoolkit.sld.xml.v100.PolygonSymbolizer) {
                final org.geotoolkit.sld.xml.v100.PolygonSymbolizer pst = (org.geotoolkit.sld.xml.v100.PolygonSymbolizer) st;
                rule.symbolizers().add(visit(pst));
            } else if (st instanceof org.geotoolkit.sld.xml.v100.TextSymbolizer) {
                final org.geotoolkit.sld.xml.v100.TextSymbolizer pst = (org.geotoolkit.sld.xml.v100.TextSymbolizer) st;
                rule.symbolizers().add(visit(pst));
            } else if (st instanceof org.geotoolkit.sld.xml.v100.RasterSymbolizer) {
                final org.geotoolkit.sld.xml.v100.RasterSymbolizer pst = (org.geotoolkit.sld.xml.v100.RasterSymbolizer) st;
                rule.symbolizers().add(visit(pst));
            }
        }
    }
    return rule;
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) MutableRule(org.geotoolkit.style.MutableRule) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) TextSymbolizer(org.opengis.style.TextSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer)

Example 20 with RasterSymbolizer

use of org.opengis.style.RasterSymbolizer in project geotoolkit by Geomatys.

the class GTtoSE110Transformer method visit.

/**
 * Transform a GT rule in jaxb rule or OnlineResource
 */
@Override
public Object visit(final Rule rule, final Object data) {
    if (rule.getOnlineResource() != null) {
        // we store only the online resource
        return visit(rule.getOnlineResource(), null);
    }
    final RuleType rt = se_factory.createRuleType();
    rt.setName(rule.getName());
    rt.setDescription(visit(rule.getDescription(), null));
    if (rule.isElseFilter()) {
        rt.setElseFilter(se_factory.createElseFilterType());
    } else if (rule.getFilter() != null) {
        rt.setFilter(apply(rule.getFilter()));
    }
    if (rule.getLegend() != null) {
        rt.setLegendGraphic(visit(rule.getLegend(), null));
    }
    rt.setMaxScaleDenominator(rule.getMaxScaleDenominator());
    rt.setMinScaleDenominator(rule.getMinScaleDenominator());
    for (final Symbolizer symbol : rule.symbolizers()) {
        if (symbol instanceof LineSymbolizer) {
            rt.getSymbolizer().add(visit((LineSymbolizer) symbol, null));
        } else if (symbol instanceof PolygonSymbolizer) {
            rt.getSymbolizer().add(visit((PolygonSymbolizer) symbol, null));
        } else if (symbol instanceof PointSymbolizer) {
            rt.getSymbolizer().add(visit((PointSymbolizer) symbol, null));
        } else if (symbol instanceof RasterSymbolizer) {
            rt.getSymbolizer().add(visit((RasterSymbolizer) symbol, null));
        } else if (symbol instanceof TextSymbolizer) {
            rt.getSymbolizer().add(visit((TextSymbolizer) symbol, null));
        } else if (symbol instanceof ExtensionSymbolizer) {
            ((List) rt.getSymbolizer()).add(visit((ExtensionSymbolizer) symbol, null));
        }
    }
    return rt;
}
Also used : RasterSymbolizer(org.opengis.style.RasterSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RuleType(org.geotoolkit.se.xml.v110.RuleType) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) Symbolizer(org.opengis.style.Symbolizer)

Aggregations

RasterSymbolizer (org.opengis.style.RasterSymbolizer)22 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)15 LineSymbolizer (org.opengis.style.LineSymbolizer)14 PointSymbolizer (org.opengis.style.PointSymbolizer)14 TextSymbolizer (org.opengis.style.TextSymbolizer)14 Symbolizer (org.opengis.style.Symbolizer)13 Expression (org.opengis.filter.Expression)10 ColorMap (org.opengis.style.ColorMap)10 ChannelSelection (org.opengis.style.ChannelSelection)9 ContrastEnhancement (org.opengis.style.ContrastEnhancement)9 ShadedRelief (org.opengis.style.ShadedRelief)9 Unit (javax.measure.Unit)7 Description (org.opengis.style.Description)7 OverlapBehavior (org.opengis.style.OverlapBehavior)7 GridCoverage (org.apache.sis.coverage.grid.GridCoverage)4 SimpleInternationalString (org.apache.sis.util.SimpleInternationalString)4 ExtensionSymbolizer (org.opengis.style.ExtensionSymbolizer)4 IOException (java.io.IOException)3 GridCoverage2D (org.apache.sis.coverage.grid.GridCoverage2D)3 MapLayer (org.apache.sis.portrayal.MapLayer)3