Search in sources :

Example 36 with Location

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);
    }
}
Also used : Specimen(org.eol.globi.domain.Specimen) Date(java.util.Date) Location(org.eol.globi.domain.Location)

Example 37 with Location

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;
}
Also used : LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) IOException(java.io.IOException) Location(org.eol.globi.domain.Location)

Example 38 with Location

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;
}
Also used : LocationImpl(org.eol.globi.domain.LocationImpl) LatLng(org.eol.globi.geo.LatLng) Location(org.eol.globi.domain.Location)

Example 39 with Location

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;
}
Also used : LocationImpl(org.eol.globi.domain.LocationImpl) Location(org.eol.globi.domain.Location)

Example 40 with 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));
}
Also used : Study(org.eol.globi.domain.Study) Specimen(org.eol.globi.domain.Specimen) Relationship(org.neo4j.graphdb.Relationship) SpecimenNode(org.eol.globi.domain.SpecimenNode) Location(org.eol.globi.domain.Location) Test(org.junit.Test)

Aggregations

Location (org.eol.globi.domain.Location)44 LocationImpl (org.eol.globi.domain.LocationImpl)32 Specimen (org.eol.globi.domain.Specimen)31 Study (org.eol.globi.domain.Study)24 StudyImpl (org.eol.globi.domain.StudyImpl)16 TaxonImpl (org.eol.globi.domain.TaxonImpl)16 Date (java.util.Date)14 IOException (java.io.IOException)13 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)12 HashMap (java.util.HashMap)8 LatLng (org.eol.globi.geo.LatLng)8 TermImpl (org.eol.globi.domain.TermImpl)6 Test (org.junit.Test)6 Relationship (org.neo4j.graphdb.Relationship)6 SpecimenNode (org.eol.globi.domain.SpecimenNode)5 ArrayList (java.util.ArrayList)4 Taxon (org.eol.globi.domain.Taxon)4 Node (org.neo4j.graphdb.Node)3 List (java.util.List)2 Map (java.util.Map)2