use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForRaymond method parseDietObservation.
private void parseDietObservation(LabeledCSVParser dietParser, Study study) throws StudyImporterException {
try {
Specimen predator = getSpecimen(dietParser, "PREDATOR_NAME", "PREDATOR_LIFE_STAGE", study);
dietParser.getValueByLabel("ALTITUDE_MIN");
dietParser.getValueByLabel("ALTITUDE_MAX");
dietParser.getValueByLabel("DEPTH_MIN");
dietParser.getValueByLabel("DEPTH_MAX");
Location sampleLocation = parseLocation(dietParser, study);
predator.caughtIn(sampleLocation);
Specimen prey = getSpecimen(dietParser, "PREY_NAME", "PREY_LIFE_STAGE", study);
prey.caughtIn(sampleLocation);
predator.ate(prey);
Date date = parseCollectionDate(dietParser);
nodeFactory.setUnixEpochProperty(prey, date);
nodeFactory.setUnixEpochProperty(predator, date);
} catch (NodeFactoryException e) {
throw new StudyImporterException("failed to import data", e);
}
}
use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForRaymond method locationFromLocale.
private Location locationFromLocale(LabeledCSVParser dietParser, Study study) throws NodeFactoryException {
Location loc = null;
LatLng centroid;
String location = dietParser.getValueByLabel("LOCATION");
if (StringUtils.isNotBlank(location)) {
String cleanedLocationString = location.replaceAll("\\.$", "");
getLocations().add(cleanedLocationString);
try {
centroid = getGeoNamesService().findLatLng(cleanedLocationString);
if (centroid == null) {
getLogger().warn(study, "missing lat/lng bounding box [" + dietParser.lastLineNumber() + "] and attempted to using location [" + location + "] failed.");
} else {
loc = nodeFactory.getOrCreateLocation(new LocationImpl(centroid.getLat(), centroid.getLng(), null, null));
}
} catch (IOException e) {
getLogger().warn(study, "failed to lookup point for location [" + location + "] on line [" + dietParser.lastLineNumber() + "]");
}
}
return loc;
}
use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForRaymond method parseLocation.
private Location parseLocation(LabeledCSVParser dietParser, Study study) throws StudyImporterException {
/**
* left, top ------- right, top
* | |
* | |
* left, bottom -- right, bottom
*/
String westString = dietParser.getValueByLabel(WEST);
String eastString = dietParser.getValueByLabel(EAST);
String northString = dietParser.getValueByLabel(NORTH);
String southString = dietParser.getValueByLabel(SOUTH);
Location loc = null;
if (StringUtils.isBlank(westString) || StringUtils.isBlank(eastString) || StringUtils.isBlank(northString) || StringUtils.isBlank(southString)) {
try {
loc = locationFromLocale(dietParser, study);
} catch (NodeFactoryException ex) {
throw new StudyImporterException("found invalid location on line [" + dietParser.lastLineNumber() + "]", ex);
}
} else {
double left = Double.parseDouble(westString);
double top = Double.parseDouble(northString);
double right = Double.parseDouble(eastString);
double bottom = Double.parseDouble(southString);
LatLng centroid = calculateCentroidOfBBox(left, top, right, bottom);
try {
loc = nodeFactory.getOrCreateLocation(new LocationImpl(centroid.getLat(), centroid.getLng(), null, null));
} catch (NodeFactoryException ex) {
String locationString = StringUtils.join(Arrays.asList(westString, northString, eastString, southString), ",");
LOG.warn("found invalid locations [" + locationString + "] on line [" + (dietParser.lastLineNumber() + 1) + "]: " + ex.getMessage());
}
}
return loc;
}
use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForINaturalist method parseLocation.
private Location parseLocation(JsonNode observation) throws NodeFactoryException {
Location location = null;
String latitudeString = observation.get("latitude").getTextValue();
String longitudeString = observation.get("longitude").getTextValue();
if (latitudeString != null && longitudeString != null) {
double latitude = Double.parseDouble(latitudeString);
double longitude = Double.parseDouble(longitudeString);
location = nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, null, null));
}
return location;
}
use of org.eol.globi.domain.Location in project eol-globi-data by jhpoelen.
the class StudyImporterForRobledoTest method createAndPopulateStudy.
@Test
public void createAndPopulateStudy() throws StudyImporterException, NodeFactoryException {
StudyImporterForRobledo importer = new StudyImporterForRobledo(new ParserFactoryLocal(), nodeFactory);
importStudy(importer);
Study study = getStudySingleton(getGraphDb());
assertNotNull(taxonIndex.findTaxonByName("Heliconia imbricata"));
assertNotNull(taxonIndex.findTaxonByName("Renealmia alpinia"));
assertNotNull(nodeFactory.findStudy(study.getTitle()));
int count = 0;
Iterable<Relationship> specimenRels = NodeUtil.getSpecimens(study);
for (Relationship specimenRel : specimenRels) {
Specimen specimen1 = new SpecimenNode(specimenRel.getEndNode());
Location sampleLocation = specimen1.getSampleLocation();
assertThat(sampleLocation, is(notNullValue()));
assertThat(sampleLocation.getAltitude(), is(35.0));
assertThat(Math.round(sampleLocation.getLongitude()), is(-84L));
assertThat(Math.round(sampleLocation.getLatitude()), is(10L));
count++;
}
assertThat(count, is(93));
}
Aggregations