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();
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations