use of org.opengis.style.LineSymbolizer in project geotoolkit by Geomatys.
the class IsolineSymbolizerRenderer method presentations.
@Override
public Stream<Presentation> presentations(MapLayer layer, Resource resource) {
if (!(resource instanceof GridCoverageResource)) {
return Stream.empty();
}
final GridCoverageResource coverageReference = (GridCoverageResource) resource;
final IsolineSymbolizer isolineSymbolizer = symbol.getSource();
try {
Stream<Presentation> stream = Stream.empty();
// //////////////////
// 1 - Render raster
// //////////////////
final CachedRasterSymbolizer cachedRasterSymbolizer = symbol.getCachedRasterSymbolizer();
if (!isolineSymbolizer.getIsolineOnly() || isJenksFunction(cachedRasterSymbolizer)) {
final MapLayer sublayer = MapBuilder.createLayer(coverageReference);
sublayer.setStyle(GO2Utilities.STYLE_FACTORY.style(cachedRasterSymbolizer.getSource()));
stream = Stream.concat(stream, DefaultPortrayalService.present(sublayer, coverageReference, renderingContext));
}
final LineSymbolizer lineSymbolizer = isolineSymbolizer.getLineSymbolizer();
final TextSymbolizer textSymbolizer = isolineSymbolizer.getTextSymbolizer();
// //////////////////
if (lineSymbolizer != null) {
double[] intervales = symbol.getSteps();
final CoverageQuery query = new CoverageQuery();
query.setSelection(renderingContext.getGridGeometry());
query.setSourceDomainExpansion(2);
final GridCoverageResource res = coverageReference.subset(query);
final GridCoverage inCoverage = res.read(null).forConvertedValues(true);
final GridCoverageResource resampledCovRef = new InMemoryGridCoverageResource(coverageReference.getIdentifier().orElse(null), inCoverage);
// ///////////////////
// 2.2 - Compute isolines
// //////////////////
FeatureSet isolines = null;
final ProcessDescriptor isolineDesc = symbol.getIsolineDesc();
if (isolineDesc != null) {
final Parameters inputs = Parameters.castOrWrap(isolineDesc.getInputDescriptor().createValue());
inputs.getOrCreate(IsolineDescriptor.COVERAGE_REF).setValue(resampledCovRef);
inputs.getOrCreate(IsolineDescriptor.INTERVALS).setValue(intervales);
final org.geotoolkit.process.Process process = isolineDesc.createProcess(inputs);
final ParameterValueGroup result = process.call();
isolines = (FeatureSet) result.parameter(IsolineDescriptor.FCOLL.getName().getCode()).getValue();
}
// //////////////////
if (isolines != null) {
MutableStyle featureStyle = null;
if (textSymbolizer != null) {
featureStyle = GO2Utilities.STYLE_FACTORY.style(lineSymbolizer, textSymbolizer);
} else {
featureStyle = GO2Utilities.STYLE_FACTORY.style(lineSymbolizer);
}
MapLayer fml = MapBuilder.createLayer(isolines);
fml.setStyle(featureStyle);
stream = Stream.concat(stream, DefaultPortrayalService.present(fml, isolines, renderingContext));
}
}
return stream;
} catch (DataStoreException | ProcessException ex) {
ExceptionPresentation ep = new ExceptionPresentation(ex);
ep.setLayer(layer);
ep.setResource(resource);
return Stream.of(ep);
}
}
use of org.opengis.style.LineSymbolizer in project geotoolkit by Geomatys.
the class SEforSLD100Test method testLineSymbolizer.
@Test
public void testLineSymbolizer() throws JAXBException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
final Marshaller MARSHALLER = POOL.acquireMarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_SE_SYMBOL_LINE);
assertNotNull(obj);
JAXBElement<org.geotoolkit.sld.xml.v100.LineSymbolizer> jax = (JAXBElement<org.geotoolkit.sld.xml.v100.LineSymbolizer>) obj;
LineSymbolizer lineSymbol = TRANSFORMER_GT.visit(jax.getValue());
assertNotNull(lineSymbol);
assertEquals(lineSymbol.getGeometryPropertyName(), valueGeom);
assertEquals(Units.POINT, lineSymbol.getUnitOfMeasure());
assertNotNull(lineSymbol.getStroke());
assertEquals(floatValue(lineSymbol.getStroke().getWidth()), 13f, DELTA);
assertEquals(floatValue(lineSymbol.getStroke().getOpacity()), 0.4f, DELTA);
assertEquals(stringValue(lineSymbol.getStroke().getLineJoin()), "bevel");
assertEquals(stringValue(lineSymbol.getStroke().getLineCap()), "butt");
assertEquals(floatValue(lineSymbol.getStroke().getDashOffset()), 2.3f, DELTA);
assertEquals(stringValue(lineSymbol.getStroke().getColor()), "#404040");
// Write test
JAXBElement<org.geotoolkit.sld.xml.v100.LineSymbolizer> pvt = TRANSFORMER_OGC.visit(lineSymbol, null);
assertNotNull(pvt);
assertEquals(pvt.getValue().getGeometry().getPropertyName().getContent(), "");
assertNotNull(pvt.getValue().getStroke());
MARSHALLER.marshal(pvt, TEST_FILE_SE_SYMBOL_LINE);
POOL.recycle(MARSHALLER);
POOL.recycle(UNMARSHALLER);
}
use of org.opengis.style.LineSymbolizer in project geotoolkit by Geomatys.
the class CategoryStyleBuilder method derivateSymbolizer.
/**
* Derivate a symbolizer with a new color.
*/
public Symbolizer derivateSymbolizer(final Symbolizer symbol, final Color color) {
if (symbol instanceof PolygonSymbolizer) {
PolygonSymbolizer ps = (PolygonSymbolizer) symbol;
Fill fill = sf.fill(sf.literal(color), ps.getFill().getOpacity());
return sf.polygonSymbolizer(ps.getName(), ps.getGeometryPropertyName(), ps.getDescription(), ps.getUnitOfMeasure(), ps.getStroke(), fill, ps.getDisplacement(), ps.getPerpendicularOffset());
} else if (symbol instanceof LineSymbolizer) {
LineSymbolizer ls = (LineSymbolizer) symbol;
Stroke oldStroke = ls.getStroke();
Stroke stroke = sf.stroke(sf.literal(color), oldStroke.getOpacity(), oldStroke.getWidth(), oldStroke.getLineJoin(), oldStroke.getLineCap(), oldStroke.getDashArray(), oldStroke.getDashOffset());
return sf.lineSymbolizer(ls.getName(), ls.getGeometryPropertyName(), ls.getDescription(), ls.getUnitOfMeasure(), stroke, ls.getPerpendicularOffset());
} else if (symbol instanceof PointSymbolizer) {
PointSymbolizer ps = (PointSymbolizer) symbol;
Graphic oldGraphic = ps.getGraphic();
Mark oldMark = (Mark) oldGraphic.graphicalSymbols().get(0);
Fill fill = sf.fill(sf.literal(color), oldMark.getFill().getOpacity());
List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
symbols.add(sf.mark(oldMark.getWellKnownName(), fill, oldMark.getStroke()));
Graphic graphic = sf.graphic(symbols, oldGraphic.getOpacity(), oldGraphic.getSize(), oldGraphic.getRotation(), oldGraphic.getAnchorPoint(), oldGraphic.getDisplacement());
return sf.pointSymbolizer(graphic, ps.getGeometryPropertyName());
} else {
throw new IllegalArgumentException("unexpected symbolizer type : " + symbol);
}
}
use of org.opengis.style.LineSymbolizer 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.LineSymbolizer 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