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);
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations