org.geotools.filter.Filters类的使用及代码示例

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

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

Filters介绍

[英]Utility class for working with Filters & Expression.

To get the full benefit you will need to create an instanceof this Object (supports your own custom FilterFactory!). Additional methods to help create expressions are available.

Example use:

Filters filters = new Filters( factory ); 
filters.duplicate( original );

The above example creates a copy of the provided Filter, the factory provided will be used when creating the duplicated content.

Expression

Expressions form an interesting little semi scripting language, intended for queries. A interesting Feature of Filter as a language is that it is not strongly typed. This utility class many helper methods that ease the transition from Strongly typed Java to the more relaxed setting of Expression where most everything can be a string.

double sum = Filters.number( Object ) + Filters.number( Object );

The above example will support the conversion of many things into a format suitable for addition - the complete list is something like:

  • Any instance of Number
  • "1234" - aka Integer
  • "#FFF" - aka Integer
  • "123.0" - aka Double
    A few things (like Geometry and "ABC") will not be considered addative. In general the scope of these functions should be similar to that allowed by the XML Atomic Types, aka those that can be seperated by whitespace to form a list.

We do our best to be forgiving, any Java class which takes a String as a constructor can be tried, and toString() assumed to be the inverse. This lets many things (like URL and Date) function without modification.
[中]用于处理筛选器和表达式的实用程序类。
要获得全部好处,您需要创建此对象的实例(支持您自己的自定义FilterFactory!)。可以使用其他方法来帮助创建表达式。
示例用法:

Filters filters = new Filters( factory ); 
filters.duplicate( original );

上面的示例创建所提供过滤器的副本,创建复制内容时将使用所提供的工厂。
####表情
表达式形成了一种有趣的半脚本语言,用于查询。Filter作为一种语言的一个有趣特性是它不是强类型的。这个实用程序类包含许多帮助器方法,可以简化从强类型Java到更宽松的表达式设置的转换,其中大部分内容都可以是字符串。

double sum = Filters.number( Object ) + Filters.number( Object );

上述示例将支持将许多内容转换为适合添加的格式-完整列表如下所示:
*任何数字实例
*“1234”-又名整数
*“#FFF”-也称为整数
*“123.0”-又名双
有些东西(如几何和“ABC”)不会被认为是附加的。一般来说,这些函数的范围应该类似于XML原子类型所允许的范围,也就是那些可以用空格分隔以形成列表的函数。
我们尽最大努力去原谅,任何以字符串作为构造函数的Java类都可以尝试,而toString()则被认为是相反的。这使得很多东西(比如URL和日期)不需要修改就可以正常工作。

代码示例

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

/**
 *
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 *
 * @generated modifiable
 */
public Object parse(ElementInstance instance, Node node, Object value) throws Exception {
  Expression expression = (Expression) value;
  String xpath = Filters.asString(expression);
  // if null returned, assume empty string == default geometry
  if (xpath == null) {
    xpath = "";
  }
  return factory.property(xpath);
}

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

int filterType = Filters.getFilterType(this);
if (filterType == NULL) {
  return "[ " + expression1 + " IS NULL ]";

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

/**
 * Retrieve the opacity value of an Expression.
 *
 * @param opacity Expression object
 * @returna double value or 1.0 if unavailable.
 */
private static double opacity(Expression opacity) {
  if (opacity == null) {
    return 1.0;
  }
  double value = Filters.asDouble(opacity);
  return (Double.isNaN(value) ? 1.0 : value);
}

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

private List<Filter> duplicateFilters(List<Filter> filterList) {
  Filters filtersUtil = new Filters();
  return filterList
      .stream()
      .map(f -> filtersUtil.duplicate(f))
      .collect(Collectors.toList());
}

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

@Test
public void testRasterWithTransparentGradient() throws Exception {
  //    <UserStyle>
  //      <Title>SLD Cook Book: Transparent gradient</Title>
  //      <FeatureTypeStyle>
  //        <Rule>
  //          <RasterSymbolizer>
  //            <Opacity>0.3</Opacity>
  //            <ColorMap>
  //              <ColorMapEntry color="#008000" quantity="70" />
  //              <ColorMapEntry color="#663333" quantity="256" />
  //            </ColorMap>
  //          </RasterSymbolizer>
  //        </Rule>
  //      </FeatureTypeStyle>
  //    </UserStyle>
  Style style = parse("raster", "transparent-gradient.sld");
  RasterSymbolizer raster = SLD.rasterSymbolizer(style);
  assertEquals(0.3, Filters.asDouble(raster.getOpacity()), 0.1);
  ColorMapEntry e = raster.getColorMap().getColorMapEntry(0);
  assertEquals("#008000", Filters.asString(e.getColor()));
  assertEquals(70, Filters.asInt(e.getQuantity()));
  e = raster.getColorMap().getColorMapEntry(1);
  assertEquals("#663333", Filters.asString(e.getColor()));
  assertEquals(256, Filters.asInt(e.getQuantity()));
}

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

@Test
public void testRasterWithAlphaChannel() throws Exception {
  //    <UserStyle>
  //      <Title>SLD Cook Book: Alpha channel</Title>
  //      <FeatureTypeStyle>
  //        <Rule>
  //          <RasterSymbolizer>
  //            <ColorMap>
  //              <ColorMapEntry color="#008000" quantity="70" />
  //              <ColorMapEntry color="#008000" quantity="256" opacity="0"/>
  //            </ColorMap>
  //          </RasterSymbolizer>
  //        </Rule>
  //      </FeatureTypeStyle>
  //    </UserStyle>
  Style style = parse("raster", "alpha-channel.sld");
  RasterSymbolizer raster = SLD.rasterSymbolizer(style);
  ColorMapEntry e = raster.getColorMap().getColorMapEntry(0);
  assertEquals("#008000", Filters.asString(e.getColor()));
  assertEquals(70, Filters.asInt(e.getQuantity()));
  e = raster.getColorMap().getColorMapEntry(1);
  assertEquals("#008000", Filters.asString(e.getColor()));
  assertEquals(256, Filters.asInt(e.getQuantity()));
  assertEquals(0, Filters.asInt(e.getOpacity()));
}

代码示例来源:origin: org.geotools/gt2-shapefile-renderer

public void visit(LogicFilter filter) {
  Iterator iter = filter.getFilterIterator();
  while (iter.hasNext()) {
    org.opengis.filter.Filter f = (org.opengis.filter.Filter) iter.next();
    Filters.accept(f, this);
  }
}

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

/**
 * Override of hashCode method.
 *
 * @return the hash code for this literal expression
 */
public int hashCode() {
  int result = 17;
  result = (37 * result) + ((literal == null) ? 0 : literal.hashCode());
  result = (37 * result) + Filters.getExpressionType(this);
  return result;
}

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

/**
 * Retrieve the width of a Stroke object.
 *
 * @param stroke the Stroke object.
 * @return width or {@linkplain #NOTFOUND} if not available.
 */
public static int width(Stroke stroke) {
  if (stroke == null) {
    return NOTFOUND;
  }
  return Filters.asInt(stroke.getWidth());
}

代码示例来源:origin: org.geotools/gt-jdbc

if (filter2 != null) {
  if (splitType == AbstractFilter.LOGIC_AND) {
    retFilter = Filters.and( ff, filter1, filter2 );
  } else { //OR and AND only split types, this must be or.
    retFilter = Filters.or( ff, filter1, filter2 );

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

for (int i = 0; i < params.size(); i++) {
  Expression e = (Expression) params.get(i);
  T value = asType(e, TYPE);

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

assertEquals(7.5, Filters.asDouble(stroke.getDashOffset()), 0.1);
assertEquals(5, Filters.asInt(g.getSize()));

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

@Test
public void testAnd() {
  Filter result = filters.and(ff, a, b);
  assertEquals(ff.and(a, b), result);
}

代码示例来源:origin: stackoverflow.com

Filters filters = new Filters();
filters.add(new Filters(“description”, “Pap”)
 .add(new Filter(“description”))
 .add(new Filter("kind.description", "persa"))
 .add(new Filter("kind.anAssociation.attribute", "anything"));
List<Cat> cats = dao.find(filters);

代码示例来源:origin: stackoverflow.com

var filters = new Filters();

// building of an options hash
var options = {}
for (var pair in facetsCollection) {
  for (var prop in facetsCollection[pair]) {
    options[prop] = (facetsCollection[pair])[prop];
  }
}

// setting the options all at once instead of 1 at a time in the for loops
filters.set(options);

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

private Filter buildLocationsFilter(RasterManager manager, Set<String> locations) {
  PropertyName locationProperty = getLocationProperty(manager);
  List<Filter> filters =
      locations
          .stream()
          .map(l -> FF.equal(locationProperty, FF.literal(l), false))
          .collect(Collectors.toList());
  return Filters.or(FF, filters);
}

代码示例来源:origin: stackoverflow.com

f = new Filters();
 bgr2 = f.barrel(bgr,prog);

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

assertEquals(0.5, Filters.asDouble(contrast.getGammaValue()), 0.1);
assertEquals(ContrastMethod.NORMALIZE, contrast.getMethod());
assertEquals("#008000", Filters.asString(e.getColor()));
assertEquals(70, Filters.asInt(e.getQuantity()));
assertEquals("#663333", Filters.asString(e.getColor()));
assertEquals(256, Filters.asInt(e.getQuantity()));

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

@Test
public void testRasterWithDiscreteColors() throws Exception {
  //    <UserStyle>
  //      <Title>SLD Cook Book: Discrete colors</Title>
  //      <FeatureTypeStyle>
  //        <Rule>
  //          <RasterSymbolizer>
  //            <ColorMap type="intervals">
  //              <ColorMapEntry color="#008000" quantity="150" />
  //              <ColorMapEntry color="#663333" quantity="256" />
  //            </ColorMap>
  //          </RasterSymbolizer>
  //        </Rule>
  //      </FeatureTypeStyle>
  //    </UserStyle>
  Style style = parse("raster", "discrete-colors.sld");
  RasterSymbolizer raster = SLD.rasterSymbolizer(style);
  ColorMapEntry e = raster.getColorMap().getColorMapEntry(0);
  assertEquals("#008000", Filters.asString(e.getColor()));
  assertEquals(150, Filters.asInt(e.getQuantity()));
  e = raster.getColorMap().getColorMapEntry(1);
  assertEquals("#663333", Filters.asString(e.getColor()));
  assertEquals(256, Filters.asInt(e.getQuantity()));
}

代码示例来源:origin: org.geotools/gt2-main

/**
 * @see org.geotools.filter.FilterVisitor#visit(org.geotools.filter.LogicFilter)
 * @deprecated use one of {@link #visit(And, Object)},{@link #visit(Or, Object)},
 *     {@link #visit(Not, Object)}
 */
public void visit(LogicFilter filter) {
  for (Iterator it = filter.getFilterIterator(); it.hasNext();) {
    Filters.accept((org.opengis.filter.Filter)it.next(),this);
  }
}

相关文章