org.opengis.filter.expression.Literal Java Examples

The following examples show how to use org.opengis.filter.expression.Literal. 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 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 #2
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
private void visitLiteralGeometry(Literal expression) throws IOException {
    // evaluate the literal and store it for later
    currentGeometry  = (Geometry) evaluateLiteral(expression, Geometry.class);

    if ( currentGeometry instanceof LinearRing ) {
        // convert LinearRing to LineString
        final GeometryFactory factory = currentGeometry.getFactory();
        final LinearRing linearRing = (LinearRing) currentGeometry;
        final CoordinateSequence coordinates;
        coordinates = linearRing.getCoordinateSequence();
        currentGeometry = factory.createLineString(coordinates);
    }

    final String geoJson = new GeometryJSON().toString(currentGeometry);
    currentShapeBuilder = mapReader.readValue(geoJson);
}
 
Example #3
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
private Object visitBinaryTemporalOperator(BinaryTemporalOperator filter,
                                           Object extraData) {
    if (filter == null) {
        throw new NullPointerException("Null filter");
    }

    Expression e1 = filter.getExpression1();
    Expression e2 = filter.getExpression2();

    if (e1 instanceof Literal && e2 instanceof PropertyName) {
        e1 = filter.getExpression2();
        e2 = filter.getExpression1();
    }

    if (e1 instanceof PropertyName && e2 instanceof Literal) {
        //call the "regular" method
        return visitBinaryTemporalOperator(filter, (PropertyName)e1, (Literal)e2, 
                filter.getExpression1() instanceof Literal, extraData);
    }
    else {
        //call the join version
        return visitBinaryTemporalOperator();
    }
}
 
Example #4
Source File: FunctionManager.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates the expression.
 *
 * @param functionName the function name
 * @param argumentList the argument list
 * @return the expression
 */
/*
 * (non-Javadoc)
 *
 * @see
 * com.sldeditor.filter.v2.function.FunctionNameInterface#createExpression(org.opengis.filter.
 * capability.FunctionName, java.util.List)
 */
@Override
public Expression createExpression(FunctionName functionName, List<Expression> argumentList) {
    if (functionName == null) {
        return null;
    }

    Literal fallback = null;
    return functionFactory.function(functionName.getFunctionName(), argumentList, fallback);
}
 
Example #5
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 #6
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
private void visitDistanceSpatialOperator(DistanceBufferOperator filter,
                                          PropertyName property, Literal geometry, boolean swapped,
                                          Object extraData) {

    property.accept(delegate, extraData);
    key = (String) delegate.field;
    geometry.accept(delegate, extraData);
    final Geometry geo = delegate.currentGeometry;
    double lat = geo.getCentroid().getY();
    double lon = geo.getCentroid().getX();
    final double inputDistance = filter.getDistance();
    final String inputUnits = filter.getDistanceUnits();
    double distance = Double.valueOf(toMeters(inputDistance, inputUnits));

    delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL,
            "filter", ImmutableMap.of("geo_distance", 
                    ImmutableMap.of("distance", distance +"m", key, ImmutableList.of(lon, lat)))));

    if ((filter instanceof DWithin && swapped)
            || (filter instanceof Beyond && !swapped)) {
        delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must_not", delegate.queryBuilder));
    }
}
 
Example #7
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
private void visitComparisonSpatialOperator(BinarySpatialOperator filter, PropertyName property, Literal geometry,
                                            boolean swapped, Object extraData) {

    // if geography case, sanitize geometry first
    Literal geometry1 = clipToWorld(geometry);

    //noinspection RedundantCast
    visitBinarySpatialOperator(filter, (Expression)property, (Expression) geometry1, swapped, extraData);

    // if geography case, sanitize geometry first
    if(isWorld(geometry1)) {
        // nothing to filter in this case
        delegate.queryBuilder = MATCH_ALL;
        return;
    } else if(isEmpty(geometry1)) {
        if(!(filter instanceof Disjoint)) {
            delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must_not", MATCH_ALL));
        } else {
            delegate.queryBuilder = MATCH_ALL;
        }
        return;
    }

    //noinspection RedundantCast
    visitBinarySpatialOperator(filter, (Expression)property, (Expression) geometry1, swapped, extraData);
}
 
Example #8
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns true if the geometry is fully empty
 * @param geometry Geometry
 * @return Flag indicating whether geometry is empty
 */
private boolean isEmpty(Literal geometry) {
    boolean result = false;
    if(geometry != null) {
        Geometry g = geometry.evaluate(null, Geometry.class);
        result = g == null || g.isEmpty();
    }
    return result;
}
 
Example #9
Source File: CriteriaVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Get the literal value for an expression.
 * 
 * @param expression expression
 * @return literal value
 */
private Object getLiteralValue(Expression expression) {
	if (!(expression instanceof Literal)) {
		throw new IllegalArgumentException("Expression " + expression + " is not a Literal.");
	}
	return ((Literal) expression).getValue();
}
 
Example #10
Source File: ExtractGeometryFilterVisitor.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * Please note we are only visiting literals involved in spatial operations.
 *
 * @param expression hopefully a Geometry or Envelope
 * @param data Incoming BoundingBox (or Envelope or CRS)
 * @return ReferencedEnvelope updated to reflect literal
 */
@Override
public Object visit(final Literal expression, final Object data) {
  final Object value = expression.getValue();
  if (value instanceof Geometry) {
    final Geometry geometry = (Geometry) value;
    return geometry;
  } else {
    LOGGER.info("LiteralExpression ignored!");
  }
  return bbox(data);
}
 
Example #11
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Export the contents of a Literal Expresion
 *
 * @param expression
 * the Literal to export
 *
 * @throws FilterToElasticException If there were io problems.
 */
@Override
public Object visit(Literal expression, Object context)
        throws FilterToElasticException {
    LOGGER.finest("exporting LiteralExpression");

    // type to convert the literal to
    Class<?> target = null;
    if ( context instanceof Class ) {
        target = (Class<?>) context;
    }

    try {
        //evaluate the expression
        Object literal = evaluateLiteral( expression, target );

        // handle geometry case
        if (literal instanceof Geometry) {
            // call this method for backwards compatibility with subclasses
            visitLiteralGeometry(filterFactory.literal(literal));
        }
        else {
            // write out the literal allowing subclasses to override this
            // behaviour (for writing out dates and the like using the BDMS custom functions)
            writeLiteral(literal);
        }
    } catch (IOException e) {
        throw new FilterToElasticException("IO problems writing literal", e);
    }
    return context;
}
 
Example #12
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
private Object visitBinarySpatialOperator(BinarySpatialOperator filter,
                                          Object extraData) {
    // basic checks
    if (filter == null)
        throw new NullPointerException(
                "Filter to be encoded cannot be null");

    // extract the property name and the geometry literal
    Expression e1 = filter.getExpression1();
    Expression e2 = filter.getExpression2();

    if (e1 instanceof Literal && e2 instanceof PropertyName) {
        e1 = filter.getExpression2();
        e2 = filter.getExpression1();
    }

    if (e1 instanceof PropertyName && e2 instanceof Literal) {
        //call the "regular" method
        return visitBinarySpatialOperator(filter, (PropertyName)e1, (Literal)e2, filter
                .getExpression1() instanceof Literal, extraData);
    }
    else {
        //call the join version
        return visitBinarySpatialOperator(filter, e1, e2, extraData);
    }

}
 
Example #13
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns true if the geometry covers the entire world
 * @param geometry Geometry
 * @return Flag indicating geometry is the world
 */
private boolean isWorld(Literal geometry) {
    boolean result = false;
    if(geometry != null) {
        Geometry g = geometry.evaluate(null, Geometry.class);
        if(g != null) {
            result = JTS.toGeometry(WORLD).equalsTopo(g.union());
        }
    }
    return result;
}
 
Example #14
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
Object visitBinarySpatialOperator(BinarySpatialOperator filter,
                                  PropertyName property, Literal geometry, boolean swapped,
                                  Object extraData) {

    if (filter instanceof DistanceBufferOperator) {
        visitDistanceSpatialOperator((DistanceBufferOperator) filter,
                property, geometry, swapped, extraData);
    } else {
        visitComparisonSpatialOperator(filter, property, geometry,
                swapped, extraData);
    }
    return extraData;
}
 
Example #15
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
private Literal clipToWorld(Literal geometry) {
    if(geometry != null) {
        Geometry g = geometry.evaluate(null, Geometry.class);
        if(g != null) {
            g.apply((GeometryComponentFilter) geom -> geom.apply((CoordinateFilter) coord -> {
                coord.setCoordinate(new Coordinate(clipLon(coord.x), clipLat(coord.y)));
            }));
            geometry = CommonFactoryFinder.getFilterFactory(null).literal(g);

        }
    }

    return geometry;
}
 
Example #16
Source File: FunctionManager.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the expression.
 *
 * @param functionName the function name
 * @return the expression
 */
@Override
public Expression createExpression(FunctionName functionName) {
    if (functionName == null) {
        return null;
    }

    List<Expression> parameters = new ArrayList<>();
    Literal fallback = null;

    FunctionExpressionInterface.createNewFunction(functionName, parameters);

    return functionFactory.function(functionName.getFunctionName(), parameters, fallback);
}
 
Example #17
Source File: FilterManager.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the expression.
 *
 * @param functionName the function name
 * @return the expression
 */
@Override
public Expression createExpression(FunctionName functionName) {
    if (functionName == null) {
        return null;
    }

    List<Expression> parameters = null;
    Literal fallback = null;
    return functionFactory.function(functionName.getFunctionName(), parameters, fallback);
}
 
Example #18
Source File: SymbolTypeFactory.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the solid fill.
 *
 * @param fieldConfigManager the field config manager
 * @param expFillColour the exp fill colour
 * @param expFillColourOpacity the exp fill colour opacity
 */
public void setSolidFill(
        GraphicPanelFieldManager fieldConfigManager,
        Expression expFillColour,
        Expression expFillColourOpacity) {
    if (symbolTypeField != null) {
        FieldConfigBase field = fieldConfigManager.get(this.selectionComboBox);
        Literal expression = ff.literal(solidFileValue);
        field.populate(expression);

        markerField.setSolidFill(fieldConfigManager, expFillColour, expFillColourOpacity);
    }
}
 
Example #19
Source File: RasterReader.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the rgb image symbol.
 *
 * @param sym the sym
 * @param cov the cov
 * @param raster the raster
 */
private void createRGBImageSymbol(
        RasterSymbolizer sym, GridCoverage2D cov, WritableRaster raster) {
    double dest;
    List<Double> valueList = new ArrayList<>();

    GridEnvelope2D gridRange2D = cov.getGridGeometry().getGridRange2D();
    for (int x = 0; x < gridRange2D.getWidth(); x++) {
        for (int y = 0; y < gridRange2D.getHeight(); y++) {
            try {
                dest = raster.getSampleDouble(x, y, 0);

                if (!valueList.contains(dest)) {
                    valueList.add(dest);
                }
            } catch (Exception e) {
                ConsoleManager.getInstance().exception(this, e);
            }
        }
    }

    ColorMapImpl colourMap = new ColorMapImpl();

    // Sort the unique sample values in ascending order
    Collections.sort(valueList);

    // Create colour amp entries in the colour map for all the sample values
    for (Double value : valueList) {
        ColorMapEntry entry = new ColorMapEntryImpl();
        Literal colourExpression =
                ff.literal(ColourUtils.fromColour(ColourUtils.createRandomColour()));
        entry.setColor(colourExpression);
        entry.setQuantity(ff.literal(value.doubleValue()));

        colourMap.addColorMapEntry(entry);
    }

    colourMap.setType(ColorMap.TYPE_VALUES);
    sym.setColorMap(colourMap);
}
 
Example #20
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Filter createOverlapsFilter(Geometry geometry, String geomName) {
	Expression nameExpression = FF.property(geomName);
	Literal geomLiteral = FF.literal(geometry);
	return FF.overlaps(nameExpression, geomLiteral);
}
 
Example #21
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Filter createTouchesFilter(Geometry geometry, String geomName) {
	Expression nameExpression = FF.property(geomName);
	Literal geomLiteral = FF.literal(geometry);
	return FF.touches(nameExpression, geomLiteral);
}
 
Example #22
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Filter createIntersectsFilter(Geometry geometry, String geomName) {
	Expression nameExpression = FF.property(geomName);
	Literal geomLiteral = FF.literal(geometry);
	return FF.intersects(nameExpression, geomLiteral);
}
 
Example #23
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Filter createWithinFilter(Geometry geometry, String geomName) {
	Expression nameExpression = FF.property(geomName);
	Literal geomLiteral = FF.literal(geometry);
	return FF.within(nameExpression, geomLiteral);
}
 
Example #24
Source File: FilterServiceImpl.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Filter createContainsFilter(Geometry geometry, String geomName) {
	Expression nameExpression = FF.property(geomName);
	Literal geomLiteral = FF.literal(geometry);
	return FF.contains(nameExpression, geomLiteral);
}
 
Example #25
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
private Object visitBinarySpatialOperator(BinarySpatialOperator filter,
                                          PropertyName property, Literal geometry, boolean swapped,
                                          Object extraData) {
    return helper.visitBinarySpatialOperator(filter, property, geometry,
            swapped, extraData);
}
 
Example #26
Source File: FieldConfigFontPreview.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Populate field.
 *
 * @param font the font
 */
@Override
public void populateField(Font font) {
    if ((textField != null) && (font != null)) {
        if (font.getFamily().isEmpty()) {
            textField.setText("");
        } else if ((font.getStyle() == null)
                || (font.getWeight() == null)
                || (font.getSize() == null)) {
            textField.setText("");
        } else {
            textField.setText(SAMPLE_TEXT);

            int styleIndex = 0;
            int weightIndex = 0;
            String familyName = font.getFamily().get(0).toString();
            String styleName = ((Literal) font.getStyle()).getValue().toString();
            for (int index = 0; index < styles.length; index++) {
                if (styles[index].equalsIgnoreCase(styleName)) {
                    styleIndex = index;
                    break;
                }
            }

            String weightName = ((Literal) font.getWeight()).getValue().toString();
            for (int index = 0; index < weights.length; index++) {
                if (weights[index].equalsIgnoreCase(weightName)) {
                    weightIndex = index;
                    break;
                }
            }

            StringBuilder sb = new StringBuilder(familyName);
            if (weightIndex == 0) {
                if (styleIndex == 0) {
                    sb.append("-PLAIN-");
                } else {
                    sb.append("-ITALIC-");
                }
            } else {
                if (styleIndex == 0) {
                    sb.append("-BOLD-");
                } else {
                    sb.append("-BOLDITALIC-");
                }
            }

            // Get font size
            int size = 12;
            if (font.getSize() instanceof Literal) {
                Literal sizeExpression = (Literal) font.getSize();
                Object obj = sizeExpression.getValue();
                if (obj instanceof Number) {
                    Number number = (Number) obj;
                    size = number.intValue();
                } else if (obj instanceof String) {
                    size = Double.valueOf((String) obj).intValue();
                }
            }
            sb.append(size);

            java.awt.Font sampleFont = java.awt.Font.decode(sb.toString());

            textField.setFont(sampleFont);
        }
    }
}
 
Example #27
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
private Object evaluateLiteral(Literal expression, Class<?> target) {
    Object literal = null;

    // HACK: let expression figure out the right value for numbers,
    // since the context is almost always improperly set and the
    // numeric converters try to force floating points to integrals
    // JD: the above is no longer true, so instead do a safe conversion
    if(target != null) {
        // use the target type
        if (Number.class.isAssignableFrom(target)) {
            literal = safeConvertToNumber(expression, target);

            if (literal == null) {
                literal = safeConvertToNumber(expression, Number.class);
            }
        }
        else {
            literal = expression.evaluate(null, target);
        }
    }

    //check for conversion to number
    if (target == null) {
        // we don't know the target type, check for a conversion to a number

        Number number = safeConvertToNumber(expression, Number.class);
        if (number != null) {
            literal = number;
        }
    }

    // if the target was not known, of the conversion failed, try the
    // type guessing dance literal expression does only for the following
    // method call
    if(literal == null)
        literal = expression.evaluate(null);

    // if that failed as well, grab the value as is
    if(literal == null)
        literal = expression.getValue();

    return literal;
}
 
Example #28
Source File: VOGeoServerTextSymbolizer2Test.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSymbolizer2#VOGeoServerTextSymbolizer2(java.lang.Class,
 * com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testVOGeoServerTextSymbolizer2() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();

    TextSymbolizer2 textSymbolizer = null;
    VOGeoServerTextSymbolizer2 testObj = new VOGeoServerTextSymbolizer2(panel.getClass());
    testObj.setParentPanel(panel);
    testObj.populate(textSymbolizer);
    testObj.updateSymbol(textSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Literal featureDescription = ff.literal("feature description");
    textSymbolizer.setFeatureDescription(featureDescription);

    OtherText otherText = new OtherTextImpl();
    otherText.setTarget("target");
    Literal otherTextExpression = ff.literal("other text");
    otherText.setText(otherTextExpression);
    textSymbolizer.setOtherText(otherText);
    Literal snippet = ff.literal("snippet");
    textSymbolizer.setSnippet(snippet);

    // Try with marker symbol
    Graphic graphic = styleFactory.createDefaultGraphic();
    graphic.graphicalSymbols().add(styleFactory.createMark());
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Try with external graphic
    graphic = styleFactory.createDefaultGraphic();
    try {
        graphic.graphicalSymbols()
                .add(
                        styleFactory.createExternalGraphic(
                                new File("test.png").toURI().toURL(), "png"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Find minimum version with textSymbolizer2 values set
    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
    assertEquals(1, vendorOptionsPresentList.size());

    // Find minimum version with no textSymbolizer2 values set
    vendorOptionsPresentList.clear();
    testObj.getMinimumVersion(
            null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());

    // Get the code coverage values up
    testObj.populate(SelectedSymbol.getInstance());

    PolygonSymbolizer polygon = null;
    testObj.populate(polygon);
    testObj.updateSymbol(polygon);

    RasterSymbolizer raster = null;
    testObj.populate(raster);
    testObj.updateSymbol(raster);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
}
 
Example #29
Source File: VOGeoServerTextSpacingTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.vendor.geoserver.text.VOGeoServerTextSpacingTest#VOGeoServerTextSpacingTest(java.lang.Class,
 * com.sldeditor.filter.v2.function.FunctionNameInterface)}.
 */
@Test
public void testVOGeoServerTextSpacingTest() {
    TextSymbolizerDetails panel = new TextSymbolizerDetails();

    TextSymbolizer2 textSymbolizer = null;
    VOGeoServerTextSpacing testObj = new VOGeoServerTextSpacing(panel.getClass());
    testObj.setParentPanel(panel);
    testObj.populate(textSymbolizer);
    testObj.updateSymbol(textSymbolizer);

    StyleFactoryImpl styleFactory = (StyleFactoryImpl) CommonFactoryFinder.getStyleFactory();
    textSymbolizer = (TextSymbolizer2) styleFactory.createTextSymbolizer();

    FilterFactory ff = CommonFactoryFinder.getFilterFactory();

    Literal featureDescription = ff.literal("feature description");
    textSymbolizer.setFeatureDescription(featureDescription);

    OtherText otherText = new OtherTextImpl();
    otherText.setTarget("target");
    Literal otherTextExpression = ff.literal("other text");
    otherText.setText(otherTextExpression);
    textSymbolizer.setOtherText(otherText);
    Literal snippet = ff.literal("snippet");
    textSymbolizer.setSnippet(snippet);

    // Try with marker symbol
    Graphic graphic = styleFactory.createDefaultGraphic();
    graphic.graphicalSymbols().add(styleFactory.createMark());
    textSymbolizer.setGraphic(graphic);
    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Try with external graphic
    graphic = styleFactory.createDefaultGraphic();
    try {
        graphic.graphicalSymbols()
                .add(
                        styleFactory.createExternalGraphic(
                                new File("test.png").toURI().toURL(), "png"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    textSymbolizer.setGraphic(graphic);

    textSymbolizer.getOptions().put("wordSpacing", String.valueOf(42));
    textSymbolizer.getOptions().put("charSpacing", String.valueOf(21));

    Controller.getInstance().setPopulating(true);
    testObj.populate(textSymbolizer);
    Controller.getInstance().setPopulating(false);
    testObj.updateSymbol(textSymbolizer);

    // Find minimum version with textSymbolizer2 values set
    List<VendorOptionPresent> vendorOptionsPresentList = new ArrayList<VendorOptionPresent>();
    testObj.getMinimumVersion(null, textSymbolizer, vendorOptionsPresentList);
    assertEquals(2, vendorOptionsPresentList.size());

    // Find minimum version with no textSymbolizer2 values set
    vendorOptionsPresentList.clear();
    testObj.getMinimumVersion(
            null, styleFactory.createTextSymbolizer(), vendorOptionsPresentList);
    assertEquals(0, vendorOptionsPresentList.size());

    // Get the code coverage values up
    testObj.populate(SelectedSymbol.getInstance());

    PolygonSymbolizer polygon = null;
    testObj.populate(polygon);
    testObj.updateSymbol(polygon);

    FeatureTypeStyle fts = null;
    testObj.populate(fts);
    testObj.updateSymbol(fts);

    RasterSymbolizer raster = null;
    testObj.populate(raster);
    testObj.updateSymbol(raster);
    testObj.preLoadSymbol();
    assertTrue(testObj.isDataPresent());
}
 
Example #30
Source File: ExtractTimeFilterVisitor.java    From geowave with Apache License 2.0 2 votes vote down vote up
/**
 * Please note we are only visiting literals involved in time.
 *
 * @param expression a literal time
 * @param data unused
 * @return temporal constraints updated to reflect literal
 */
@Override
public Object visit(final Literal expression, final Object data) {
  final Object value = expression.getValue();
  return btime(value);
}