org.opengis.filter.FilterFactory2 Java Examples

The following examples show how to use org.opengis.filter.FilterFactory2. 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: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDisjointFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
    Disjoint f = ff.disjoint(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(2, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.13");
}
 
Example #3
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoShapeAsWkt() throws Exception {
    if (client.getVersion() < 6.2) {
        // wkt unsupported prior to v6.2
        return;
    }
    init("not-active","geo6");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 2, 2 }, 2));
    Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");

    sf = new PackedCoordinateSequenceFactory();
    ls = gf.createLineString(sf.create(new double[] { 0, 0, 1, 1 }, 2));
    f = ff.crosses(ff.property("geo5"), ff.literal(ls));
    features = featureSource.getFeatures(f);
    assertEquals(0, features.size());
}
 
Example #4
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoPointAsArray() throws Exception {
    init("active","geo5");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
    DWithin f = ff.dwithin(ff.property("geo5"), ff.literal(ls), 3, "m");
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(2, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    SimpleFeature feature = fsi.next();
    assertEquals(feature.getID(), "active.01");
    assertNotNull(feature.getDefaultGeometry());
    assertTrue(fsi.hasNext());
    feature = fsi.next();
    assertEquals(feature.getID(), "active.10");
    assertNotNull(feature.getDefaultGeometry());
}
 
Example #5
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testOgrStyleGeoPoint() throws Exception {
    init("not-active","geo4.coordinates");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    BBOX bbox = ff.bbox("geo4.coordinates", 0, 0, 5, 5, "EPSG:4326");
    assertNotNull(featureSource.getSchema().getDescriptor("geo4.coordinates"));
    assertNull(featureSource.getSchema().getDescriptor("geo4.type"));

    SimpleFeatureCollection features = featureSource.getFeatures(bbox);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    SimpleFeature feature = fsi.next();
    assertEquals(feature.getID(), "active.13");
    assertNotNull(feature.getDefaultGeometry());
}
 
Example #6
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAlternateGeometry() throws Exception {
    init("active", "geo2");
    SimpleFeatureType schema = featureSource.getSchema();
    GeometryDescriptor gd = schema.getGeometryDescriptor();
    assertNotNull(gd);
    assertEquals("geo2", gd.getLocalName());

    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    BBOX bbox = ff.bbox("geo2", 6.5, 23.5, 7.5, 24.5, "EPSG:4326");
    SimpleFeatureCollection features = featureSource.getFeatures(bbox);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.09");
}
 
Example #7
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDWithinFilter() throws Exception {
    init();
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
    DWithin f = ff.dwithin(ff.property("geo"), ff.literal(ls), 3, "m");
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(2, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.01");
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.10");
}
 
Example #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testBeyondFilter() throws Exception {
    init();
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 0, 0 }, 2));
    Beyond f = ff.beyond(ff.property("geo"), ff.literal(ls), 1, "m");
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(9, features.size());
}
 
Example #15
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testContainsFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Polygon ls = gf.createPolygon(sf.create(new double[] { 2, 2, 3, 2, 3, 3, 2, 3, 2, 2 }, 2));
    Contains f = ff.contains(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
}
 
Example #16
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testIntersectsFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Polygon ls = gf.createPolygon(sf.create(new double[] { 6, 6, 7, 6, 7, 7, 6, 7, 6, 6 }, 2));
    Intersects f = ff.intersects(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.13");
}
 
Example #17
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testOverlapsFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Polygon ls = gf.createPolygon(sf.create(
            new double[] { 5.5, 6, 7, 6, 7, 7, 5.5, 7, 5.5, 6 }, 2));
    Overlaps f = ff.overlaps(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.13");
}
 
Example #18
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testWithinFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Polygon ls = gf.createPolygon(sf.create(new double[] { 0, 0, 0, 6, 6, 6, 6, 0, 0, 0 }, 2));
    Within f = ff.within(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
}
 
Example #19
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testTouchesFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Point ls = gf.createPoint(sf.create(new double[] { 1, 1 }, 2));
    Touches f = ff.touches(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
}
 
Example #20
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEqualFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Polygon ls = gf.createPolygon(sf.create(new double[] { 3, 2, 6, 2, 6, 7, 3, 7, 3, 2 }, 2));
    Equals f = ff.equal(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.13");
}
 
Example #21
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testNotCrossesFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 1, 1 }, 2));
    Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(0, features.size());
}
 
Example #22
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testCrossesFilter() throws Exception {
    init("not-active","geo3");
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    LineString ls = gf.createLineString(sf.create(new double[] { 0, 0, 2, 2 }, 2));
    Crosses f = ff.crosses(ff.property("geo3"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.12");
}
 
Example #23
Source File: ElasticGeometryFilterIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testWithinPolygonFilter() throws Exception {
    init();
    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    GeometryFactory gf = new GeometryFactory();
    PackedCoordinateSequenceFactory sf = new PackedCoordinateSequenceFactory();
    Polygon ls = gf.createPolygon(sf.create(new double[] { -180, -90, 180, -90, 180, 90, -180, 90, -180, -90 }, 2));
    Within f = ff.within(ff.property("geo"), ff.literal(ls));
    SimpleFeatureCollection features = featureSource.getFeatures(f);
    assertEquals(11, features.size());
}