Search in sources :

Example 6 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class SE100toGTTransformer method visitUserStyle.

// Style, FTS and Rule-------------------------------------------------------
/**
 * Transform a SLD v1.0 userstyle in GT style.
 */
public MutableStyle visitUserStyle(final org.geotoolkit.sld.xml.v100.UserStyle us) {
    if (us == null) {
        return null;
    } else {
        final MutableStyle mls = styleFactory.style();
        mls.setName(us.getName());
        final InternationalString title = (us.getTitle() == null) ? null : new SimpleInternationalString(us.getTitle());
        final InternationalString abs = (us.getAbstract() == null) ? null : new SimpleInternationalString(us.getAbstract());
        mls.setDescription(styleFactory.description(title, abs));
        final Boolean def = us.isIsDefault();
        mls.setDefault((def != null) ? def : false);
        final List<org.geotoolkit.sld.xml.v100.FeatureTypeStyle> ftss = us.getFeatureTypeStyle();
        for (final org.geotoolkit.sld.xml.v100.FeatureTypeStyle obj : ftss) {
            final MutableFeatureTypeStyle fts = visitFTS(obj);
            mls.featureTypeStyles().add(fts);
        }
        return mls;
    }
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle)

Example 7 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class SE100toGTTransformer method visitFTS.

/**
 * Transform a SLD v1.0 FeatureTypeStyle or CoverageStyle in GT FTS.
 */
public MutableFeatureTypeStyle visitFTS(final org.geotoolkit.sld.xml.v100.FeatureTypeStyle obj) {
    if (obj == null)
        return null;
    final MutableFeatureTypeStyle fts = styleFactory.featureTypeStyle();
    final org.geotoolkit.sld.xml.v100.FeatureTypeStyle ftst = (org.geotoolkit.sld.xml.v100.FeatureTypeStyle) obj;
    fts.setName(ftst.getName());
    final InternationalString title = (ftst.getTitle() == null) ? null : new SimpleInternationalString(ftst.getTitle());
    final InternationalString abs = (ftst.getAbstract() == null) ? null : new SimpleInternationalString(ftst.getAbstract());
    fts.setDescription(styleFactory.description(title, abs));
    fts.semanticTypeIdentifiers().addAll(visitSemantics(ftst.getSemanticTypeIdentifier()));
    if (ftst.getFeatureTypeName() != null) {
        fts.featureTypeNames().add(NamesExt.create(ftst.getFeatureTypeName()));
    }
    if (ftst.getRule() == null || ftst.getRule().isEmpty()) {
    } else {
        for (org.geotoolkit.sld.xml.v100.Rule rt : ftst.getRule()) {
            fts.rules().add(visitRule(rt));
        }
    }
    return fts;
}
Also used : SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.SimpleInternationalString) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle)

Example 8 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class SE110toGTTransformer method visitUserStyle.

// Style, FTS and Rule-------------------------------------------------------
/**
 * Transform a SLD v1.1 userstyle in GT style.
 */
public MutableStyle visitUserStyle(final org.geotoolkit.sld.xml.v110.UserStyle us) throws FactoryException {
    if (us == null) {
        return null;
    } else {
        final MutableStyle mls = styleFactory.style();
        mls.setName(us.getName());
        mls.setDescription(visitDescription(us.getDescription()));
        final Boolean def = us.isIsDefault();
        mls.setDefault((def != null) ? def : false);
        final List<Object> ftss = us.getFeatureTypeStyleOrCoverageStyleOrOnlineResource();
        for (final Object obj : ftss) {
            MutableFeatureTypeStyle fts = visitFTS(obj);
            mls.featureTypeStyles().add(fts);
        }
        return mls;
    }
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle)

Example 9 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class CachedPatternSymbolizer method getMasks.

public Map.Entry<FeatureSet, MutableStyle> getMasks(final GridCoverage coverage) throws IOException, TransformException {
    final List<Feature> features = new ArrayList<>();
    final Map<NumberRange, List<Symbolizer>> styles = new LinkedHashMap<>();
    final Map<NumberRange, Integer> stylesIndexes = new LinkedHashMap<>();
    final Map<Expression, List<Symbolizer>> categorizes = styleElement.getRanges();
    final Expression[] steps = categorizes.keySet().toArray(new Expression[categorizes.size()]);
    Arrays.sort(steps, new Comparator<Expression>() {

        @Override
        public int compare(Expression t1, Expression t2) {
            if (t1 == null) {
                return -1;
            } else if (t2 == null) {
                return +1;
            }
            double d1 = ((Number) t1.apply(null)).doubleValue();
            double d2 = ((Number) t2.apply(null)).doubleValue();
            double res = d1 - d2;
            if (res < 0) {
                return -1;
            } else if (res > 0) {
                return +1;
            } else {
                return 0;
            }
        }
    });
    // fill the numberranges ------------------------------------------------
    double last = Double.NEGATIVE_INFINITY;
    double end = Double.POSITIVE_INFINITY;
    NumberRange interval;
    int i = 0;
    int index = 0;
    for (; i < steps.length - 1; i++) {
        end = ((Number) steps[i + 1].apply(null)).doubleValue();
        interval = NumberRange.create(last, true, end, false);
        styles.put(interval, categorizes.get(steps[i]));
        stylesIndexes.put(interval, index++);
        last = end;
    }
    // last element
    end = Double.POSITIVE_INFINITY;
    NumberRange<Double> lastRange = NumberRange.create(last, true, end, true);
    styles.put(lastRange, categorizes.get(steps[i]));
    stylesIndexes.put(lastRange, index++);
    // calculate the polygons -----------------------------------------------
    final ProcessDescriptor descriptor = CoverageToVectorDescriptor.INSTANCE;
    final Integer band = ((Number) styleElement.getChannel().apply(null)).intValue();
    final ParameterValueGroup input = descriptor.getInputDescriptor().createValue();
    input.parameter(CoverageToVectorDescriptor.COVERAGE.getName().getCode()).setValue(coverage);
    final Set<NumberRange> nrs = styles.keySet();
    input.parameter(CoverageToVectorDescriptor.RANGES.getName().getCode()).setValue(nrs.toArray(new NumberRange[nrs.size()]));
    input.parameter(CoverageToVectorDescriptor.BAND.getName().getCode()).setValue(band);
    final Process process = descriptor.createProcess(input);
    final Geometry[] polygons;
    try {
        polygons = (Geometry[]) process.call().parameter(CoverageToVectorDescriptor.GEOMETRIES.getName().getCode()).getValue();
    } catch (ProcessException ex) {
        Logger.getLogger("org.geotoolkit.display2d.ext.pattern").log(Level.WARNING, null, ex);
        throw new IOException(ex.getMessage(), ex);
    }
    // build the global style -----------------------------------------------
    final MutableStyle style = GO2Utilities.STYLE_FACTORY.style();
    final MutableFeatureTypeStyle fts = GO2Utilities.STYLE_FACTORY.featureTypeStyle();
    style.featureTypeStyles().add(fts);
    int idx = 0;
    for (List<Symbolizer> lst : styles.values()) {
        MutableRule rule = GO2Utilities.STYLE_FACTORY.rule();
        rule.symbolizers().addAll(lst);
        rule.setFilter(GO2Utilities.FILTER_FACTORY.equal(GO2Utilities.FILTER_FACTORY.property("category"), GO2Utilities.FILTER_FACTORY.literal(idx), true, MatchAction.ANY));
        fts.rules().add(rule);
        idx++;
    }
    // build the features ---------------------------------------------------
    final CoordinateReferenceSystem crs = coverage.getCoordinateReferenceSystem();
    final FeatureTypeBuilder sftBuilder = new FeatureTypeBuilder();
    final String geometryField = "geometry";
    sftBuilder.setName("DynamicFeature");
    sftBuilder.addAttribute(Integer.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
    sftBuilder.addAttribute(Geometry.class).setName(geometryField).setCRS(crs).addRole(AttributeRole.DEFAULT_GEOMETRY);
    sftBuilder.addAttribute(Integer.class).setName("category");
    final FeatureType sft = sftBuilder.build();
    int id = 0;
    for (Geometry entry : polygons) {
        if (entry == null)
            continue;
        NumberRange numberRange = (NumberRange) entry.getUserData();
        idx = stylesIndexes.get(numberRange);
        entry.setUserData(crs);
        final Feature feature = sft.newInstance();
        feature.setPropertyValue(geometryField, entry);
        feature.setPropertyValue("id", id++);
        feature.setPropertyValue("category", idx);
        features.add(feature);
    }
    return new AbstractMap.SimpleEntry<>(new InMemoryFeatureSet(sft, features), style);
}
Also used : FeatureType(org.opengis.feature.FeatureType) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ArrayList(java.util.ArrayList) Process(org.geotoolkit.process.Process) Feature(org.opengis.feature.Feature) LinkedHashMap(java.util.LinkedHashMap) MutableStyle(org.geotoolkit.style.MutableStyle) List(java.util.List) ArrayList(java.util.ArrayList) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) IOException(java.io.IOException) CachedSymbolizer(org.geotoolkit.display2d.style.CachedSymbolizer) Symbolizer(org.opengis.style.Symbolizer) NumberRange(org.apache.sis.measure.NumberRange) Geometry(org.locationtech.jts.geom.Geometry) MutableRule(org.geotoolkit.style.MutableRule) ProcessException(org.geotoolkit.process.ProcessException) Expression(org.opengis.filter.Expression) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) ProcessDescriptor(org.geotoolkit.process.ProcessDescriptor)

Example 10 with MutableFeatureTypeStyle

use of org.geotoolkit.style.MutableFeatureTypeStyle in project geotoolkit by Geomatys.

the class RenderingRoutines method mergeStyles.

/**
 * Merge a layer style with a selection style.
 * The selection style fts elements will be placed after those of the default style.
 */
public static MutableStyle mergeStyles(MutableStyle style, Filter selectionFilter, MutableStyle selectionStyle) {
    if (selectionFilter == null || Filter.exclude().equals(selectionFilter) || selectionStyle == null) {
        // unmodified
        return style;
    }
    final Filter exclusionFilter = FILTER_FACTORY.not(selectionFilter);
    final MutableStyle result = GO2Utilities.STYLE_FACTORY.style();
    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
        final MutableFeatureTypeStyle resultfts = GO2Utilities.STYLE_FACTORY.featureTypeStyle();
        resultfts.setDescription(fts.getDescription());
        resultfts.setFeatureInstanceIDs(fts.getFeatureInstanceIDs());
        resultfts.setName(fts.getName());
        resultfts.setOnlineResource(fts.getOnlineResource());
        result.featureTypeStyles().add(resultfts);
        for (Rule rule : fts.rules()) {
            final MutableRule modifiedRule = STYLE_FACTORY.rule(rule.symbolizers().toArray(new Symbolizer[0]));
            Filter f = rule.getFilter();
            if (f == null) {
                f = exclusionFilter;
            } else {
                f = FILTER_FACTORY.and(f, exclusionFilter);
            }
            modifiedRule.setFilter(f);
            resultfts.rules().add(modifiedRule);
        }
    }
    if (selectionStyle != null) {
        for (FeatureTypeStyle fts : selectionStyle.featureTypeStyles()) {
            final MutableFeatureTypeStyle resultfts = GO2Utilities.STYLE_FACTORY.featureTypeStyle();
            resultfts.setDescription(fts.getDescription());
            resultfts.setFeatureInstanceIDs(fts.getFeatureInstanceIDs());
            resultfts.setName(fts.getName());
            resultfts.setOnlineResource(fts.getOnlineResource());
            result.featureTypeStyles().add(resultfts);
            for (Rule rule : fts.rules()) {
                final MutableRule modifiedRule = STYLE_FACTORY.rule(rule.symbolizers().toArray(new Symbolizer[0]));
                Filter f = rule.getFilter();
                if (f == null) {
                    f = selectionFilter;
                } else {
                    f = FILTER_FACTORY.and(f, selectionFilter);
                }
                modifiedRule.setFilter(f);
                resultfts.rules().add(modifiedRule);
            }
        }
    }
    return result;
}
Also used : MutableRule(org.geotoolkit.style.MutableRule) MutableStyle(org.geotoolkit.style.MutableStyle) Filter(org.opengis.filter.Filter) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) FeatureTypeStyle(org.opengis.style.FeatureTypeStyle) Rule(org.opengis.style.Rule) MutableRule(org.geotoolkit.style.MutableRule) Symbolizer(org.opengis.style.Symbolizer)

Aggregations

MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)15 MutableStyle (org.geotoolkit.style.MutableStyle)9 MutableRule (org.geotoolkit.style.MutableRule)6 FeatureTypeStyle (org.opengis.style.FeatureTypeStyle)3 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 Marshaller (javax.xml.bind.Marshaller)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 SimpleInternationalString (org.apache.sis.util.SimpleInternationalString)2 CoverageStyleType (org.geotoolkit.se.xml.v110.CoverageStyleType)2 Test (org.junit.Test)2 Feature (org.opengis.feature.Feature)2 Rule (org.opengis.style.Rule)2 SemanticType (org.opengis.style.SemanticType)2 Symbolizer (org.opengis.style.Symbolizer)2 InternationalString (org.opengis.util.InternationalString)2 Color (java.awt.Color)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1