Search in sources :

Example 1 with GeospatialPredicate

use of ddf.catalog.pubsub.predicate.GeospatialPredicate in project ddf by codice.

the class PredicateTest method testGeospatialEvaluatorPointRadiusContains.

@Test
public void testGeospatialEvaluatorPointRadiusContains() throws Exception {
    LOGGER.debug("**************************  START: testGeospatialEvaluator_PointRadius_Contains()  ***********************");
    // WKT specifies points in LON LAT order
    String geometryWkt = "POINT (44.5 34.5)";
    String operation = "point_radius";
    // 0.6 degrees
    double distance = 0.6 * NM_PER_DEG_LAT * METERS_PER_NM;
    // latitude in
    // meters
    double radiusInDegrees = (distance * 180.0) / (Math.PI * EQUATORIAL_RADIUS_IN_METERS);
    LOGGER.debug("distance (in meters) = " + distance + ",   radiusInDegrees = " + radiusInDegrees);
    GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, radiusInDegrees);
    Geometry geoCriteria = predicate.getGeoCriteria();
    LOGGER.debug("geoCriteria.toText() = {}", geoCriteria.toText());
    String geospatialXml = "<gml:Polygon xmlns:gml=\"http://www.opengis.net/gml\" gml:id=\"BGE-1\">\n" + "    <gml:exterior>\n" + "        <gml:LinearRing>\n" + "            <gml:pos>34.0 44.0</gml:pos>\n" + "            <gml:pos>33.0 44.0</gml:pos>\n" + "            <gml:pos>33.0 45.0</gml:pos>\n" + "            <gml:pos>34.0 45.0</gml:pos>\n" + "            <gml:pos>34.0 44.0</gml:pos>\n" + "        </gml:LinearRing>\n" + "    </gml:exterior>\n" + "</gml:Polygon>";
    Geometry input = GeospatialEvaluator.buildGeometry(geospatialXml);
    LOGGER.debug("input.toText() = {}", input.toText());
    GeospatialEvaluationCriteria gec = new GeospatialEvaluationCriteriaImpl(geoCriteria, operation, input, radiusInDegrees);
    boolean status = GeospatialEvaluator.evaluate(gec);
    assertTrue(status);
    LOGGER.debug("**************************  END: testGeospatialEvaluator_PointRadius_Contains()  ***********************");
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeospatialEvaluationCriteria(ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) GeospatialEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteriaImpl) Test(org.junit.Test)

Example 2 with GeospatialPredicate

use of ddf.catalog.pubsub.predicate.GeospatialPredicate in project ddf by codice.

the class SubscriptionFilterVisitor method visit.

/**
 * Intersects filter maps to a OVERLAPS Spatial search criteria.
 */
@Override
public Object visit(Intersects filter, Object data) {
    LOGGER.debug("ENTERING: Intersects filter");
    LOGGER.debug("Must have received OVERLAPS query criteria.");
    org.locationtech.jts.geom.Geometry jtsGeometry = getJtsGeometery((LiteralExpressionImpl) filter.getExpression2());
    Predicate predicate = new GeospatialPredicate(jtsGeometry, SpatialOperator.OVERLAPS.name(), 0.0);
    LOGGER.debug("EXITING: Intersects filter");
    return predicate;
}
Also used : GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) EntryPredicate(ddf.catalog.pubsub.predicate.EntryPredicate) TemporalPredicate(ddf.catalog.pubsub.predicate.TemporalPredicate) ContextualPredicate(ddf.catalog.pubsub.predicate.ContextualPredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate)

Example 3 with GeospatialPredicate

use of ddf.catalog.pubsub.predicate.GeospatialPredicate in project ddf by codice.

the class PredicateTest method testGeospatialPredicateNullMetadata.

@Test
public void testGeospatialPredicateNullMetadata() throws IOException {
    String methodName = "testGeospatialPredicateNullMetadata()";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    String geometryWkt = "POLYGON ((40 34, 40 33, 44.5 33, 44.5 34, 40 34))";
    String operation = "overlaps";
    double distance = 0.0000001;
    GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, distance);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("POINT (41 34)");
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    // No Contextual map added to properties containing indexed metadata
    Event testEvent = new Event("topic", properties);
    assertTrue(predicate.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : HashMap(java.util.HashMap) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 4 with GeospatialPredicate

use of ddf.catalog.pubsub.predicate.GeospatialPredicate in project ddf by codice.

the class PredicateTest method testGeospatialPredicateNullOperation.

@Test
public void testGeospatialPredicateNullOperation() throws IOException {
    String methodName = "testGeospatialPredicateNullOperation";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    String geometryWkt = "POLYGON ((40 34, 40 33, 44.5 33, 44.5 34, 40 34))";
    String operation = "overlaps";
    double distance = 0.0000001;
    GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, distance);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("POINT (41 34)");
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, null);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    Event testEvent = new Event("topic", properties);
    assertTrue(predicate.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : HashMap(java.util.HashMap) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 5 with GeospatialPredicate

use of ddf.catalog.pubsub.predicate.GeospatialPredicate in project ddf by codice.

the class PredicateTest method testGeospatialEvaluatorPointRadiusNotContains.

@Test
public void testGeospatialEvaluatorPointRadiusNotContains() throws Exception {
    LOGGER.debug("**************************  START: testGeospatialEvaluator_PointRadius_NotContains()  ***********************");
    // WKT specifies points in LON LAT order
    String geometryWkt = "POINT (44.5 34.5)";
    String operation = "point_radius";
    double distance = 500.0;
    double radiusInDegrees = (distance * 180.0) / (Math.PI * EQUATORIAL_RADIUS_IN_METERS);
    GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, radiusInDegrees);
    Geometry geoCriteria = predicate.getGeoCriteria();
    LOGGER.debug("geoCriteria.toText() {}", geoCriteria.toText());
    String geospatialXml = "<gml:Polygon xmlns:gml=\"http://www.opengis.net/gml\" gml:id=\"BGE-1\">\n" + "    <gml:exterior>\n" + "        <gml:LinearRing>\n" + "            <gml:pos>24.0 22.0</gml:pos>\n" + "            <gml:pos>23.0 22.0</gml:pos>\n" + "            <gml:pos>23.0 24.0</gml:pos>\n" + "            <gml:pos>24.0 24.0</gml:pos>\n" + "            <gml:pos>24.0 22.0</gml:pos>\n" + "        </gml:LinearRing>\n" + "    </gml:exterior>\n" + "</gml:Polygon>";
    Geometry input = GeospatialEvaluator.buildGeometry(geospatialXml);
    LOGGER.debug("input.toText() = {}", input.toText());
    GeospatialEvaluationCriteria gec = new GeospatialEvaluationCriteriaImpl(geoCriteria, operation, input, radiusInDegrees);
    boolean status = GeospatialEvaluator.evaluate(gec);
    assertFalse(status);
    LOGGER.debug("**************************  END: testGeospatialEvaluator_PointRadius_NotContains()  ***********************");
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeospatialEvaluationCriteria(ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) GeospatialEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteriaImpl) Test(org.junit.Test)

Aggregations

GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)8 Test (org.junit.Test)5 GeospatialEvaluationCriteria (ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria)3 GeospatialEvaluationCriteriaImpl (ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteriaImpl)3 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)3 ContextualPredicate (ddf.catalog.pubsub.predicate.ContextualPredicate)3 EntryPredicate (ddf.catalog.pubsub.predicate.EntryPredicate)3 Predicate (ddf.catalog.pubsub.predicate.Predicate)3 TemporalPredicate (ddf.catalog.pubsub.predicate.TemporalPredicate)3 Geometry (org.locationtech.jts.geom.Geometry)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 HashMap (java.util.HashMap)2 Event (org.osgi.service.event.Event)2