org.opengis.filter.expression.Function类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中org.opengis.filter.expression.Function类的一些代码示例,展示了Function类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Function类的具体详情如下:
包路径:org.opengis.filter.expression.Function
类名称:Function

Function介绍

[英]Instances of this class represent a function call into some implementation-specific function.

Each execution environment should provide a list of supported functions (and the number of arguments they expect) as part of a FilterCapabilities data structure.

This is included for completeness with respect to the OGC Filter specification. However, no functions are required to be supported by that specification.
[中]此类的实例表示对某些特定于实现的函数的函数调用。
作为FilterCapabilities数据结构的一部分,每个执行环境都应该提供一个受支持函数的列表(以及它们期望的参数数量)。
这是为了确保OGC过滤器规范的完整性。但是,该规范不需要支持任何功能。

代码示例

代码示例来源:origin: geotools/geotools

public Object visit(Function expression, Object data) {
  if (expression.getParameters() != null) {
    for (Expression parameter : expression.getParameters()) {
      data = parameter.accept(this, data);
    }
  }
  return data;
}

代码示例来源:origin: geotools/geotools

public Object visit(Function expression, Object extraData) {
  String type = (String) "Function";
  AttributesImpl atts = new AttributesImpl();
  atts.addAttribute("", "name", "name", "", expression.getName());
  start(type, atts);
  for (org.opengis.filter.expression.Expression parameter : expression.getParameters()) {
    parameter.accept(this, extraData);
  }
  end(type);
  return extraData;
}

代码示例来源:origin: geotools/geotools

@Override
public Object visit(Function f, Object extraData) {
  FunctionName fn = f.getFunctionName();
  if (fn != null && fn.getReturn() != null && fn.getReturn().getType() != Object.class) {
    return fn.getReturn().getType();
  } else if (f instanceof FilterFunction_Convert) {
    // special case for the convert function, which has the return type as
    // a parameter
    return f.getParameters().get(1).evaluate(null, Class.class);
  }
  return null;
}

代码示例来源:origin: geotools/geotools

public FunctionBuilder reset(Function original) {
  name = original.getName();
  args.clear();
  args.addAll(original.getParameters());
  literal.reset(original.getFallbackValue());
  return this;
}

代码示例来源:origin: geotools/geotools

public void testToLowerCase() {
  FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
  Function f = ff.function("strToLowerCase", ff.literal("UPCASE"));
  assertEquals("upcase", f.evaluate(null));
}

代码示例来源:origin: geotools/geotools

public void testIntersectsFilterFunctionUnreferencedGeometry() throws Exception {
  GeometryFactory gf = new GeometryFactory();
  LineString ls =
      gf.createLineString(
          new Coordinate[] {new Coordinate(10, 15), new Coordinate(20, 25)});
  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));
  assertEquals(clone.getParameters().get(1), intersects.getParameters().get(1));
}

代码示例来源:origin: geotools/geotools

public void testIntPresent() {
  PropertyName exp = ff.property("foo");
  Function func =
      ff.function(FUNCTION_NAME, exp, ff.literal(3), ff.literal(4), ff.literal(5));
  Object result = func.evaluate(feature);
  assertEquals(true, result);
}

代码示例来源:origin: geotools/geotools

/**
 * Return {@link #DAY} formatted according to {@link #PATTERN} in a time zone.
 *
 * @param timezone in one of the formats supported by {@link TimeZone}
 * @return the formatted day
 */
private String formatTimezone(String timezone) {
  return (String)
      ff.function(
              FormatDateTimezoneFunction.NAME.getFunctionName(),
              ff.literal(PATTERN),
              ff.literal(TIME),
              ff.literal(timezone))
          .evaluate(null);
}

代码示例来源:origin: geotools/geotools

public void testNestedVolatile() {
  EnvFunction.setLocalValue("power", 3);
  Function f =
      ff.function("pow", ff.function("random"), ff.function("env", ff.literal("power")));
  Function result = (Function) f.accept(simpleVisitor, null);
  // main function not simplified out
  assertEquals("pow", result.getName());
  // first argument not simplified out
  Function param1 = (Function) result.getParameters().get(0);
  assertEquals("random", param1.getName());
  // second argument simplified out
  Expression param2 = result.getParameters().get(1);
  assertTrue(param2 instanceof Literal);
  assertEquals(Integer.valueOf(3), param2.evaluate(null, Integer.class));
}

代码示例来源:origin: geotools/geotools

/** Test of getName method, of class org.geotools.filter.functions.UniqueIntervalFunction. */
public void testGetName() {
  Function equInt = ff.function("UniqueInterval", ff.literal(featureCollection));
  assertEquals("UniqueInterval", equInt.getName());
}

代码示例来源:origin: geotools/geotools

public void testCatenateTwo() {
  Literal l = ff.literal("http://test?param=");
  PropertyName pn = ff.property("intAttribute");
  Expression cat = ExpressionExtractor.catenateExpressions(Arrays.asList(l, pn));
  assertTrue(cat instanceof Function);
  Function f = (Function) cat;
  assertEquals("Concatenate", f.getName());
  assertEquals(l, f.getParameters().get(0));
  assertEquals(pn, f.getParameters().get(1));
}

代码示例来源:origin: geotools/geotools

public void testConcatenate() throws Exception {
    Function function =
        ff.function(
            "Concatenate", ff.literal("hello"), ff.literal(" "), ff.literal("world"));
    assertEquals("hello world", function.evaluate(null, String.class));
  }
}

代码示例来源:origin: geotools/geotools

@Test
public void testNoVocabFunction() {
  FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
  Function function = ff.function("Vocab", ff.literal("a"), ff.literal("urn:1234"));
  try {
    function.evaluate(null);
    fail("Should not be able to get this far");
  } catch (Exception expected) {
  }
}

代码示例来源:origin: geotools/geotools

public void testChainIntersection() {
    Function innerBuffer1 = ff.function("buffer", ff.property("the_geom"), ff.literal(3));
    Function innerBuffer2 = ff.function("buffer", ff.property("other_geom"), ff.literal(2));
    Function geomTx = ff.function("intersection", innerBuffer1, innerBuffer2);

    ReferencedEnvelope re = new ReferencedEnvelope(0, 2, 0, 2, null);

    GeometryTransformationVisitor visitor = new GeometryTransformationVisitor();
    ReferencedEnvelope result = (ReferencedEnvelope) geomTx.accept(visitor, re);

    ReferencedEnvelope expected = new ReferencedEnvelope(-3, 5, -3, 5, null);
    assertEquals(expected, result);
  }
}

代码示例来源:origin: geotools/geotools

Function min_4Function = ff.function("min_4", literal_1, literal_m1);
assertEquals(
    "min of (1.0,-1.0):",
    (long) Math.min(1.0, -1.0),
    ((Integer) min_4Function.evaluate(null)).intValue(),
    0.00001);
min_4Function = ff.function("min_4", literal_m1, literal_2);
assertEquals(
    "min of (-1.0,2.0):",
    (long) Math.min(-1.0, 2.0),
    ((Integer) min_4Function.evaluate(null)).intValue(),
    0.00001);
    "min of (2.0,-2.0):",
    (long) Math.min(2.0, -2.0),
    ((Integer) min_4Function.evaluate(null)).intValue(),
    0.00001);
    "min of (-2.0,3.141592653589793):",
    (long) Math.min(-2.0, 3.141592653589793),
    ((Integer) min_4Function.evaluate(null)).intValue(),
    0.00001);
    "min of (3.141592653589793,1.5707963267948966):",
    (long) Math.min(3.141592653589793, 1.5707963267948966),
    ((Integer) min_4Function.evaluate(null)).intValue(),
    0.00001);

代码示例来源:origin: geotools/geotools

public void testCountFunctionDescription() throws Exception {
  // Create instance of function to get hold of the filter capabilities
  PropertyName exp = ff.property("foo");
  Function func = ff.function("Collection_Count", exp);
  // Expecting one function parameter
  assertEquals(func.getParameters().size(), 1);
  // Test return parameter
  assertEquals(func.getFunctionName().getReturn().toString(), "count:Number");
}

代码示例来源:origin: geotools/geotools

public void testStableFunction() {
  EnvFunction.setLocalValue("var", "123");
  Function f = ff.function("env", ff.literal("var"));
  Expression result = (Expression) f.accept(simpleVisitor, null);
  assertTrue(result instanceof Literal);
  assertEquals("123", result.evaluate(null, String.class));
}

代码示例来源:origin: geotools/geotools

public Object visit(org.opengis.filter.expression.Function function, Object extraData) {
  // can't optimize out volatile functions
  if (isVolatileFunction(function)) {
    return super.visit(function, extraData);
  }
  // stable function, is it using attributes?
  if (attributeExtractor == null) {
    attributeExtractor = new FilterAttributeExtractor();
  } else {
    attributeExtractor.clear();
  }
  function.accept(attributeExtractor, null);
  // if so we can replace it with a literal
  if (attributeExtractor.isConstantExpression()) {
    Object result = function.evaluate(null);
    return ff.literal(result);
  } else {
    return super.visit(function, extraData);
  }
}

代码示例来源:origin: geotools/geotools

public void testBasicTest() throws Exception {
  Function exp = ff.function("geometryType", ff.property("geom"));
  SimpleFeatureIterator iter = featureCollection.features();
  while (iter.hasNext()) {
    SimpleFeature feature = iter.next();
    assertEquals("Point", exp.evaluate(feature));
  }
  iter.close();
}

代码示例来源:origin: geotools/geotools

@Override
public Object visit(Function expression, Object extraData) {
  List old = expression.getParameters();
  FunctionName functionName = expression.getFunctionName();
  List<Parameter<?>> arguments = null;
  if (functionName != null) {
    arguments = functionName.getArguments();
  }
  Expression[] args = new Expression[old.size()];
  for (int i = 0; i < old.size(); i++) {
    Expression exp = (Expression) old.get(i);
    if (arguments != null && i < arguments.size()) {
      args[i] = optimize(exp, extraData, arguments.get(i).getType());
    } else {
      args[i] = visit(exp, extraData);
    }
  }
  Function duplicate;
  if (expression instanceof InternalFunction) {
    duplicate = ((InternalFunction) expression).duplicate(args);
  } else {
    duplicate = getFactory(extraData).function(expression.getName(), args);
  }
  return duplicate;
}

相关文章

微信公众号

最新文章

更多