Search in sources :

Example 1 with DirectPosition

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

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

Aggregations

DirectPosition (org.opengis.geometry.DirectPosition)2 Point (org.opengis.geometry.primitive.Point)2 ArrayList (java.util.ArrayList)1 JSONArray (net.minidev.json.JSONArray)1 JSONObject (net.minidev.json.JSONObject)1 DirectPositionImpl (org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl)1 PointImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)1