Search in sources :

Example 1 with Point

use of org.opengis.geometry.primitive.Point 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 2 with Point

use of org.opengis.geometry.primitive.Point 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 3 with Point

use of org.opengis.geometry.primitive.Point in project ddf by codice.

the class GeoCoderEndpoint method transformGeoResult.

void transformGeoResult(GeoResult geoResult, JSONArray resources) {
    DirectPosition directPosition = geoResult.getPoint().getDirectPosition();
    double[] coords = directPosition.getCoordinate();
    double longitude = coords[0];
    double latitude = coords[1];
    JSONObject resource = new JSONObject();
    JSONArray bbox = new JSONArray();
    List<Point> points = geoResult.getBbox();
    DirectPosition upperCorner = points.get(0).getDirectPosition();
    DirectPosition lowerCorner = points.get(1).getDirectPosition();
    bbox.add(upperCorner.getCoordinate()[1]);
    bbox.add(upperCorner.getCoordinate()[0]);
    bbox.add(lowerCorner.getCoordinate()[1]);
    bbox.add(lowerCorner.getCoordinate()[0]);
    resource.put("bbox", bbox);
    JSONObject point = new JSONObject();
    point.put("type", "Point");
    JSONArray coordinates = new JSONArray();
    coordinates.add(latitude);
    coordinates.add(longitude);
    point.put("coordinates", coordinates);
    resource.put("point", point);
    resource.put("name", geoResult.getFullName());
    resources.add(resource);
}
Also used : DirectPosition(org.opengis.geometry.DirectPosition) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) Point(org.opengis.geometry.primitive.Point)

Example 4 with Point

use of org.opengis.geometry.primitive.Point 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)

Aggregations

Point (org.opengis.geometry.primitive.Point)4 DirectPositionImpl (org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl)3 PointImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)3 DirectPosition (org.opengis.geometry.DirectPosition)2 ArrayList (java.util.ArrayList)1 JSONArray (net.minidev.json.JSONArray)1 JSONObject (net.minidev.json.JSONObject)1 GeoResult (org.codice.ddf.spatial.geocoder.GeoResult)1 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)1 Test (org.junit.Test)1