All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geotools.styling.visitor.DpiRescaleStyleVisitor Maven / Gradle / Ivy

Go to download

The main module contains the GeoTools public interfaces that are used by other GeoTools modules (and GeoTools applications). Where possible we make use industry standard terms as provided by OGC and ISO standards. The formal GeoTools public api consists of gt-metadata, jts and the gt-main module. The main module contains the default implementations that are available provided to other GeoTools modules using our factory system. Factories are obtained from an appropriate FactoryFinder, giving applications a chance configure the factory used using the Factory Hints facilities. FilterFactory ff = CommonFactoryFinder.getFilterFactory(); Expression expr = ff.add( expression1, expression2 ); If you find yourself using implementation specific classes chances are you doing it wrong: Expression expr = new AddImpl( expression1, expressiom2 );

The newest version!
/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2002-2015, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */
package org.geotools.styling.visitor;

import java.util.Map;
import org.opengis.filter.FilterFactory2;
import org.opengis.filter.expression.Expression;

/**
 * This is a style visitor that will produce a copy of the provided style. The copy will be rescaled
 * by a provided factor if UOM is PIXEL.
 */
public class DpiRescaleStyleVisitor extends RescaleStyleVisitor {

    public DpiRescaleStyleVisitor(double scale) {
        super(scale);
    }

    public DpiRescaleStyleVisitor(FilterFactory2 filterFactory, double scale) {
        super(filterFactory, scale);
    }

    @Override
    protected Expression rescale(Expression expr) {
        // handle null values
        if (expr == null) {
            return null;
        }
        if (expr == Expression.NIL) {
            return Expression.NIL;
        }

        // delegate the handling of the rescaling to ValueAndUnit
        // to deal with local uom (px, m, ft suffixes)
        Measure v = new Measure(expr, defaultUnit);
        return RescalingMode.Pixels.rescaleToExpression(scale, v);
    }

    @Override
    protected void rescaleOption(Map options, String key, double defaultValue) {
        double scaleFactor = (double) scale.evaluate(null, Double.class);
        String value = options.get(key);
        if (value == null) {
            value = String.valueOf(defaultValue);
        }

        Measure v = new Measure(value, defaultUnit);
        String rescaled = RescalingMode.Pixels.rescaleToString(scaleFactor, v);
        options.put(key, String.valueOf(rescaled));
    }

    @Override
    protected void rescaleOption(Map options, String key, int defaultValue) {
        double scaleFactor = (double) scale.evaluate(null, Double.class);
        String value = options.get(key);
        if (value == null) {
            value = String.valueOf(defaultValue);
        }

        Measure v = new Measure(value, defaultUnit);
        String rescaled = RescalingMode.Pixels.rescaleToString(scaleFactor, v);
        options.put(key, String.valueOf(rescaled));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy