Search in sources :

Example 6 with TextSymbolizer

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

the class Styles method centeredText.

public static MutableStyle centeredText() {
    // general informations
    final String name = "mySymbol";
    final Description desc = DEFAULT_DESCRIPTION;
    // use the default geometry of the feature
    final String geometry = null;
    final Unit unit = Units.POINT;
    final Expression label = FF.property("CNTRY_NAME");
    final Font font = SF.font(FF.literal("Arial"), FONT_STYLE_ITALIC, FONT_WEIGHT_BOLD, FF.literal(14));
    final LabelPlacement placement = SF.pointPlacement();
    final Halo halo = SF.halo(Color.WHITE, 1);
    final Fill fill = SF.fill(Color.BLUE);
    final TextSymbolizer symbol = SF.textSymbolizer(name, geometry, desc, unit, label, font, placement, halo, fill);
    final MutableStyle style = SF.style(DEFAULT_POLYGON_SYMBOLIZER, symbol);
    return style;
}
Also used : Fill(org.opengis.style.Fill) GraphicFill(org.opengis.style.GraphicFill) Description(org.opengis.style.Description) LabelPlacement(org.opengis.style.LabelPlacement) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression) TextSymbolizer(org.opengis.style.TextSymbolizer) Unit(javax.measure.Unit) Font(org.opengis.style.Font) Halo(org.opengis.style.Halo)

Example 7 with TextSymbolizer

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

the class GTtoSE100Transformer method visit.

/**
 * Transform a GT rule in jaxb rule or OnlineResource
 */
@Override
public org.geotoolkit.sld.xml.v100.Rule visit(final Rule rule, final Object data) {
    final org.geotoolkit.sld.xml.v100.Rule rt = sld_factory_v100.createRule();
    rt.setName(rule.getName());
    if (rule.getDescription() != null) {
        if (rule.getDescription().getAbstract() != null)
            rt.setAbstract(rule.getDescription().getAbstract().toString());
        if (rule.getDescription().getTitle() != null)
            rt.setTitle(rule.getDescription().getTitle().toString());
    }
    if (rule.isElseFilter()) {
        rt.setElseFilter(sld_factory_v100.createElseFilter());
    } 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) {
        // TODO provide jaxb parsing for unknowned symbolizers
        // 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) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) ExtensionSymbolizer(org.opengis.style.ExtensionSymbolizer) PointSymbolizer(org.opengis.style.PointSymbolizer) PolygonSymbolizer(org.opengis.style.PolygonSymbolizer) LineSymbolizer(org.opengis.style.LineSymbolizer) RasterSymbolizer(org.opengis.style.RasterSymbolizer) TextSymbolizer(org.opengis.style.TextSymbolizer) Symbolizer(org.opengis.style.Symbolizer)

Example 8 with TextSymbolizer

use of org.opengis.style.TextSymbolizer 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 9 with TextSymbolizer

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

the class SLD110Test method testUnitTranscription.

@Test
public void testUnitTranscription() {
    final SE110toGTTransformer se2gt = new SE110toGTTransformer(FILTER_FACTORY, STYLE_FACTORY);
    final GTtoSE110Transformer gt2se = new GTtoSE110Transformer();
    final TextSymbolizerType textSymbol = new TextSymbolizerType();
    final ParameterValueType labelType = new ParameterValueType();
    labelType.getContent().add("label");
    textSymbol.setLabel(labelType);
    textSymbol.setUom("km");
    TextSymbolizer transcriptedText = se2gt.visit(textSymbol);
    assertEquals("Converted unit of measure", Units.KILOMETRE, transcriptedText.getUnitOfMeasure());
    TextSymbolizerType revertedSymbol = gt2se.visit(transcriptedText, null).getValue();
    assertEquals("Reverted unit of measure", "km", revertedSymbol.getUom());
    textSymbol.setUom(null);
    transcriptedText = se2gt.visit(textSymbol);
    assertEquals("Converted unit of measure", Units.POINT, transcriptedText.getUnitOfMeasure());
    revertedSymbol = gt2se.visit(transcriptedText, null).getValue();
    assertEquals("Reverted unit of measure", "http://www.opengeospatial.org/se/units/pixel", revertedSymbol.getUom());
    textSymbol.setUom("px");
    transcriptedText = se2gt.visit(textSymbol);
    assertEquals("Converted unit of measure", Units.POINT, transcriptedText.getUnitOfMeasure());
    revertedSymbol = gt2se.visit(transcriptedText, null).getValue();
    assertEquals("Reverted unit of measure", "http://www.opengeospatial.org/se/units/pixel", revertedSymbol.getUom());
    textSymbol.setUom("meter");
    transcriptedText = se2gt.visit(textSymbol);
    assertEquals("Converted unit of measure", Units.METRE, transcriptedText.getUnitOfMeasure());
    revertedSymbol = gt2se.visit(transcriptedText, null).getValue();
    assertEquals("Reverted unit of measure", "http://www.opengeospatial.org/se/units/metre", revertedSymbol.getUom());
}
Also used : SE110toGTTransformer(org.geotoolkit.sld.xml.SE110toGTTransformer) TextSymbolizer(org.opengis.style.TextSymbolizer) TextSymbolizerType(org.geotoolkit.se.xml.v110.TextSymbolizerType) ParameterValueType(org.geotoolkit.se.xml.v110.ParameterValueType) GTtoSE110Transformer(org.geotoolkit.sld.xml.GTtoSE110Transformer) Test(org.junit.Test)

Example 10 with TextSymbolizer

use of org.opengis.style.TextSymbolizer 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)

Aggregations

TextSymbolizer (org.opengis.style.TextSymbolizer)14 LineSymbolizer (org.opengis.style.LineSymbolizer)7 PointSymbolizer (org.opengis.style.PointSymbolizer)6 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)6 MutableStyle (org.geotoolkit.style.MutableStyle)5 Expression (org.opengis.filter.Expression)5 RasterSymbolizer (org.opengis.style.RasterSymbolizer)5 Unit (javax.measure.Unit)4 Test (org.junit.Test)4 Description (org.opengis.style.Description)4 ExtensionSymbolizer (org.opengis.style.ExtensionSymbolizer)4 Fill (org.opengis.style.Fill)4 Font (org.opengis.style.Font)4 Halo (org.opengis.style.Halo)4 LabelPlacement (org.opengis.style.LabelPlacement)4 Symbolizer (org.opengis.style.Symbolizer)4 Color (java.awt.Color)2 JAXBElement (javax.xml.bind.JAXBElement)2 Marshaller (javax.xml.bind.Marshaller)2 Unmarshaller (javax.xml.bind.Unmarshaller)2