Search in sources :

Example 1 with GeospatialEvaluationCriteria

use of ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria in project ddf by codice.

the class GeospatialPredicate method matches.

public boolean matches(Event properties) {
    Metacard entry = (Metacard) properties.getProperty(PubSubConstants.HEADER_ENTRY_KEY);
    Map<String, Object> contextualMap = (Map<String, Object>) properties.getProperty(PubSubConstants.HEADER_CONTEXTUAL_KEY);
    String operation = (String) properties.getProperty(PubSubConstants.HEADER_OPERATION_KEY);
    LOGGER.debug("operation = {}", operation);
    if (contextualMap != null) {
        String metadata = (String) contextualMap.get("METADATA");
        // cannot apply any geospatial filtering - just send the event on to the subscriber
        if (PubSubConstants.DELETE.equals(operation) && PubSubConstants.METADATA_DELETED.equals(metadata)) {
            LOGGER.debug("Detected a DELETE operation where metadata is just the word 'deleted', so send event on to subscriber");
            return true;
        }
    }
    GeospatialEvaluationCriteria gec;
    try {
        gec = new GeospatialEvaluationCriteriaImpl(geoCriteria, geoOperation, entry.getLocation(), distance);
        return GeospatialEvaluator.evaluate(gec);
    } catch (ParseException e) {
        LOGGER.debug("Error parsing WKT string.  Unable to compare geos.  Returning false.");
        return false;
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) GeospatialEvaluationCriteria(ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria) GeospatialEvaluationCriteriaImpl(ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteriaImpl) ParseException(com.vividsolutions.jts.io.ParseException) Map(java.util.Map)

Example 2 with GeospatialEvaluationCriteria

use of ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria 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(com.vividsolutions.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 3 with GeospatialEvaluationCriteria

use of ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria 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 = 5000.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(com.vividsolutions.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 4 with GeospatialEvaluationCriteria

use of ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria in project ddf by codice.

the class PredicateTest method testGeospatialEvaluatorOverlaps.

@Test
public void testGeospatialEvaluatorOverlaps() throws Exception {
    LOGGER.debug("**************************  START: testGeospatialEvaluator_Overlaps()  ***********************");
    // WKT specifies points in LON LAT order
    String geometryWkt = "POLYGON ((40 34, 40 33, 44.5 33, 44.5 34, 40 34))";
    String operation = "overlaps";
    double distance = 0.0;
    GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, distance);
    Geometry geoCriteria = predicate.getGeoCriteria();
    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, distance);
    boolean status = GeospatialEvaluator.evaluate(gec);
    assertTrue(status);
    LOGGER.debug("**************************  END: testGeospatialEvaluator_Overlaps()  ***********************");
}
Also used : Geometry(com.vividsolutions.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

GeospatialEvaluationCriteria (ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteria)4 GeospatialEvaluationCriteriaImpl (ddf.catalog.pubsub.criteria.geospatial.GeospatialEvaluationCriteriaImpl)4 Geometry (com.vividsolutions.jts.geom.Geometry)3 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)3 Test (org.junit.Test)3 ParseException (com.vividsolutions.jts.io.ParseException)1 Metacard (ddf.catalog.data.Metacard)1 Map (java.util.Map)1