Java Code Examples for org.geotools.factory.CommonFactoryFinder#getFilterFactory2()

The following examples show how to use org.geotools.factory.CommonFactoryFinder#getFilterFactory2() . 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: ImageDataLoader.java    From gama with GNU General Public License v3.0 7 votes vote down vote up
private static Style createStyle(int band, double min, double max) {

		FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
		StyleFactory sf = CommonFactoryFinder.getStyleFactory();

		RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
		ColorMap cMap = sf.createColorMap();
		ColorMapEntry start = sf.createColorMapEntry();
		start.setColor(ff.literal("#ff0000"));
		start.setQuantity(ff.literal(min));
		ColorMapEntry end = sf.createColorMapEntry();
		end.setColor(ff.literal("#0000ff"));
		end.setQuantity(ff.literal(max));

		cMap.addColorMapEntry(start);
		cMap.addColorMapEntry(end);
		sym.setColorMap(cMap);
		Style style = SLD.wrapSymbolizers(sym);

		return style;
	}
 
Example 2
Source File: StyleGenerator.java    From constellation with Apache License 2.0 5 votes vote down vote up
private static Rule makeFillRule(final SimpleFeature feature) {
    final Rule rule = makeFillRule();
    rule.setName((String) feature.getAttribute(ATTRIBUTE));

    // create a filter based on name
    final FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
    rule.setFilter(ff.equals(ff.property(ATTRIBUTE), ff.literal(feature.getAttribute(ATTRIBUTE))));

    return rule;
}
 
Example 3
Source File: GeometryUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static SpatialOperator geometryToSpatialOperator(
    final Geometry jtsGeom,
    final String geometryAttributeName) {
  final FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2();
  if (jtsGeom.equalsTopo(jtsGeom.getEnvelope())) {
    return factory.bbox(
        factory.property(geometryAttributeName),
        new ReferencedEnvelope(jtsGeom.getEnvelopeInternal(), GeometryUtils.getDefaultCRS()));
  }
  // there apparently is no way to associate a CRS with a poly
  // intersection operation so it will have to assume the same CRS as the
  // feature type
  return factory.intersects(factory.property(geometryAttributeName), factory.literal(jtsGeom));
}
 
Example 4
Source File: TimeUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * @param startTimeMillis start time (inclusive)
 * @param endTimeMillis end time (exclusive)
 * @param singleTimeField
 * @return the during filter
 */
public static Filter toDuringFilter(
    final long startTimeMillis,
    final long endTimeMillis,
    final String singleTimeField) {
  final FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2();
  final Position ip1 = new DefaultPosition(new Date(startTimeMillis - 1));
  final Position ip2 = new DefaultPosition(new Date(endTimeMillis));
  final Period period = new DefaultPeriod(new DefaultInstant(ip1), new DefaultInstant(ip2));
  return factory.during(factory.property(singleTimeField), factory.literal(period));
}
 
Example 5
Source File: TimeUtils.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static Filter toFilter(
    final long startTimeMillis,
    final long endTimeMillis,
    final String startTimeField,
    final String endTimeField) {
  final FilterFactory2 factory = CommonFactoryFinder.getFilterFactory2();
  if (startTimeField.equals(endTimeField)) {
    return factory.and(
        factory.greaterOrEqual(
            factory.property(startTimeField),
            factory.literal(new Date(startTimeMillis))),
        factory.lessOrEqual(
            factory.property(endTimeField),
            factory.literal(new Date(endTimeMillis))));
  }
  // this looks redundant to use both start and end time fields, but it helps parsing logic
  return factory.and(
      factory.and(
          factory.greaterOrEqual(
              factory.property(startTimeField),
              factory.literal(new Date(startTimeMillis))),
          factory.lessOrEqual(
              factory.property(startTimeField),
              factory.literal(new Date(endTimeMillis)))),
      factory.and(
          factory.greaterOrEqual(
              factory.property(endTimeField),
              factory.literal(new Date(startTimeMillis))),
          factory.lessOrEqual(
              factory.property(endTimeField),
              factory.literal(new Date(endTimeMillis)))));
}
 
Example 6
Source File: HibernateFilterAttributeTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void nullFilter() throws Exception {
	FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
	Filter filter = ff.isNull(ff.property(PARAM_DATE_ATTR));
	Iterator<?> it = layer.getElements(filter, 0, 0);

	int t = 0;
	while (it.hasNext()) {
		Assert.assertTrue("Returned object must be a HibernateTestFeature",
				it.next() instanceof HibernateTestFeature);
		t++;
	}
	Assert.assertEquals(1, t);
}
 
Example 7
Source File: SimpleFilterTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void nullFilter() throws Exception {
	FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null);
	Filter filter = ff.isNull(ff.property(PARAM_DATE_ATTR));
	Iterator<?> it = layer.getElements(filter, 0, 0);

	int t = 0;
	while (it.hasNext()) {
		Assert.assertTrue("Returned object must be a SimpleFeature", it.next() instanceof SimpleFeature);
		t++;
	}
	Assert.assertEquals(1, t);
}
 
Example 8
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
@Before
public void setUp() {
    ff = CommonFactoryFinder.getFilterFactory2();

    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
    typeBuilder.setName("test");
    typeBuilder.add("stringAttr", String.class);
    typeBuilder.add("integerAttr", Integer.class);
    typeBuilder.add("longAttr", Long.class);
    typeBuilder.add("booleanAttr", Boolean.class);
    typeBuilder.add("doubleAttr", Double.class);
    typeBuilder.add("floatAttr", Float.class);
    typeBuilder.add("dateAttr", Date.class);

    AttributeDescriptor geoPointAtt;
    AttributeTypeBuilder geoPointAttBuilder = new AttributeTypeBuilder();
    geoPointAttBuilder.setName("geo_point");
    geoPointAttBuilder.setBinding(Point.class);
    geoPointAtt = geoPointAttBuilder.buildDescriptor("geo_point", geoPointAttBuilder.buildType());
    geoPointAtt.getUserData().put(GEOMETRY_TYPE, ElasticGeometryType.GEO_POINT);
    typeBuilder.add(geoPointAtt);

    AttributeDescriptor geoShapeAtt;
    AttributeTypeBuilder geoShapeAttBuilder = new AttributeTypeBuilder();
    geoShapeAttBuilder.setName("geom");
    geoShapeAttBuilder.setBinding(Geometry.class);
    geoShapeAtt = geoShapeAttBuilder.buildDescriptor("geom", geoShapeAttBuilder.buildType());
    geoShapeAtt.getUserData().put(GEOMETRY_TYPE, ElasticGeometryType.GEO_SHAPE);
    typeBuilder.add(geoShapeAtt);

    AttributeDescriptor analyzedAtt;
    AttributeTypeBuilder analyzedAttBuilder = new AttributeTypeBuilder();
    analyzedAttBuilder.setName("analyzed");
    analyzedAttBuilder.setBinding(String.class);
    analyzedAtt = analyzedAttBuilder.buildDescriptor("analyzed", analyzedAttBuilder.buildType());
    analyzedAtt.getUserData().put(ANALYZED, true);
    typeBuilder.add(analyzedAtt);

    AttributeDescriptor netsedAtt;
    AttributeTypeBuilder nestedAttBuilder = new AttributeTypeBuilder();
    nestedAttBuilder.setName("nested.hej");
    nestedAttBuilder.setBinding(String.class);
    netsedAtt = nestedAttBuilder.buildDescriptor("nested.hej", nestedAttBuilder.buildType());
    netsedAtt.getUserData().put(NESTED, true);
    netsedAtt.getUserData().put(ANALYZED, true);
    typeBuilder.add(netsedAtt);

    AttributeDescriptor netsedDateAtt;
    AttributeTypeBuilder nestedDateAttBuilder = new AttributeTypeBuilder();
    nestedDateAttBuilder.setName("nested.datehej");
    nestedDateAttBuilder.setBinding(Date.class);
    netsedDateAtt = nestedDateAttBuilder.buildDescriptor("nested.datehej", nestedDateAttBuilder.buildType());
    netsedDateAtt.getUserData().put(NESTED, true);
    typeBuilder.add(netsedDateAtt);

    featureType = typeBuilder.buildFeatureType();
    setFilterBuilder();

    parameters = new HashMap<>();
    final Hints hints = new Hints();
    hints.put(Hints.VIRTUAL_TABLE_PARAMETERS, parameters);
    query = new Query();
    query.setHints(hints);

    dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    gf = new GeometryFactory();
}