Search in sources :

Example 1 with Mapped

use of org.polymap.core.style.model.feature.MappedValues.Mapped in project polymap4-core by Polymap4.

the class NumberGradient2FilterEditor method initValues.

protected void initValues() {
    annotation = (NumberRange) prop.info().getAnnotation(NumberRange.class);
    df = NumberFormat.getInstance(Polymap.getSessionLocale());
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(0);
    List<Mapped<Filter, N>> values = prop.get().values();
    // defaults
    if (values.isEmpty()) {
        minimumValue = annotation.from();
        maximumValue = annotation.to();
        breakpoints = 10;
    } else // from prop
    {
        And first = (And) values.get(0).key();
        BinaryComparisonOperator lessThan = (BinaryComparisonOperator) first.getChildren().get(0);
        propertyName = ((PropertyName) lessThan.getExpression1()).getPropertyName();
        String value = (String) ((Literal) lessThan.getExpression2()).getValue();
        lowerBound = Double.parseDouble(value);
        And last = (And) values.get(values.size() - 1).key();
        BinaryComparisonOperator greaterThan = (BinaryComparisonOperator) last.getChildren().get(0);
        value = (String) ((Literal) greaterThan.getExpression2()).getValue();
        upperBound = Double.parseDouble(value);
        minimumValue = values.get(0).value().doubleValue();
        maximumValue = values.get(values.size() - 1).value().doubleValue();
        breakpoints = values.size() + 1;
    }
}
Also used : Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) And(org.opengis.filter.And) Literal(org.opengis.filter.expression.Literal) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator)

Example 2 with Mapped

use of org.polymap.core.style.model.feature.MappedValues.Mapped in project polymap4-core by Polymap4.

the class NumberGradient2MapScaleEditor method initValues.

protected void initValues() {
    // calculate map scale
    if (site().maxExtent.isPresent()) {
        try {
            ReferencedEnvelope maxExtent = site().maxExtent.get();
            Point mapSize = site().mapSize.get();
            maxScale = RendererUtilities.calculateScale(maxExtent, mapSize.x, mapSize.y, 120d);
            ReferencedEnvelope mapExtent = new ReferencedEnvelope(site().mapExtent.get(), maxExtent.getCoordinateReferenceSystem());
            mapScale = RendererUtilities.calculateScale(mapExtent, mapSize.x, mapSize.y, 120d);
            System.out.println("Scale: " + mapScale + " -- " + maxScale + " for maxExtent: " + maxExtent);
        } catch (TransformException | FactoryException e) {
            StatusDispatcher.handleError("Unable to calculate map scale.", e);
        }
    }
    annotation = (NumberRange) prop.info().getAnnotation(NumberRange.class);
    List<Mapped<ScaleRange, N>> values = prop.get().values();
    // defaults
    if (values.isEmpty()) {
        lowerBound = 5000;
        upperBound = maxScale != -1 ? (int) maxScale : 1000000;
        minimumValue = annotation.from();
        maximumValue = annotation.to();
        breakpoints = 5;
    } else // from prop
    {
        lowerBound = values.get(0).key().max.get();
        upperBound = values.get(values.size() - 1).key().min.get();
        minimumValue = values.get(0).value().doubleValue();
        maximumValue = values.get(values.size() - 1).value().doubleValue();
        // 3 intervals -> no extra breakpoint
        breakpoints = values.size() - 3;
    }
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) Point(org.eclipse.swt.graphics.Point)

Example 3 with Mapped

use of org.polymap.core.style.model.feature.MappedValues.Mapped in project polymap4-core by Polymap4.

the class ColorGradient2FilterEditor method initValues.

protected void initValues() {
    List<Mapped<Filter, java.awt.Color>> values = prop.get().values();
    df = NumberFormat.getInstance(Polymap.getSessionLocale());
    df.setMaximumFractionDigits(2);
    df.setMinimumFractionDigits(0);
    // defaults
    if (values.isEmpty()) {
        minimumValue = Color.LIGHT_GRAY;
        maximumValue = Color.BLACK;
        breakpoints = 10;
    } else // from prop
    {
        And first = (And) values.get(0).key();
        BinaryComparisonOperator lessThan = (BinaryComparisonOperator) first.getChildren().get(0);
        propertyName = ((PropertyName) lessThan.getExpression1()).getPropertyName();
        String value = (String) ((Literal) lessThan.getExpression2()).getValue();
        lowerBound = Double.parseDouble(value);
        And last = (And) values.get(values.size() - 1).key();
        BinaryComparisonOperator greaterThan = (BinaryComparisonOperator) last.getChildren().get(0);
        value = (String) ((Literal) greaterThan.getExpression2()).getValue();
        upperBound = Double.parseDouble(value);
        // minimumValue = values.get( 0 ).value().doubleValue();
        // maximumValue = values.get( values.size() - 1 ).value().doubleValue();
        breakpoints = values.size() + 1;
    }
}
Also used : Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) And(org.opengis.filter.And) Literal(org.opengis.filter.expression.Literal) BinaryComparisonOperator(org.opengis.filter.BinaryComparisonOperator)

Example 4 with Mapped

use of org.polymap.core.style.model.feature.MappedValues.Mapped in project polymap4-core by Polymap4.

the class StyleCompositeSerializer method handle.

protected <V> Iterable<RuleModifier<V, S>> handle(Property<StylePropertyValue<V>> prop) {
    StylePropertyValue<V> styleProp = prop.get();
    // no value -> nothing to modify
    if (styleProp == null || styleProp instanceof NoValue) {
        return singletonList(new NoValueRuleModifier());
    } else // ConstantValue
    if (styleProp instanceof ConstantValue) {
        Expression expr = ff.literal(((ConstantValue) styleProp).value());
        return singletonList(new SimpleRuleModifier(expr));
    } else // AttributeValue
    if (styleProp instanceof AttributeValue) {
        String attributeName = (String) ((AttributeValue) styleProp).attributeName.get();
        Expression expr = ff.property(attributeName);
        return singletonList(new SimpleRuleModifier(expr));
    } else // FilterMappedValues
    if (styleProp instanceof FilterMappedValues) {
        List<Mapped<Filter, Object>> values = ((FilterMappedValues) styleProp).values();
        return FluentIterable.from(values).transform(mapped -> new SimpleRuleModifier(ff.literal(mapped.value()), mapped.key()));
    } else // ScaleMappedValues
    if (styleProp instanceof ScaleMappedValues) {
        List<Mapped<ScaleRange, Object>> values = ((ScaleMappedValues) styleProp).values();
        return FluentIterable.from(values).transform(mapped -> new SimpleRuleModifier(ff.literal(mapped.value()), mapped.key().min.get(), mapped.key().max.get()));
    } else {
        throw new RuntimeException("Unhandled StylePropertyValue type: " + styleProp.getClass().getSimpleName());
    }
}
Also used : Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) Configurable(org.polymap.core.runtime.config.Configurable) StylePropertyValue(org.polymap.core.style.model.StylePropertyValue) ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter) Mandatory(org.polymap.core.runtime.config.Mandatory) StyleComposite(org.polymap.core.style.model.StyleComposite) Function(java.util.function.Function) StyleFactory(org.geotools.styling.StyleFactory) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Style(org.polymap.core.style.model.Style) ScaleMappedValues(org.polymap.core.style.model.feature.ScaleMappedValues) Config2(org.polymap.core.runtime.config.Config2) FluentIterable(com.google.common.collect.FluentIterable) FilterFactory2(org.opengis.filter.FilterFactory2) ConstantValue(org.polymap.core.style.model.feature.ConstantValue) FilterMappedValues(org.polymap.core.style.model.feature.FilterMappedValues) ScaleRange(org.polymap.core.style.model.feature.ScaleMappedValues.ScaleRange) Symbolizer(org.geotools.styling.Symbolizer) Cloner(com.rits.cloning.Cloner) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Property(org.polymap.model2.Property) Expression(org.opengis.filter.expression.Expression) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) List(java.util.List) NoValue(org.polymap.core.style.model.feature.NoValue) Rule(org.geotools.styling.Rule) AttributeValue(org.polymap.core.style.model.feature.AttributeValue) Filter(org.opengis.filter.Filter) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Context(org.polymap.core.style.serialize.FeatureStyleSerializer.Context) FilterStyleProperty(org.polymap.core.style.model.feature.FilterStyleProperty) AttributeValue(org.polymap.core.style.model.feature.AttributeValue) Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) ScaleMappedValues(org.polymap.core.style.model.feature.ScaleMappedValues) NoValue(org.polymap.core.style.model.feature.NoValue) Expression(org.opengis.filter.expression.Expression) ScaleRangeFilter(org.polymap.core.style.model.feature.ScaleRangeFilter) ConstantFilter(org.polymap.core.style.model.feature.ConstantFilter) Filter(org.opengis.filter.Filter) FilterMappedValues(org.polymap.core.style.model.feature.FilterMappedValues) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) List(java.util.List) ConstantValue(org.polymap.core.style.model.feature.ConstantValue)

Example 5 with Mapped

use of org.polymap.core.style.model.feature.MappedValues.Mapped in project polymap4-core by Polymap4.

the class ColorMap2FilterEditor method initValues.

protected void initValues() {
    List<Mapped<Filter, Color>> values = prop.get().values();
    for (Mapped<Filter, Color> entry : values) {
        PropertyIsEqualTo filter = (PropertyIsEqualTo) entry.key();
        propertyName = ((PropertyName) filter.getExpression1()).getPropertyName();
        Object value = ((Literal) filter.getExpression2()).getValue();
        colorMap.add(new Triple(value, -1, entry.value()));
    }
}
Also used : Mapped(org.polymap.core.style.model.feature.MappedValues.Mapped) PropertyIsEqualTo(org.opengis.filter.PropertyIsEqualTo) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Filter(org.opengis.filter.Filter) Color(java.awt.Color) Literal(org.opengis.filter.expression.Literal)

Aggregations

Mapped (org.polymap.core.style.model.feature.MappedValues.Mapped)5 Literal (org.opengis.filter.expression.Literal)3 And (org.opengis.filter.And)2 BinaryComparisonOperator (org.opengis.filter.BinaryComparisonOperator)2 Filter (org.opengis.filter.Filter)2 FluentIterable (com.google.common.collect.FluentIterable)1 Cloner (com.rits.cloning.Cloner)1 Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Function (java.util.function.Function)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Point (org.eclipse.swt.graphics.Point)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)1 Rule (org.geotools.styling.Rule)1 StyleFactory (org.geotools.styling.StyleFactory)1