Search in sources :

Example 1 with GeoCoder

use of org.codice.ddf.spatial.geocoder.GeoCoder in project ddf by codice.

the class GeoCoderEndpoint method getNearbyCities.

@GET
@Path("nearby/cities/{wkt}")
public Response getNearbyCities(@PathParam("wkt") String wkt) {
    GeoCoder geoCoder = geoCoderFactory.getService();
    try {
        NearbyLocation nearbyLocation = geoCoder.getNearbyCity(wkt);
        if (nearbyLocation != null) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("direction", nearbyLocation.getCardinalDirection());
            jsonObject.put("distance", nearbyLocation.getDistance());
            jsonObject.put("name", nearbyLocation.getName());
            return Response.ok(jsonObject.toJSONString()).build();
        } else {
            return Response.status(Response.Status.NO_CONTENT).build();
        }
    } catch (GeoEntryQueryException e) {
        LOGGER.debug("Error querying GeoNames resource with wkt:{}", wkt, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) JSONObject(net.minidev.json.JSONObject) GeoEntryQueryException(org.codice.ddf.spatial.geocoding.GeoEntryQueryException) NearbyLocation(org.codice.ddf.spatial.geocoding.context.NearbyLocation) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with GeoCoder

use of org.codice.ddf.spatial.geocoder.GeoCoder in project ddf by codice.

the class GeoCoderPlugin method process.

@Override
public CreateRequest process(CreateRequest input) throws PluginExecutionException, StopProcessingException {
    if (input.getMetacards() == null) {
        return input;
    }
    try {
        GeoCoder geoCoder = geoCoderFactory.getService();
        input.getMetacards().forEach(metacard -> setCountryCode(metacard, geoCoder));
    } catch (Exception e) {
        throw new PluginExecutionException("Unable to determine country code for data", e);
    }
    return input;
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) StopProcessingException(ddf.catalog.plugin.StopProcessingException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException) PluginExecutionException(ddf.catalog.plugin.PluginExecutionException)

Example 3 with GeoCoder

use of org.codice.ddf.spatial.geocoder.GeoCoder in project ddf by codice.

the class GeoCoderServiceImpl method doQuery.

JSONObject doQuery(String query) {
    GeoCoder geoCoder = geoCoderFactory.getService();
    GeoResult geoResult = null;
    if (geoCoder != null) {
        geoResult = geoCoder.getLocation(query);
    }
    JSONObject jsonObject = new JSONObject();
    JSONArray resourceSets = new JSONArray();
    JSONObject resourceSet = new JSONObject();
    jsonObject.put("resourceSets", resourceSets);
    resourceSets.add(resourceSet);
    JSONArray resources = new JSONArray();
    resourceSet.put("resources", resources);
    if (geoResult != null) {
        transformGeoResult(geoResult, resources);
    }
    return jsonObject;
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) GeoResult(org.codice.ddf.spatial.geocoder.GeoResult)

Example 4 with GeoCoder

use of org.codice.ddf.spatial.geocoder.GeoCoder in project ddf by codice.

the class GeoCoderPlugin method process.

@Override
public UpdateRequest process(UpdateRequest input) throws PluginExecutionException, StopProcessingException {
    if (input == null || input.getUpdates() == null) {
        return input;
    }
    GeoCoder geoCoder = geoCoderFactory.getService();
    input.getUpdates().stream().map(Map.Entry::getValue).forEach(metacard -> setCountryCode(metacard, geoCoder));
    return input;
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) Map(java.util.Map)

Example 5 with GeoCoder

use of org.codice.ddf.spatial.geocoder.GeoCoder in project ddf by codice.

the class GeoCoderEndpoint method doQuery.

JSONObject doQuery(String query) {
    GeoCoder geoCoder = geoCoderFactory.getService();
    GeoResult geoResult = null;
    if (geoCoder != null) {
        geoResult = geoCoder.getLocation(query);
    }
    JSONObject jsonObject = new JSONObject();
    JSONArray resourceSets = new JSONArray();
    JSONObject resourceSet = new JSONObject();
    jsonObject.put("resourceSets", resourceSets);
    resourceSets.add(resourceSet);
    JSONArray resources = new JSONArray();
    resourceSet.put("resources", resources);
    if (geoResult != null) {
        transformGeoResult(geoResult, resources);
    }
    return jsonObject;
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) GeoResult(org.codice.ddf.spatial.geocoder.GeoResult)

Aggregations

GeoCoder (org.codice.ddf.spatial.geocoder.GeoCoder)6 JSONObject (net.minidev.json.JSONObject)4 JSONArray (net.minidev.json.JSONArray)2 GeoResult (org.codice.ddf.spatial.geocoder.GeoResult)2 NearbyLocation (org.codice.ddf.spatial.geocoding.context.NearbyLocation)2 PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)1 StopProcessingException (ddf.catalog.plugin.StopProcessingException)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 GeoEntryQueryException (org.codice.ddf.spatial.geocoding.GeoEntryQueryException)1