Search in sources :

Example 11 with PointImpl

use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.

the class OpenSearchFilterVisitor method visit.

/**
     * DWithin filter maps to a Point/Radius distance Spatial search criteria.
     */
@Override
public Object visit(DWithin filter, Object data) {
    LOGGER.trace("ENTERING: DWithin filter");
    if (currentNest == null || NestedTypes.AND.equals(currentNest)) {
        // The geometric point is wrapped in a <Literal> element, so have to
        // get geometry expression as literal and then evaluate it to get
        // the geometry.
        // Example:
        // <ogc:Literal>org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl@dc33f184</ogc:Literal>
        Literal literalWrapper = (Literal) filter.getExpression2();
        // Luckily we know what type the geometry expression should be, so
        // we
        // can cast it
        PointImpl point = (PointImpl) literalWrapper.evaluate(null);
        double[] coords = point.getCentroid().getCoordinate();
        double distance = filter.getDistance();
        LOGGER.debug("point: coords[0] = {},   coords[1] = {}", coords[0], coords[1]);
        LOGGER.debug("radius = {}", distance);
        this.spatialSearch = new SpatialDistanceFilter(coords[0], coords[1], distance);
        filters.add(filter);
    } else {
        LOGGER.debug(ONLY_AND_MSG);
    }
    LOGGER.trace("EXITING: DWithin filter");
    return super.visit(filter, data);
}
Also used : PropertyIsEqualToLiteral(ddf.catalog.filter.impl.PropertyIsEqualToLiteral) Literal(org.opengis.filter.expression.Literal) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)

Example 12 with PointImpl

use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.

the class GeoResultCreator method createGeoResult.

public static GeoResult createGeoResult(final String name, final double latitude, final double longitude, final String featureCode, final double population) {
    double offset = 0.1;
    if (featureCode != null) {
        if (featureCode.startsWith(ADMINISTRATIVE_DIVISION)) {
            offset = getOffsetAdministrativeDivision(featureCode);
        } else if (featureCode.startsWith(POLITICAL_ENTITY)) {
            offset = getOffsetPoliticalEntity(population);
        } else if (featureCode.startsWith(POPULATED_PLACE)) {
            offset = getOffsetPopulatedPlace(population);
        }
    }
    final DirectPosition northWest = new DirectPositionImpl(longitude - offset, latitude + offset);
    final DirectPosition southEast = new DirectPositionImpl(longitude + offset, latitude - offset);
    final List<Point> bbox = new ArrayList<>();
    bbox.add(new PointImpl(northWest));
    bbox.add(new PointImpl(southEast));
    final DirectPosition directPosition = new DirectPositionImpl(longitude, latitude);
    final GeoResult geoResult = new GeoResult();
    geoResult.setPoint(new PointImpl(directPosition));
    geoResult.setBbox(bbox);
    geoResult.setFullName(name);
    return geoResult;
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) DirectPositionImpl(org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl) ArrayList(java.util.ArrayList) Point(org.opengis.geometry.primitive.Point) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)

Example 13 with PointImpl

use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.

the class GeoResultCreatorTest method verifyGeoResult.

private void verifyGeoResult(final String name, final double latitude, final double longitude, final double expectedLatitudeOffset, final double expectedLongitudeOffset, final GeoResult geoResult) {
    assertThat(geoResult.fullName, is(equalTo(name)));
    final Point point = new PointImpl(new DirectPositionImpl(longitude, latitude));
    assertThat(geoResult.point, is(equalTo(point)));
    assertThat(geoResult.bbox.size(), is(2));
    assertEquals(geoResult.bbox.get(0).getDirectPosition().getCoordinate()[0], longitude - expectedLongitudeOffset, 0.001);
    assertEquals(geoResult.bbox.get(0).getDirectPosition().getCoordinate()[1], latitude + expectedLatitudeOffset, 0.001);
    assertEquals(geoResult.bbox.get(1).getDirectPosition().getCoordinate()[0], longitude + expectedLongitudeOffset, 0.001);
    assertEquals(geoResult.bbox.get(1).getDirectPosition().getCoordinate()[1], latitude - expectedLatitudeOffset, 0.001);
}
Also used : DirectPositionImpl(org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl) Point(org.opengis.geometry.primitive.Point) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)

Example 14 with PointImpl

use of org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl in project ddf by codice.

the class SolrProviderSpatial method testSpatialPointRadius.

@Test
public void testSpatialPointRadius() throws Exception {
    deleteAll(provider);
    MetacardImpl metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    MetacardImpl metacard2 = new MockMetacard(Library.getTampaRecord());
    MetacardImpl metacard3 = new MockMetacard(Library.getShowLowRecord());
    // Add in the geometry
    metacard1.setLocation(Library.FLAGSTAFF_AIRPORT_POINT_WKT);
    metacard2.setLocation(Library.TAMPA_AIRPORT_POINT_WKT);
    metacard3.setLocation(Library.SHOW_LOW_AIRPORT_POINT_WKT);
    List<Metacard> list = Arrays.asList(metacard1, metacard2, metacard3);
    // CREATE
    create(list, provider);
    Filter filter = getFilterBuilder().attribute(Metacard.ID).is().like().text("*");
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
    assertEquals("Failed to find all records.", 3, sourceResponse.getResults().size());
    // Right on Flagstaff
    QueryImpl query = pointRadius(-111.67121887207031, 35.138454437255859, 10.0);
    query.setPageSize(1);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals("Failed to find Flagstaff record only.", 1, sourceResponse.getResults().size());
    for (Result r : sourceResponse.getResults()) {
        assertTrue("Wrong record, Flagstaff keyword was not found.", r.getMetacard().getMetadata().contains(Library.FLAGSTAFF_QUERY_PHRASE));
        LOGGER.info("Distance to Flagstaff: {}", r.getDistanceInMeters());
    // assertTrue(r.getDistanceInMeters() != null);
    }
    // Right on Flagstaff, finding 2 records with 195 km radius
    query = pointRadius(-111.67121887207031, 35.138454437255859, 195000);
    query.setSortBy(new ddf.catalog.filter.impl.SortByImpl("foo", SortOrder.ASCENDING));
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals("Failed to find the two records.", 2, sourceResponse.getResults().size());
    ArrayList<Result> results = new ArrayList<>(sourceResponse.getResults());
    // querybuilder
    for (int i = 0; i < 2; i++) {
        Result result = results.get(i);
        LOGGER.info("Distance of [{}]]: {}", i, result.getDistanceInMeters());
        if (i == 0) {
            assertTrue("Grabbed the wrong record.", result.getMetacard().getMetadata().contains(Library.FLAGSTAFF_QUERY_PHRASE));
        }
        if (i == 1) {
            assertTrue("Grabbed the wrong record - should be Show Low.", result.getMetacard().getMetadata().contains("Show Low"));
        }
    }
    // NEGATIVE CASE
    query = pointRadius(80.1, 25, 195000);
    query.setPageSize(3);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals("Should have not found any records.", 0, sourceResponse.getResults().size());
    // FEET
    double[] coords = { -111.67121887207031, 35.138454437255859 };
    query = new QueryImpl(filterFactory.dwithin(Metacard.ANY_GEO, new PointImpl(new DirectPositionImpl(coords), DefaultGeographicCRS.WGS84), 195000, UomOgcMapping.FOOT.name()));
    query.setStartIndex(1);
    SortByImpl sortby = new SortByImpl(filterFactory.property(Result.DISTANCE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortby);
    query.setPageSize(3);
    sourceResponse = provider.query(new QueryRequestImpl(query));
    assertEquals(1, sourceResponse.getResults().size());
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) DirectPositionImpl(org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) SortByImpl(org.geotools.filter.SortByImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) Test(org.junit.Test)

Aggregations

PointImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)14 DirectPositionImpl (org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl)9 Test (org.junit.Test)7 Filter (org.opengis.filter.Filter)5 Literal (org.opengis.filter.expression.Literal)5 Point (org.opengis.geometry.primitive.Point)5 QueryImpl (ddf.catalog.operation.impl.QueryImpl)4 SortByImpl (org.geotools.filter.SortByImpl)4 TemporalFilter (ddf.catalog.impl.filter.TemporalFilter)3 ArrayList (java.util.ArrayList)3 DWithinImpl (org.geotools.filter.spatial.DWithinImpl)3 Metacard (ddf.catalog.data.Metacard)2 Result (ddf.catalog.data.Result)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 SourceResponse (ddf.catalog.operation.SourceResponse)2 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)2 HashMap (java.util.HashMap)2 BBoxSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.BBoxSpatialFilter)2 PolygonSpatialFilter (org.codice.ddf.opensearch.endpoint.query.filter.PolygonSpatialFilter)2 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)2