Search in sources :

Example 11 with LineSymbolizer

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);
    }
}
Also used : org.geotoolkit.process(org.geotoolkit.process) DataStoreException(org.apache.sis.storage.DataStoreException) Parameters(org.apache.sis.parameter.Parameters) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) MapLayer(org.apache.sis.portrayal.MapLayer) CoverageQuery(org.apache.sis.storage.CoverageQuery) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) Presentation(org.apache.sis.internal.map.Presentation) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) MutableStyle(org.geotoolkit.style.MutableStyle) TextSymbolizer(org.opengis.style.TextSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) InMemoryGridCoverageResource(org.geotoolkit.storage.memory.InMemoryGridCoverageResource) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) FeatureSet(org.apache.sis.storage.FeatureSet) CachedRasterSymbolizer(org.geotoolkit.display2d.style.CachedRasterSymbolizer)

Example 12 with LineSymbolizer

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);
}
Also used : Marshaller(javax.xml.bind.Marshaller) LineSymbolizer(org.opengis.style.LineSymbolizer) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 13 with LineSymbolizer

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);
    }
}
Also used : PointSymbolizer(org.opengis.style.PointSymbolizer) Fill(org.opengis.style.Fill) Stroke(org.opengis.style.Stroke) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) Graphic(org.opengis.style.Graphic) LineSymbolizer(org.opengis.style.LineSymbolizer) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) Mark(org.opengis.style.Mark)

Example 14 with LineSymbolizer

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;
}
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 15 with LineSymbolizer

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

LineSymbolizer (org.opengis.style.LineSymbolizer)18 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)9 Stroke (org.opengis.style.Stroke)8 MutableStyle (org.geotoolkit.style.MutableStyle)7 PointSymbolizer (org.opengis.style.PointSymbolizer)7 Unit (javax.measure.Unit)6 Expression (org.opengis.filter.Expression)6 Description (org.opengis.style.Description)6 TextSymbolizer (org.opengis.style.TextSymbolizer)6 ArrayList (java.util.ArrayList)5 GraphicStroke (org.opengis.style.GraphicStroke)5 GraphicalSymbol (org.opengis.style.GraphicalSymbol)4 RasterSymbolizer (org.opengis.style.RasterSymbolizer)4 ExtensionSymbolizer (org.opengis.style.ExtensionSymbolizer)3 Fill (org.opengis.style.Fill)3 Graphic (org.opengis.style.Graphic)3 Symbolizer (org.opengis.style.Symbolizer)3 Color (java.awt.Color)2 JAXBElement (javax.xml.bind.JAXBElement)2 Marshaller (javax.xml.bind.Marshaller)2