Java Code Examples for org.opengis.filter.expression.Expression#evaluate()

The following examples show how to use org.opengis.filter.expression.Expression#evaluate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets a numeric value for the given graphic
 *
 * @param feature sample to be used for evals
 * @param pointSymbolizer symbolizer
 * @param defaultSize size to use is none can be taken from the graphic
 */
private double getGraphicSize(Feature feature, Graphic graphic, int defaultSize) {
    if (graphic != null) {
        Expression sizeExp = graphic.getSize();
        if (sizeExp instanceof Literal) {
            Object size = sizeExp.evaluate(feature);
            if (size != null) {
                if (size instanceof Double) {
                    return (Double) size;
                }
                try {
                    return Double.parseDouble(size.toString());
                } catch (NumberFormatException e) {
                    return defaultSize;
                }
            }
        }
    }
    return defaultSize;
}
 
Example 2
Source File: SLDEditorBufferedImageLegendGraphicBuilder.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets a numeric value for the given graphic
 *
 * @param feature sample to be used for evals
 * @param pointSymbolizer symbolizer
 * @param defaultSize size to use is none can be taken from the graphic
 */
private double getWidthSize(Feature feature, Expression widthExp, int defaultSize) {
    if (widthExp != null) {
        if (widthExp instanceof Literal) {
            Object size = widthExp.evaluate(feature);
            if (size != null) {
                if (size instanceof Double) {
                    return (Double) size;
                }
                try {
                    return Double.parseDouble(size.toString());
                } catch (NumberFormatException e) {
                    return defaultSize;
                }
            }
        }
    }
    return defaultSize;
}
 
Example 3
Source File: StyleUtilities.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get the offset from a {@link Symbolizer}.
 * 
 * @param symbolizer the symbolizer.
 * @return the offset.
 */
@SuppressWarnings("rawtypes")
public static Point2D getOffset( Symbolizer symbolizer ) {
    Expression geometry = symbolizer.getGeometry();
    if (geometry != null) {
        if (geometry instanceof FilterFunction_offset) {
            FilterFunction_offset offsetFunction = (FilterFunction_offset) geometry;
            List parameters = offsetFunction.getParameters();
            Expression xOffsetExpr = (Expression) parameters.get(1);
            Expression yOffsetExpr = (Expression) parameters.get(2);
            Double xOffsetDouble = xOffsetExpr.evaluate(null, Double.class);
            Double yOffsetDouble = yOffsetExpr.evaluate(null, Double.class);
            if (xOffsetDouble != null && yOffsetDouble != null) {
                Point2D.Double point = new Point2D.Double(xOffsetDouble, yOffsetDouble);
                return point;
            }
        }
    }
    return null;
}
 
Example 4
Source File: FeatureLayer.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void visit(TextSymbolizer text) {
    super.visit(text);
    TextSymbolizer textCopy = (TextSymbolizer) pages.peek();
    Fill textFill = textCopy.getFill();
    if (textFill != null) {
        Expression opacityExpression = textFill.getOpacity();
        if (opacityExpression != null) {
            textOpacity = opacityExpression.evaluate(opacityExpression, Double.class);
        }
    }
}
 
Example 5
Source File: VectorLayerFactory.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void visit(Expression expression) {
	if (expression instanceof Function) {
		Function f = (Function) expression;
		for (Expression param : f.getParameters()) {
			Object keyValue = param.evaluate(null);
			if (keyValue instanceof Map) {
				Object bf = ((Map) keyValue).get(BUFFER_SIZE);
				if (bf != null) {
					preRenderBuffer = Integer.parseInt(bf.toString());
				}
			}
		}
	}
}
 
Example 6
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Writes the FilterBuilder for the PropertyIsBetween Filter.
 *
 * @param filter the Filter to be visited.
 *
 */
public Object visit(PropertyIsBetween filter, Object extraData) {
    LOGGER.finest("exporting PropertyIsBetween");

    Expression expr = filter.getExpression();
    Expression lowerbounds = filter.getLowerBoundary();
    Expression upperbounds = filter.getUpperBoundary();

    Class<?> context;
    nested = false;
    AttributeDescriptor attType = (AttributeDescriptor)expr.evaluate(featureType);
    if (attType != null) {
        context = attType.getType().getBinding();
        if (attType.getUserData().containsKey(NESTED)) {
            nested = (Boolean) attType.getUserData().get(NESTED);
        }
        if (Date.class.isAssignableFrom(context)) {
            updateDateFormatter(attType);
        }
    } else {
        //assume it's a string?
        context = String.class;
    }

    expr.accept(this, extraData);
    key = (String) field;
    lowerbounds.accept(this, context);
    lower = field;
    upperbounds.accept(this, context);
    Object upper = field;

    if(nested) {
        path = extractNestedPath(key);
    }

    queryBuilder = ImmutableMap.of("range", ImmutableMap.of(key, ImmutableMap.of("gte", lower, "lte", upper)));
    if(nested) {
        queryBuilder = ImmutableMap.of("nested", ImmutableMap.of("path", path, "query", queryBuilder));
    }

    return extraData;
}
 
Example 7
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Writes the FilterBuilder for the Like Filter.
 *
 * @param filter the filter to be visited
 *
 */
public Object visit(PropertyIsLike filter, Object extraData) {
    char esc = filter.getEscape().charAt(0);
    char multi = filter.getWildCard().charAt(0);
    char single = filter.getSingleChar().charAt(0);
    if (filter.isMatchingCase()) {
        LOGGER.fine("Case sensitive search not supported");
    }

    String literal = filter.getLiteral();
    Expression att = filter.getExpression();

    AttributeDescriptor attType = (AttributeDescriptor) att.evaluate(featureType);
    Boolean analyzed = false;
    nested = false;
    if (attType != null) {
        if (attType.getUserData().containsKey(ANALYZED)) {
            analyzed = (Boolean) attType.getUserData().get(ANALYZED);
        }
        if (attType.getUserData().containsKey(NESTED)) {
            nested = (Boolean) attType.getUserData().get(NESTED);
        }
        if (Date.class.isAssignableFrom(attType.getType().getBinding())) {
            updateDateFormatter(attType);
        }
    }

    att.accept(this, extraData);
    key = (String) field;

    String pattern;
    if (analyzed) {
        // use query string query post filter for analyzed fields
        pattern = convertToQueryString(esc, multi, single, literal);
    } else {
        // default to regexp filter
        pattern = convertToRegex(esc, multi, single, literal);
    }
    if (nested) {
        path = extractNestedPath(key);
    }

    if (analyzed) {
        // use query string query for analyzed fields
        queryBuilder = ImmutableMap.of("query_string", ImmutableMap.of("query", pattern, "default_field", key));
    } else {
        // default to regexp query
        queryBuilder = ImmutableMap.of("regexp", ImmutableMap.of(key, pattern));
    }
    if (nested) {
        queryBuilder = ImmutableMap.of("nested", ImmutableMap.of("path", path, "query", queryBuilder));
    }

    return extraData;
}
 
Example 8
Source File: OmsVectorReshaper.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * You cannot call this once the dialog is closed, see the okPressed method.
 * @param originalFeatureType 
 * @param expressions 
 * @param names 
 * @return a SimpleFeatureType created based on the contents of Text
 */
private SimpleFeatureType createFeatureType( String expressionString, SimpleFeatureType originalFeatureType,
        List<String> names, List<Expression> expressions ) throws SchemaException {

    SimpleFeatureTypeBuilder build = new SimpleFeatureTypeBuilder();

    for( int i = 0; i < names.size(); i++ ) {
        String name = names.get(i);

        Expression expression = expressions.get(i);

        Object value = expression.evaluate(sample);

        // hack because sometimes expression returns null. I think the real bug is with
        // AttributeExpression
        Class< ? > binding = null;
        if (value == null) {
            if (expression instanceof PropertyName) {
                String path = ((PropertyName) expression).getPropertyName();
                AttributeType attributeType = sample.getFeatureType().getType(path);
                if (attributeType == null) {
                    throw new ModelsIllegalargumentException("Attribute type is null", this.getClass().getSimpleName(), pm);
                }
                binding = attributeType.getClass();
            }
        } else {
            binding = value.getClass();
        }

        if (binding == null) {
            throw new ModelsIllegalargumentException("Binding is null", this.getClass().getSimpleName(), pm);
        }

        if (Geometry.class.isAssignableFrom(binding)) {
            CoordinateReferenceSystem crs;
            AttributeType originalAttributeType = originalFeatureType.getType(name);
            if (originalAttributeType instanceof GeometryType) {
                crs = ((GeometryType) originalAttributeType).getCoordinateReferenceSystem();
            } else {
                crs = originalFeatureType.getCoordinateReferenceSystem();
            }
            build.crs(crs);

            build.add(name, binding);
        } else {
            build.add(name, binding);
        }
    }
    build.setName(getNewTypeName(originalFeatureType.getTypeName()));

    return build.buildFeatureType();
}
 
Example 9
Source File: PointSymbolizerWrapper.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public PointSymbolizerWrapper( Symbolizer symbolizer, RuleWrapper parent ) {
    super(symbolizer, parent);

    PointSymbolizer pointSymbolizer = (PointSymbolizer) symbolizer;
    graphic = pointSymbolizer.getGraphic();
    List<ExternalGraphic> externalGraphicsList = externalGraphicsFromGraphic(graphic);

    // size
    Expression sizeExpr = graphic.getSize();
    String tmp = expressionToString(sizeExpr);
    if (tmp != null) {
        size = tmp;
    } else {
        size = DEFAULT_WIDTH;
    }
    // rotation
    Expression rotationExpr = graphic.getRotation();
    tmp = expressionToString(rotationExpr);
    if (tmp != null) {
        rotation = tmp;
    } else {
        rotation = DEFAULT_ROTATION;
    }
    // offset
    Point2D offset = StyleUtilities.getOffset(pointSymbolizer);
    if (offset != null) {
        xOffset = String.valueOf(offset.getX());
        yOffset = String.valueOf(offset.getY());
    } else {
        xOffset = DEFAULT_OFFSET;
        yOffset = DEFAULT_OFFSET;
    }

    if (externalGraphicsList.size() == 0) {
        mark = SLD.mark(pointSymbolizer);
        if (mark == null) {
            return;
        }
        markName = mark.getWellKnownName().evaluate(null, String.class);
        if (markName == null || markName.equals("")) { //$NON-NLS-1$
            markName = "circle"; //$NON-NLS-1$
            mark.setWellKnownName(ff.literal(markName));
        }

        fill = mark.getFill();
        if (fill != null) {
            fillColor = fill.getColor().evaluate(null, String.class);
            Expression opacityExpr = fill.getOpacity();
            fillOpacity = expressionToString(opacityExpr);
            hasFill = true;
        } else {
            hasFill = false;
        }

        stroke = mark.getStroke();
        if (stroke != null) {
            Expression color = stroke.getColor();
            tmp = color.evaluate(null, String.class);
            if (tmp != null) {
                strokeColor = tmp;
            } else {
                strokeColor = DEFAULT_COLOR;
            }

            Expression opacity = stroke.getOpacity();
            tmp = expressionToString(opacity);
            if (tmp != null) {
                strokeOpacity = tmp;
            } else {
                strokeOpacity = DEFAULT_OPACITY;
            }

            Expression width = stroke.getWidth();
            tmp = expressionToString(width);
            if (tmp != null) {
                strokeWidth = tmp;
            } else {
                strokeWidth = DEFAULT_WIDTH;
            }
            hasStroke = true;
        } else {
            hasStroke = false;
        }
    } else {
        // graphics case
        externalGraphic = externalGraphicsList.get(0);
    }
}