Java源码示例:org.opengis.filter.spatial.Intersects
示例1
@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());
}
示例2
@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());
}
示例3
@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());
}
示例4
@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());
}
示例5
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);
}
示例6
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;
}
}
示例7
@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");
}
示例8
@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());
}
示例9
@Override
public Object visit(final Intersects filter, final Object extraData) {
if (!usesProperty(filter)) {
return Filter.INCLUDE;
}
return super.visit(filter, extraData);
}
示例10
@Override
public Object visit(final Intersects filter, final Object extraData) {
if (!usesProperty(filter)) {
return Filter.INCLUDE;
}
return super.visit(filter, extraData);
}
示例11
@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);
}
示例12
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;
}
}
示例13
public Object visit(Intersects filter, Object extraData) {
return visitBinarySpatialOperator(filter, extraData);
}
示例14
@Override
public Object visit(final Intersects filter, final Object data) {
return new TemporalConstraints();
}
示例15
/** {@inheritDoc} */
@Override
public Object visit(Intersects filter, Object userData) {
String finalName = parsePropertyName(geomName, userData);
return SpatialRestrictions.intersects(finalName, asGeometry(getLiteralValue(filter.getExpression2())));
}