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

org.geotools.styling.AbstractSymbolizer 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) 2019, 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;

import java.util.LinkedHashMap;
import java.util.Map;
import javax.measure.Unit;
import javax.measure.quantity.Length;
import org.geotools.factory.CommonFactoryFinder;
import org.opengis.filter.expression.Expression;
import org.opengis.filter.expression.PropertyName;

public abstract class AbstractSymbolizer implements Symbolizer {
    protected String name;

    protected Description description;

    protected Expression geometry;

    protected Unit unitOfMeasure;

    protected Map options;

    protected AbstractSymbolizer() {}

    public AbstractSymbolizer(
            String name, Description description, Expression geometry, Unit unitOfMeasure) {
        this.name = name;
        this.description = description;
        this.geometry = geometry;
        this.unitOfMeasure = unitOfMeasure;
    }

    public AbstractSymbolizer(
            String name,
            Description description,
            String geometryPropertyName,
            Unit unitOfMeasure) {
        this.name = name;
        this.description = description;
        this.unitOfMeasure = unitOfMeasure;
        setGeometryPropertyName(geometryPropertyName);
    }

    public Description getDescription() {
        return description;
    }

    public void setDescription(org.opengis.style.Description description) {
        this.description = DescriptionImpl.cast(description);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setUnitOfMeasure(Unit uom) {
        this.unitOfMeasure = uom;
    }

    public Unit getUnitOfMeasure() {
        return unitOfMeasure;
    }

    public Expression getGeometry() {
        return geometry;
    }

    public void setGeometry(Expression geometry) {
        this.geometry = geometry;
    }

    public String getGeometryPropertyName() {
        if (geometry instanceof PropertyName) {
            PropertyName pg = (PropertyName) geometry;
            return pg.getPropertyName();
        }
        return null;
    }

    public void setGeometryPropertyName(String geometryPropertyName) {
        if (geometryPropertyName == null) {
            geometry = null;
        } else {
            org.opengis.filter.FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
            geometry = ff.property(geometryPropertyName);
        }
    }

    public boolean hasOption(String key) {
        return options != null && options.containsKey(key);
    }

    public Map getOptions() {
        if (options == null) {
            options = new LinkedHashMap();
        }
        return options;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((description == null) ? 0 : description.hashCode());
        result = prime * result + ((geometry == null) ? 0 : geometry.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((unitOfMeasure == null) ? 0 : unitOfMeasure.hashCode());
        result = prime * result + ((options == null) ? 0 : options.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        AbstractSymbolizer other = (AbstractSymbolizer) obj;
        if (description == null) {
            if (other.description != null) return false;
        } else if (!description.equals(other.description)) return false;
        if (geometry == null) {
            if (other.geometry != null) return false;
        } else if (!geometry.equals(other.geometry)) return false;
        if (name == null) {
            if (other.name != null) return false;
        } else if (!name.equals(other.name)) return false;
        if (unitOfMeasure == null) {
            if (other.unitOfMeasure != null) return false;
        } else if (!unitOfMeasure.equals(other.unitOfMeasure)) return false;
        if (options == null) {
            if (other.options != null && !other.options.isEmpty()) return false;
        }
        if (options == null || options.isEmpty()) {
            // this options are NULL or empty
            if (other.options != null && !other.options.isEmpty()) {
                // the other options are neither NULL or empty
                return false;
            }
        } else if (!options.equals(other.options)) {
            // options are not considered the same
            return false;
        }
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy