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

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

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

FilterFactory2介绍

[英]Allows creation of additional Filter constructs.

Why do we need this? Because not all implementations are going to be using geoapi Geometry. This allows the creation of complient filters with SFSQL Geometry constructs. Consider this a bridge to existing projects allowing GeoAPI to be used.
[中]允许创建其他筛选器构造。
我们为什么需要这个?因为并非所有的实现都将使用geoapi几何体。这允许使用SFSQL几何结构创建complient筛选器。认为这是一个桥梁,以允许使用GEOAPI的现有项目。

代码示例

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

private SimpleFeatureCollection filteredCollection(
      Geometry currentGeom, SimpleFeatureCollection subFeatureCollection) {
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
    Filter intersectFilter =
        ff.intersects(ff.property(dataGeomName), ff.literal(currentGeom));
    SimpleFeatureCollection subFeatureCollectionIntersection =
        this.subFeatureCollection.subCollection(intersectFilter);
    if (subFeatureCollectionIntersection.size() == 0) {
      subFeatureCollectionIntersection = subFeatureCollection;
    }
    return subFeatureCollectionIntersection;
  }
}

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

protected Filter intersection(Filter a, Filter b) {
  if (a == null) return b;
  if (b == null) return a;
  if (a == Filter.INCLUDE && b == Filter.INCLUDE) {
    return Filter.INCLUDE;
  } else if (a == Filter.EXCLUDE || b == Filter.EXCLUDE) {
    return Filter.EXCLUDE;
  } else {
    return factory.and(a, b);
  }
}

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

Object cloneFilter(
      BinarySpatialOperator bso, Object extraData, Expression ex1, Expression ex2) {
    return ff.equal(ex1, ex2);
  }
}.transform(filter, extraData);

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

@Override
  public Object visit(Id filter, Object extraData) {
    Set<Identifier> identifiers = filter.getIdentifiers();
    Set<Identifier> renamedIdentifiers =
        identifiers
            .stream()
            .map(
                id -> {
                  String name = id.getID().toString();
                  if (name.startsWith(prefix)) {
                    name = name.substring(prefix.length());
                  }
                  return getFactory(extraData).featureId(name);
                })
            .collect(Collectors.toSet());
    return getFactory(extraData).id(renamedIdentifiers);
  }
}

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

private Filter partialIndexedFilterXpath() {
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
    Filter filter =
        ff.and(
            ff.equals(ff.property("st:Station"), ff.literal("st.1")),
            ff.like(ff.property("st:Station/st:location/st:name"), "*fer*"));
    return filter;
  }
}

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

@Test
public void testFilter() throws Exception {
  FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2();
  StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
  StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
  UserLayer layer = styleFactory.createUserLayer();
  sld.layers().add(layer);
  Style style = styleFactory.createStyle();
  layer.userStyles().add(style);
  Rule rule = styleFactory.createRule();
  rule.setFilter(filterFactory.less(filterFactory.property("foo"), filterFactory.literal(2)));
  style.featureTypeStyles().add(styleFactory.createFeatureTypeStyle());
  style.featureTypeStyles().get(0).rules().add(rule);
  PointSymbolizer p = styleFactory.createPointSymbolizer();
  rule.symbolizers().add((Symbolizer) p);
  StringWriter out = new StringWriter();
  Ysld.encode(sld, out);
  YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
  YamlMap result = obj.seq("feature-styles").map(0).seq("rules").map(0);
  assertThat(result, yHasEntry("filter", equalTo("${foo < 2}")));
}

代码示例来源: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

private Filter totallyIndexedFilter() {
  FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
  Filter filter =
      ff.or(
          ff.equals(ff.property("st:Station"), ff.literal("st.1")),
          ff.like(ff.property("st:Station/st:name"), "*fer*"));
  return filter;
}

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

private Style createEnvMinMaxCoverageStyle(String bandName) {
    StyleFactory sf = CommonFactoryFinder.getStyleFactory(null);
    FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);

    ContrastEnhancement ce = sf.contrastEnhancement(ff.literal(1.0), ContrastMethod.NORMALIZE);
    ce.addOption("algorithm", ff.literal("StretchToMinimumMaximum"));
    ce.addOption("minValue", ff.function("env", ff.literal("range_min"), ff.literal(0)));
    ce.addOption("maxValue", ff.function("env", ff.literal("range_max"), ff.literal(220)));
    SelectedChannelType sct = sf.createSelectedChannelType(bandName, ce);

    RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
    ChannelSelection sel = sf.channelSelection(sct);
    sym.setChannelSelection(sel);

    return SLD.wrapSymbolizers(sym);
  }
}

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

@Test
public void testAnd() {
  Filter f =
      ff.and(
          ff.bbox("geom", -10, -10, 10, 10, null),
          ff.equals(ff.property("att"), ff.literal("10")));
  Envelope env = (Envelope) f.accept(visitor, null);
  assertEquals(new Envelope(-10, 10, -10, 10), env);
}

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

@Test
public void testAndDisjoint() {
  Coordinate[] coords = new Coordinate[] {new Coordinate(0, 0), new Coordinate(10, 10)};
  LineString lineString = new GeometryFactory().createLineString(coords);
  Filter filter = ff.disjoint(ff.property("name"), ff.literal(lineString));
  filter = ff.and(filter, ff.bbox(ff.property("geom"), 50, 50, 150, 150, null));
  Envelope env = (Envelope) filter.accept(visitor, null);
  assertEquals(new Envelope(50, 150, 50, 150), env);
}

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

protected Expression optimize(Expression expression, Object extraData, Class targetType) {
  if (expression instanceof Literal && targetType != null) {
    // perform the conversion and return the optimized literal
    Object converted = expression.evaluate(null, targetType);
    if (converted != null) {
      return ff.literal(converted);
    }
  }
  // in case we could not optimize, just duplicate
  return visit(expression, extraData);
}

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

@Test
public void testOr() {
  Filter f =
      ff.or(
          ff.bbox("geom", -10, -10, 10, 10, null),
          ff.equals(ff.property("att"), ff.literal("10")));
  Envelope env = (Envelope) f.accept(visitor, null);
  assertEquals(infinity, env);
}

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

public void testIdFinderFilterVisitor() {
  Filter filter = ff.isNull(ff.property("name"));
  boolean found = (Boolean) filter.accept(new IdFinderFilterVisitor(), null);
  assertFalse(found);
  filter = ff.id(Collections.singleton(ff.featureId("eclesia")));
  found = (Boolean) filter.accept(new IdFinderFilterVisitor(), null);
  assertTrue(found);
}

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

@Test
public void testEmbededExpressionEscapeExpression() throws Exception {
  PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
  Expression expression =
      CommonFactoryFinder.getFilterFactory2()
          .function(
              "strEndsWith",
              CommonFactoryFinder.getFilterFactory2().property("attribute1"),
              CommonFactoryFinder.getFilterFactory2().literal("}"));
  p.setGeometry(expression);
  StringWriter out = new StringWriter();
  Ysld.encode(sld(p), out);
  YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
  String result =
      obj.seq("feature-styles")
          .map(0)
          .seq("rules")
          .map(0)
          .seq("symbolizers")
          .map(0)
          .map("point")
          .str("geometry");
  assertThat(result, equalTo("${strEndsWith(attribute1,'\\}')}"));
}

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

@Test
public void testIntersects() {
  ff.intersects(ff.property("geom"), ff.literal(null)).accept(visitor, null);
  assertTrue(visitor.hasSpatialFilter);
}

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

@Test
public void testNonNameExpressionAttribute() throws Exception {
  PointSymbolizer p = CommonFactoryFinder.getStyleFactory().createPointSymbolizer();
  Expression expression = CommonFactoryFinder.getFilterFactory2().property("test");
  p.setGeometry(expression);
  StringWriter out = new StringWriter();
  Ysld.encode(sld(p), out);
  YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString()));
  String result =
      obj.seq("feature-styles")
          .map(0)
          .seq("rules")
          .map(0)
          .seq("symbolizers")
          .map(0)
          .map("point")
          .str("geometry");
  assertThat(result, equalTo("${test}"));
}

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

@Test
public void testFunction() throws Exception {
  Function fe =
      ff.function(
          "strIndexOf",
          ff.property("/measurement/determinand_description"),
          ff.literal("determinand_description_1"));
  List unrolledExpressions = (List) fe.accept(visitor, null);
  Expression unmapped = (Expression) unrolledExpressions.get(0);
  assertTrue(unmapped instanceof Function);
  List params = ((Function) unmapped).getParameters();
  assertEquals(2, params.size());
  assertTrue(params.get(0) instanceof PropertyName);
  assertEquals("determinand_description", ((PropertyName) params.get(0)).getPropertyName());
}

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

@Test
public void testAndTemporalBetween() throws Exception {
  final Instant start = instant("2016-01-01T00:00:00.000-0500");
  final Instant end = instant("2106-01-02T00:00:00.000-0500");
  final Filter f =
      ff.and(
          ff.bbox("geom", -10, -10, 10, 10, null),
          ff.between(ff.literal("someDate"), ff.literal(start), ff.literal(end)));
  final Envelope env = (Envelope) f.accept(visitor, null);
  assertEquals(new Envelope(-10, 10, -10, 10), env);
}

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

@BeforeClass
public static void setUpBeforeClass() throws Exception {
  ff = CommonFactoryFinder.getFilterFactory2(null);
  filters = new Filters(ff);
  a = ff.greater(ff.property("zone"), ff.literal(7));
  b = ff.like(ff.property("suburb"), "N%");
  c = ff.equals(ff.property("Subject"), ff.literal("foo"));
  d = ff.equals(ff.property("Subject"), ff.literal("bar"));
}

相关文章