Search in sources :

Example 1 with DirectPositionImpl

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

the class CommonQueryBuilder method pointRadius.

/**
     * Creates a point radius {@link QueryImpl} with units of measurement of meters.
     *
     * @param x
     * @param y
     * @param distance
     * @return
     */
// public QueryImpl pointRadius(double x, double y, double distance) {
//
// double[] coords = {x, y} ;
//
// QueryImpl query = new QueryImpl(
// filterFactory.dwithin(
// Metacard.ANY_GEO,
// new PointImpl(new DirectPositionImpl(coords), DefaultGeographicCRS.WGS84),
// distance,
// UomOgcMapping.METRE.name()));
//
// query.setStartIndex(1) ;
//
// SortByImpl sortby = new SortByImpl(filterFactory.property(Result.DISTANCE),
// org.opengis.filter.sort.SortOrder.ASCENDING);
// query.setSortBy(sortby) ;
//
// return query;
// }
// public QueryImpl intersects(double x, double y) {
//
// double[] coords = {x, y} ;
//
// QueryImpl query = new QueryImpl( filterFactory.intersects(Metacard.ANY_GEO, new PointImpl(new
// DirectPositionImpl(coords), DefaultGeographicCRS.WGS84)));
//
// query.setStartIndex(1) ;
//
// query.setRequestsTotalResultsCount(true);
//
// return query;
//
// }
/**
     * Creates a point radius {@link QueryImpl} with units of measurement of meters.
     *
     * @param x
     * @param y
     * @param distance
     * @return
     */
public QueryImpl pointRadius(double x, double y, double distance) {
    double[] coords = { x, y };
    QueryImpl query = new QueryImpl(filterFactory.dwithin(Metacard.ANY_GEO, new PointImpl(new DirectPositionImpl(coords), DefaultGeographicCRS.WGS84), distance, UomOgcMapping.METRE.name()));
    query.setStartIndex(1);
    SortByImpl sortby = new SortByImpl(filterFactory.property(Result.DISTANCE), org.opengis.filter.sort.SortOrder.ASCENDING);
    query.setSortBy(sortby);
    return query;
}
Also used : DirectPositionImpl(org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SortByImpl(org.geotools.filter.SortByImpl) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)

Example 2 with DirectPositionImpl

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

the class TestGeoResultCreator method verifyGeoResult.

private void verifyGeoResult(final String name, final double latitude, final double longitude, final String featureCode, final long population, final double expectedLatitudeOffset, final double expectedLongitudeOffset) {
    final GeoResult geoResult = GeoResultCreator.createGeoResult(name, latitude, longitude, featureCode, population);
    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 3 with DirectPositionImpl

use of org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl 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 latitudeOffset = 0;
    double longitudeOffset = 0;
    if (featureCode.startsWith(GeoCodingConstants.ADMINISTRATIVE_DIVISION)) {
        if (featureCode.endsWith(GeoCodingConstants.DIVISION_FIRST_ORDER)) {
            latitudeOffset = longitudeOffset = 5;
        } else if (featureCode.endsWith(GeoCodingConstants.DIVISION_SECOND_ORDER)) {
            latitudeOffset = longitudeOffset = 4;
        } else if (featureCode.endsWith(GeoCodingConstants.DIVISION_THIRD_ORDER)) {
            latitudeOffset = longitudeOffset = 3;
        } else if (featureCode.endsWith(GeoCodingConstants.DIVISION_FOURTH_ORDER)) {
            latitudeOffset = longitudeOffset = 2;
        } else if (featureCode.endsWith(GeoCodingConstants.DIVISION_FIFTH_ORDER)) {
            latitudeOffset = longitudeOffset = 1;
        }
    } else if (featureCode.startsWith(GeoCodingConstants.POLITICAL_ENTITY)) {
        latitudeOffset = longitudeOffset = 6;
        if (population > 100000000) {
            latitudeOffset *= 2;
            longitudeOffset *= 2;
        } else if (population > 10000000) {
            latitudeOffset *= 1;
            longitudeOffset *= 1;
        } else if (population > 1000000) {
            latitudeOffset *= 0.8;
            longitudeOffset *= 0.8;
        } else if (population > 0) {
            latitudeOffset *= 0.5;
            longitudeOffset *= 0.5;
        }
    } else if (featureCode.startsWith(GeoCodingConstants.POPULATED_PLACE)) {
        latitudeOffset = longitudeOffset = 0.5;
        if (population > 10000000) {
            latitudeOffset *= 1.5;
            longitudeOffset *= 1.5;
        } else if (population > 1000000) {
            latitudeOffset *= 0.8;
            longitudeOffset *= 0.8;
        } else if (population > 100000) {
            latitudeOffset *= 0.5;
            longitudeOffset *= 0.5;
        } else if (population > 10000) {
            latitudeOffset *= 0.3;
            longitudeOffset *= 0.3;
        } else if (population > 0) {
            latitudeOffset *= 0.2;
            longitudeOffset *= 0.2;
        }
    } else {
        latitudeOffset = longitudeOffset = 0.1;
    }
    final DirectPosition northWest = new DirectPositionImpl(longitude - longitudeOffset, latitude + latitudeOffset);
    final DirectPosition southEast = new DirectPositionImpl(longitude + longitudeOffset, latitude - latitudeOffset);
    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 4 with DirectPositionImpl

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

the class TestGeoNamesLocalIndex method testWithResults.

@Test
public void testWithResults() throws GeoEntryQueryException {
    final List<GeoEntry> topResults = Arrays.asList(GEO_ENTRY_1, GEO_ENTRY_2);
    doReturn(topResults).when(geoEntryQueryable).query("Phoenix", 1);
    final GeoResult geoResult = geoNamesLocalIndex.getLocation("Phoenix");
    assertThat(geoResult.getFullName(), is(equalTo(GEO_ENTRY_1.getName())));
    final Point point = new PointImpl(new DirectPositionImpl(GEO_ENTRY_1.getLongitude(), GEO_ENTRY_1.getLatitude()));
    assertThat(geoResult.getPoint(), is(equalTo(point)));
}
Also used : DirectPositionImpl(org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl) GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) GeoResult(org.codice.ddf.spatial.geocoder.GeoResult) Point(org.opengis.geometry.primitive.Point) PointImpl(org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl) Test(org.junit.Test)

Example 5 with DirectPositionImpl

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

the class SolrProviderTest method testSpatialPointRadius.

@Test
public void testSpatialPointRadius() throws Exception {
    deleteAllIn(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(FLAGSTAFF_AIRPORT_POINT_WKT);
    metacard2.setLocation(TAMPA_AIRPORT_POINT_WKT);
    metacard3.setLocation(SHOW_LOW_AIRPORT_POINT_WKT);
    List<Metacard> list = Arrays.asList((Metacard) metacard1, metacard2, metacard3);
    /** CREATE **/
    create(list);
    Filter filter = filterBuilder.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());
    CommonQueryBuilder builder = new CommonQueryBuilder();
    // Right on Flagstaff
    QueryImpl query = builder.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.", ALL_RESULTS != r.getMetacard().getMetadata().indexOf(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 = builder.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<Result>();
    for (Result r : sourceResponse.getResults()) {
        results.add(r);
    }
    // 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.", ALL_RESULTS != result.getMetacard().getMetadata().indexOf(FLAGSTAFF_QUERY_PHRASE));
        }
        if (i == 1) {
            assertTrue("Grabbed the wrong record - should be Show Low.", ALL_RESULTS != result.getMetacard().getMetadata().indexOf("Show Low"));
        }
    }
    // NEGATIVE CASE
    query = builder.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(builder.filterFactory.dwithin(Metacard.ANY_GEO, new PointImpl(new DirectPositionImpl(coords), DefaultGeographicCRS.WGS84), 195000, UomOgcMapping.FOOT.name()));
    query.setStartIndex(1);
    SortByImpl sortby = new SortByImpl(builder.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) Test(org.junit.Test)

Aggregations

DirectPositionImpl (org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl)5 PointImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)5 Point (org.opengis.geometry.primitive.Point)3 QueryImpl (ddf.catalog.operation.impl.QueryImpl)2 ArrayList (java.util.ArrayList)2 SortByImpl (org.geotools.filter.SortByImpl)2 Test (org.junit.Test)2 Metacard (ddf.catalog.data.Metacard)1 Result (ddf.catalog.data.Result)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 GeoResult (org.codice.ddf.spatial.geocoder.GeoResult)1 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)1 Filter (org.opengis.filter.Filter)1 DirectPosition (org.opengis.geometry.DirectPosition)1