private Attribute buildSimpleContentInternal(AttributeType simpleContentType, Object value) { Object convertedValue = FF.literal(value).evaluate(value, simpleContentType.getBinding()); AttributeDescriptor descriptor = new AttributeDescriptorImpl( simpleContentType, ComplexFeatureConstants.SIMPLE_CONTENT, 1, 1, true, (Object) null); return new AttributeImpl(convertedValue, descriptor, null); }
public Object visit(Literal expression, Object extraData) { Object value = expression.getValue(); if (value == null) { element("Literal", ""); } else if (value instanceof Geometry) { geometryEncoder.encode((Geometry) value); } else { String txt = expression.evaluate(null, String.class); if (txt == null) { txt = value.toString(); } element("Literal", txt); } return extraData; }
AttributeDescriptor attType = (AttributeDescriptor) property.evaluate(featureType); if (attType != null) { typeContext = attType.getType().getBinding(); if (temporal.evaluate(null) instanceof Period) { period = (Period) temporal.evaluate(null); out.write("("); property.accept(this, extraData); out.write(swapped ? inv : op); visitBegin(period, extraData); } else { if (swapped) { temporal.accept(this, typeContext); } else { property.accept(this, extraData); property.accept(this, extraData); } else { temporal.accept(this, typeContext); property.accept(this, extraData); out.write(" = "); temporal.accept(this, typeContext);
private Literal clipToWorld(Literal geometry) { if(geometry != null) { Geometry g = geometry.evaluate(null, Geometry.class); if(g != null) { Envelope env = g.getEnvelopeInternal(); g = sanitizePolygons(g.intersection(JTS.toGeometry(WORLD))); env = g.getEnvelopeInternal(); if(Math.sqrt(env.getWidth() * env.getWidth() + env.getHeight() * env.getHeight()) >= 180) { geometry = CommonFactoryFinder.getFilterFactory(null).literal(g);
private void testLogicFilter(Class<?> filterType) throws Exception { BinaryLogicOperator complexLogicFilter; PropertyIsGreaterThan resultFilter = ff.greater(ff.property("measurement/result"), ff.literal(Integer.valueOf(5))); ((PropertyName) unmappedResult.getExpression1()).getPropertyName()); assertEquals(Integer.valueOf(5), ((Literal) unmappedResult.getExpression2()).getValue()); ((PropertyName) unmappedDeterm.getExpression()).getPropertyName()); assertEquals( "determinand_description_1_1", ((Literal) unmappedDeterm.getLowerBoundary()).getValue()); assertEquals( "determinand_description_3_3", ((Literal) unmappedDeterm.getUpperBoundary()).getValue());
@Test public void testLogicFilterAnd() throws Exception { PropertyIsEqualTo equals = ff.equals(ff.property("measurement/result"), ff.literal(1.1)); PropertyIsGreaterThan greater = ff.greater(ff.property("measurement/determinand_description"), ff.literal("desc1")); And logicFilter = ff.and(equals, greater); Filter unrolled = (Filter) logicFilter.accept(visitor, null); assertNotNull(unrolled); assertTrue(unrolled instanceof And); assertNotSame(equals, unrolled); And sourceAnd = (And) unrolled; assertEquals(2, sourceAnd.getChildren().size()); Filter sourceEquals = (Filter) sourceAnd.getChildren().get(0); assertTrue(sourceEquals instanceof PropertyIsEqualTo); Expression left = ((PropertyIsEqualTo) sourceEquals).getExpression1(); Expression right = ((PropertyIsEqualTo) sourceEquals).getExpression2(); assertTrue(left instanceof PropertyName); assertTrue(right instanceof Literal); assertEquals("results_value", ((PropertyName) left).getPropertyName()); assertEquals(new Double(1.1), ((Literal) right).getValue()); Filter sourceGreater = (Filter) sourceAnd.getChildren().get(1); assertTrue(sourceGreater instanceof PropertyIsGreaterThan); left = ((PropertyIsGreaterThan) sourceGreater).getExpression1(); right = ((PropertyIsGreaterThan) sourceGreater).getExpression2(); assertTrue(left instanceof PropertyName); assertTrue(right instanceof Literal); assertEquals("determinand_description", ((PropertyName) left).getPropertyName()); assertEquals("desc1", ((Literal) right).getValue()); }
protected Envelope extractBboxForSpatialIndexQuery(BinarySpatialOperator filter){ org.opengis.filter.expression.Expression leftGeom = filter.getExpression1(); org.opengis.filter.expression.Expression rightGeom = filter.getExpression2(); Geometry g ; if (leftGeom instanceof org.opengis.filter.expression.Literal){ g = (Geometry)((org.opengis.filter.expression.Literal)leftGeom).getValue(); }else{ g = (Geometry)((org.opengis.filter.expression.Literal)rightGeom).getValue(); } return g.getEnvelopeInternal(); }
@Test public void testCompareFilter() throws Exception { PropertyIsEqualTo complexFilter = ff.equal(ff.property("measurement/result"), ff.literal(1.1), true, MatchAction.ALL); Filter unrolled = (Filter) complexFilter.accept(visitor, null); assertNotNull(unrolled); assertTrue(unrolled instanceof PropertyIsEqualTo); assertNotSame(complexFilter, unrolled); assertTrue(((PropertyIsEqualTo) unrolled).isMatchingCase()); assertEquals(MatchAction.ALL, ((PropertyIsEqualTo) unrolled).getMatchAction()); Expression left = ((PropertyIsEqualTo) unrolled).getExpression1(); Expression right = ((PropertyIsEqualTo) unrolled).getExpression2(); assertTrue(left instanceof PropertyName); assertTrue(right instanceof Literal); PropertyName attExp = (PropertyName) left; String expectedAtt = "results_value"; assertEquals(expectedAtt, attExp.getPropertyName()); assertEquals(new Double(1.1), ((Literal) right).getValue()); }
public Object visit(BBOX filter, Object extraData) { if (filter.getExpression2() instanceof Literal) { Literal bboxLiteral = (Literal) filter.getExpression2(); if (bboxLiteral.getValue() instanceof BoundingBox) { BoundingBox bounds = (BoundingBox) bboxLiteral.getValue(); return ff.bbox(filter.getExpression1(), new ReferencedEnvelope( bounds.getMinY(), bounds.getMaxY(), bounds.getMinX(), bounds.getMaxX(), bounds.getCoordinateReferenceSystem())); } else if (bboxLiteral.getValue() instanceof Geometry) { Geometry geom = (Geometry) bboxLiteral.getValue(); Envelope geomEnvelope = geom.getEnvelopeInternal(); return ff.bbox(filter.getExpression1(), new ReferencedEnvelope( geomEnvelope.getMinY(), geomEnvelope.getMaxY(), geomEnvelope.getMinX(), geomEnvelope.getMaxX(), null)); } } return filter; }
public void testIntersectsFilterFunctionReferencedGeometry() throws Exception { GeometryFactory gf = new GeometryFactory(); LineString ls = gf.createLineString( new Coordinate[] {new Coordinate(10, 15), new Coordinate(20, 25)}); ls.setUserData(CRS.decode("urn:x-ogc:def:crs:EPSG:6.11.2:4326")); Function intersects = ff.function("intersects", ff.property("geom"), ff.literal(ls)); Function clone = (Function) intersects.accept(reprojector, null); assertNotSame(intersects, clone); assertEquals(clone.getParameters().get(0), intersects.getParameters().get(0)); assertFalse(clone.getParameters().get(1).equals(intersects.getParameters().get(1))); LineString clonedLs = (LineString) ((Literal) clone.getParameters().get(1)).getValue(); assertTrue(15 == clonedLs.getCoordinateN(0).x); assertTrue(10 == clonedLs.getCoordinateN(0).y); assertTrue(25 == clonedLs.getCoordinateN(1).x); assertTrue(20 == clonedLs.getCoordinateN(1).y); assertEquals(CRS.decode("EPSG:4326"), clonedLs.getUserData()); }
@Test public void testFindCategorizeFunction() throws Exception { // System.out.println(" testFindCategorizeFunction"); Literal fallback = ff2.literal("NOT_FOUND"); parameters.add(ff2.property("value")); parameters.add(ff2.literal(0)); Function fn = finder.findFunction("categorize", parameters, fallback); Object result = fn.evaluate(feature(0)); assertFalse("Could not locate 'categorize' function", result.equals(fallback.getValue())); }
public static PeriodNode createPeriodDateAndDuration( final Literal date, final Literal duration, FilterFactory filterFactory) { // compute last date from duration // Y M D and H M S Date firstDate = (Date) date.getValue(); String strDuration = (String) duration.getValue(); Date lastDate = DurationUtil.addDurationToDate(firstDate, strDuration); Literal literalLastDate = filterFactory.literal(lastDate); PeriodNode period = new PeriodNode(date, literalLastDate); return period; }
public Object visit(Literal expression, Object extraData) { if (!(expression.getValue() instanceof Geometry)) return super.visit(expression, extraData); // check if reprojection is needed Geometry geom = (Geometry) expression.getValue(); if(geom.getUserData() != null && geom.getUserData() instanceof CoordinateReferenceSystem) return super.visit(expression, extraData); // clone the geometry and assign the new crs Geometry clone = geom.getFactory().createGeometry(geom); clone.setUserData(defaultCrs); // clone return ff.literal(clone); } }
private void updateMinMaxFields(Expression expression) { if (expression instanceof Literal) { Literal bbox = (Literal) expression; Object value = bbox.getValue(); if (value instanceof BoundingBox) { BoundingBox env = (BoundingBox) value; } else if (value instanceof Geometry) { Geometry geom = (Geometry) value; env = geom.getEnvelopeInternal(); if (geom.getUserData() != null) { if (geom.getUserData() instanceof String) { srs = (String) geom.getUserData(); } else if (geom.getUserData() instanceof CoordinateReferenceSystem) { env = (Envelope) bbox.evaluate(null, Envelope.class);
private String getPropertyName(Expression expr) { String propertyName; if (expr instanceof Literal) { propertyName = String.valueOf(((Literal) expr).getValue()); } else if (expr instanceof PropertyName) { propertyName = ((PropertyName) expr).getPropertyName(); } else { throw new IllegalStateException("Not a property name expression: " + expr); } return propertyName; }
/** * Given a geometry literal, it buffers it with the provided distance, and then * transforms it with the given reprojection/affine transform we're applying. * Used to transform distance filters * @param geom * @param distance * @return */ private Literal bufferTransformGeometry(Literal geomLiteral, double distance, Object extraData) { try { Geometry geometry = (Geometry) geomLiteral.evaluate(null, Geometry.class); Geometry buffered = geometry.buffer(distance); Geometry transformed = JTS.transform(buffered, mt); return getFactory(extraData).literal(transformed); } catch(Exception e) { throw new RuntimeException(e); } }
/** * Rescale using listMultiply, if there is only one entry. * * @param expressions * @return */ protected List<Expression> rescaleDashArray(List<Expression> expressions) { if (expressions == null || expressions.isEmpty()) { return expressions; } Expression rescaleToExpression = rescale(ff.literal(1)); // How to test, if it is a measure with a unit or not? String data = ((Literal) rescaleToExpression).getValue().toString(); boolean evaluate = rescaleToExpression instanceof Literal && Character.isDigit(data.charAt(data.length() - 1)); List<Expression> rescaled = new ArrayList<>(expressions.size()); for (Expression expression : expressions) { Expression rescale = ff.function("listMultiply", rescaleToExpression, expression); if (expression instanceof Literal && evaluate) { rescaled.add(ff.literal(rescale.evaluate(null))); } else { rescaled.add(rescale); } } return rescaled; }
final Geometry geom = literal.evaluate(null, Geometry.class); final double distance = filter.getDistance(); final Geometry buffer = geom.buffer(distance); BinarySpatialOperator intersects = ff.intersects(property, ff.literal(buffer));