org.opengis.filter.spatial.Intersects Java Examples

The following examples show how to use org.opengis.filter.spatial.Intersects. 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: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 7 votes vote down vote up
@Test
public void testGeoShapeIntersectsFilter() throws CQLException {
    Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(\"geom\", LINESTRING(0 0,1.1 1.1))");
    List<List<Double>> coords = new ArrayList<>();
    coords.add(ImmutableList.of(0.,0.));
    coords.add(ImmutableList.of(1.1,1.1));
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_shape", 
                    ImmutableMap.of("geom", ImmutableMap.of("shape", 
                            ImmutableMap.of("coordinates", coords, "type", "LineString"),
                            "relation", "INTERSECTS")))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    // TODO: Why doesn't equality check on objects work here
    assertEquals(expected.toString(), builder.getQueryBuilder().toString());
}
 
Example #2
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoShapeIntersectsFilterReversed() throws CQLException {
    Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(LINESTRING(0 0,1.1 1.1), \"geom\")");
    List<List<Double>> coords = new ArrayList<>();
    coords.add(ImmutableList.of(0.,0.));
    coords.add(ImmutableList.of(1.1,1.1));
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_shape", 
                    ImmutableMap.of("geom", ImmutableMap.of("shape", 
                            ImmutableMap.of("coordinates", coords, "type", "LineString"),
                            "relation", "INTERSECTS")))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected.toString(), builder.getQueryBuilder().toString());
}
 
Example #3
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testGeoPolygonFilter() throws CQLException {
    Intersects filter = (Intersects) ECQL.toFilter("INTERSECTS(\"geo_point\", POLYGON((0 0, 0 1.1, 1.1 1.1, 1.1 0, 0 0)))");
    List<List<Double>> points = ImmutableList.of(
            ImmutableList.of(0.,0.),
            ImmutableList.of(0.,1.1),
            ImmutableList.of(1.1,1.1),
            ImmutableList.of(1.1,0.),
            ImmutableList.of(0.,0.));
    Map<String,Object> expected = ImmutableMap.of("bool", 
            ImmutableMap.of("must", MATCH_ALL, "filter", ImmutableMap.of("geo_polygon", 
                    ImmutableMap.of("geo_point", ImmutableMap.of("points", points)))));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #4
Source File: StyleConverterServiceTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testFilters() throws LayerException {
	Style style = styleConverterService.convert(layerBeansMixedGeometryStyleInfoSld.getUserStyle());
	List<Rule> rules = style.featureTypeStyles().get(0).rules();
	assertThat(rules.get(0).getFilter()).isInstanceOf(BBOX.class);
	assertThat(rules.get(1).getFilter()).isInstanceOf(Contains.class);
	assertThat(rules.get(2).getFilter()).isInstanceOf(Crosses.class);
	assertThat(rules.get(3).getFilter()).isInstanceOf(Disjoint.class);
	assertThat(rules.get(4).getFilter()).isInstanceOf(Equals.class);
	assertThat(rules.get(5).getFilter()).isInstanceOf(Intersects.class);
	assertThat(rules.get(6).getFilter()).isInstanceOf(Overlaps.class);
	assertThat(rules.get(7).getFilter()).isInstanceOf(Touches.class);
	assertThat(rules.get(8).getFilter()).isInstanceOf(Within.class);
	NamedStyleInfo namedStyleInfo = styleConverterService.convert(
			layerBeansMixedGeometryStyleInfoSld.getUserStyle(), featureInfo);
	Assert.assertEquals(9, namedStyleInfo.getFeatureStyles().size());
}
 
Example #5
Source File: ElasticCapabilities.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
public ElasticCapabilities() {
    super(new ElasticFilterCapabilities());

    addAll(LOGICAL_OPENGIS);
    addAll(SIMPLE_COMPARISONS_OPENGIS);
    addType(PropertyIsNull.class);
    addType(PropertyIsBetween.class);
    addType(Id.class);
    addType(IncludeFilter.class);
    addType(ExcludeFilter.class);
    addType(PropertyIsLike.class);

    // spatial filters
    addType(BBOX.class);
    addType(Contains.class);
    //addType(Crosses.class);
    addType(Disjoint.class);
    //addType(Equals.class);
    addType(Intersects.class);
    //addType(Overlaps.class);
    //addType(Touches.class);
    addType(Within.class);
    addType(DWithin.class);
    addType(Beyond.class);

    //temporal filters
    addType(After.class);
    addType(Before.class);
    addType(Begins.class);
    addType(BegunBy.class);
    addType(During.class);
    addType(Ends.class);
    addType(EndedBy.class);
    addType(TContains.class);
    addType(TEquals.class);
}
 
Example #6
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
private void visitGeoShapeBinarySpatialOperator(BinarySpatialOperator filter, Expression e1, Expression e2,
                                                boolean swapped, Object extraData) {

    SpatialRelation shapeRelation;
    if (filter instanceof Disjoint) {
        shapeRelation = SpatialRelation.DISJOINT;
    } else if ((!swapped && filter instanceof Within) || (swapped && filter instanceof Contains)) {
        shapeRelation = SpatialRelation.WITHIN;
    } else if (filter instanceof Intersects || filter instanceof BBOX) {
        shapeRelation = SpatialRelation.INTERSECTS;
    } else {
        FilterToElastic.LOGGER.fine(filter.getClass().getSimpleName() 
                + " is unsupported for geo_shape types");
        shapeRelation = null;
        delegate.fullySupported = false;
    }

    if (shapeRelation != null) {
        e1.accept(delegate, extraData);
        key = (String) delegate.field;
        e2.accept(delegate, extraData);
        shapeBuilder = delegate.currentShapeBuilder;
    }

    if (shapeRelation != null && shapeBuilder != null) {
        delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL, "filter",
                ImmutableMap.of("geo_shape", ImmutableMap.of(key,
                        ImmutableMap.of("shape", shapeBuilder, "relation", shapeRelation)))));
    } else {
        delegate.queryBuilder = MATCH_ALL;
    }
}
 
Example #7
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 #8
Source File: ElasticFilterTest.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEmptyGeoShape() {
    LineString ls = gf.createLineString(new Coordinate[0]);
    Intersects filter = ff.intersects(ff.property("geom"), ff.literal(ls));

    Map<String,Object> expected = ImmutableMap.of("bool", ImmutableMap.of("must_not",MATCH_ALL));

    builder.visit(filter, null);
    assertTrue(builder.createCapabilities().fullySupports(filter));
    assertEquals(expected, builder.getQueryBuilder());
}
 
Example #9
Source File: PropertyIgnoringFilterVisitor.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public Object visit(final Intersects filter, final Object extraData) {
  if (!usesProperty(filter)) {
    return Filter.INCLUDE;
  }
  return super.visit(filter, extraData);
}
 
Example #10
Source File: PropertyIgnoringFilterVisitor.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public Object visit(final Intersects filter, final Object extraData) {
  if (!usesProperty(filter)) {
    return Filter.INCLUDE;
  }
  return super.visit(filter, extraData);
}
 
Example #11
Source File: ExtractGeometryFilterVisitor.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public Object visit(final Intersects filter, Object data) {
  if (!attributeOfInterest.equals(filter.getExpression1().toString())) {
    return new ExtractGeometryFilterVisitorResult(infinity(), null);
  }
  data = filter.getExpression2().accept(this, data);
  return new ExtractGeometryFilterVisitorResult((Geometry) data, CompareOperation.INTERSECTS);
}
 
Example #12
Source File: FilterToElasticHelper.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
private void visitGeoPointBinarySpatialOperator(BinarySpatialOperator filter, Expression e1, Expression e2,
                                                boolean swapped, Object extraData) {

    e1.accept(delegate, extraData);
    key = (String) delegate.field;
    e2.accept(delegate, extraData);

    final Geometry geometry = delegate.currentGeometry;

    if (geometry instanceof Polygon &&
            ((!swapped && filter instanceof Within) 
                    || (swapped && filter instanceof Contains)
                    || filter instanceof Intersects)) {
        final Polygon polygon = (Polygon) geometry;
        final List<List<Double>> points = new ArrayList<>();
        for (final Coordinate coordinate : polygon.getCoordinates()) {
            points.add(ImmutableList.of(coordinate.x, coordinate.y));
        }
        delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL,
                "filter", ImmutableMap.of("geo_polygon", 
                        ImmutableMap.of(key, ImmutableMap.of("points", points)))));
    } else if (filter instanceof BBOX) {
        final BoundingBox envelope = ((BBOX) filter).getBounds();
        final double minY = clipLat(envelope.getMinY());
        final double maxY = clipLat(envelope.getMaxY());
        final double minX, maxX;
        if (envelope.getWidth() < 360) {
            minX = clipLon(envelope.getMinX());
            maxX = clipLon(envelope.getMaxX());
        } else {
            minX = -180;
            maxX = 180;
        }
        delegate.queryBuilder = ImmutableMap.of("bool", ImmutableMap.of("must", MATCH_ALL,
                "filter", ImmutableMap.of("geo_bounding_box", ImmutableMap.of(key, 
                        ImmutableMap.of("top_left", ImmutableList.of(minX, maxY), 
                                "bottom_right", ImmutableList.of(maxX, minY))))));
    } else {
        FilterToElastic.LOGGER.fine(filter.getClass().getSimpleName() 
                + " is unsupported for geo_point types");
        delegate.fullySupported = false;
        delegate.queryBuilder = MATCH_ALL;
    }
}
 
Example #13
Source File: FilterToElastic.java    From elasticgeo with GNU General Public License v3.0 4 votes vote down vote up
public Object visit(Intersects filter, Object extraData) {
    return visitBinarySpatialOperator(filter, extraData);
}
 
Example #14
Source File: ExtractTimeFilterVisitor.java    From geowave with Apache License 2.0 4 votes vote down vote up
@Override
public Object visit(final Intersects filter, final Object data) {
  return new TemporalConstraints();
}
 
Example #15
Source File: CriteriaVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public Object visit(Intersects filter, Object userData) {
	String finalName = parsePropertyName(geomName, userData);
	return SpatialRestrictions.intersects(finalName, asGeometry(getLiteralValue(filter.getExpression2())));
}