Search in sources :

Example 1 with Ecoregion

use of org.eol.globi.geo.Ecoregion in project eol-globi-data by jhpoelen.

the class NodeFactoryNeo4j method associateWithEcoRegions.

private List<Ecoregion> associateWithEcoRegions(Location location) throws NodeFactoryException {
    List<Ecoregion> associatedEcoregions = new ArrayList<Ecoregion>();
    try {
        EcoregionFinder finder = getEcoregionFinder();
        if (finder != null) {
            Collection<Ecoregion> ecoregions = finder.findEcoregion(location.getLatitude(), location.getLongitude());
            for (Ecoregion ecoregion : ecoregions) {
                associateLocationWithEcoRegion(location, ecoregion);
                associatedEcoregions.add(ecoregion);
            }
        }
    } catch (EcoregionFinderException e) {
        throw new NodeFactoryException("problem finding eco region for location (lat,lng):(" + location.getLatitude() + "," + location.getLongitude() + ")");
    }
    return associatedEcoregions;
}
Also used : EcoregionFinder(org.eol.globi.geo.EcoregionFinder) Ecoregion(org.eol.globi.geo.Ecoregion) ArrayList(java.util.ArrayList) EcoregionFinderException(org.eol.globi.geo.EcoregionFinderException)

Example 2 with Ecoregion

use of org.eol.globi.geo.Ecoregion in project eol-globi-data by jhpoelen.

the class NodeFactoryNeo4j method getEcoRegions.

private List<Ecoregion> getEcoRegions(Node locationNode) {
    Iterable<Relationship> relationships = locationNode.getRelationships(NodeUtil.asNeo4j(RelTypes.IN_ECOREGION), Direction.OUTGOING);
    List<Ecoregion> ecoregions = null;
    for (Relationship relationship : relationships) {
        Node ecoregionNode = relationship.getEndNode();
        Ecoregion ecoregion = new Ecoregion();
        ecoregion.setGeometry(NodeUtil.getPropertyStringValueOrDefault(ecoregionNode, "geometry", null));
        ecoregion.setName(NodeUtil.getPropertyStringValueOrDefault(ecoregionNode, PropertyAndValueDictionary.NAME, null));
        ecoregion.setId(NodeUtil.getPropertyStringValueOrDefault(ecoregionNode, PropertyAndValueDictionary.EXTERNAL_ID, null));
        ecoregion.setPath(NodeUtil.getPropertyStringValueOrDefault(ecoregionNode, "path", null));
        if (ecoregions == null) {
            ecoregions = new ArrayList<>();
        }
        ecoregions.add(ecoregion);
    }
    return ecoregions;
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Ecoregion(org.eol.globi.geo.Ecoregion) JsonNode(org.codehaus.jackson.JsonNode) Node(org.neo4j.graphdb.Node)

Example 3 with Ecoregion

use of org.eol.globi.geo.Ecoregion in project eol-globi-data by jhpoelen.

the class NormalizerTest method createNormalizer.

private Normalizer createNormalizer() {
    Normalizer dataNormalizationTool = new Normalizer();
    dataNormalizationTool.setEcoregionFinder(new EcoregionFinder() {

        @Override
        public Collection<Ecoregion> findEcoregion(double lat, double lng) throws EcoregionFinderException {
            final Ecoregion ecoregion = new Ecoregion();
            ecoregion.setName("some name");
            ecoregion.setPath("some | path");
            ecoregion.setId("someId");
            ecoregion.setGeometry("POINT(1,2)");
            return new ArrayList<Ecoregion>() {

                {
                    add(ecoregion);
                }
            };
        }

        @Override
        public void shutdown() {
        }
    });
    return dataNormalizationTool;
}
Also used : EcoregionFinder(org.eol.globi.geo.EcoregionFinder) Ecoregion(org.eol.globi.geo.Ecoregion) EcoregionFinderException(org.eol.globi.geo.EcoregionFinderException) Collection(java.util.Collection)

Example 4 with Ecoregion

use of org.eol.globi.geo.Ecoregion in project eol-globi-data by jhpoelen.

the class GraphDBTestCase method createNodeFactory.

NodeFactory createNodeFactory() {
    NodeFactoryNeo4j nodeFactoryNeo4j = new NodeFactoryNeo4j(getGraphDb());
    nodeFactoryNeo4j.setEcoregionFinder(new EcoregionFinder() {

        @Override
        public Collection<Ecoregion> findEcoregion(double lat, double lng) throws EcoregionFinderException {
            final Ecoregion ecoregion = new Ecoregion();
            ecoregion.setName("some eco region");
            ecoregion.setPath("some | eco | region | path");
            ecoregion.setId("some:id");
            ecoregion.setGeometry("POINT(0,0)");
            return new ArrayList<Ecoregion>() {

                {
                    add(ecoregion);
                }
            };
        }

        @Override
        public void shutdown() {
        }
    });
    nodeFactoryNeo4j.setEnvoLookupService(getEnvoLookupService());
    nodeFactoryNeo4j.setTermLookupService(getTermLookupService());
    return nodeFactoryNeo4j;
}
Also used : EcoregionFinder(org.eol.globi.geo.EcoregionFinder) Ecoregion(org.eol.globi.geo.Ecoregion) EcoregionFinderException(org.eol.globi.geo.EcoregionFinderException) Collection(java.util.Collection)

Example 5 with Ecoregion

use of org.eol.globi.geo.Ecoregion in project eol-globi-data by jhpoelen.

the class EcoregionFinderProxyTest method multipleRegionsForSingleLocation.

@Test
public void multipleRegionsForSingleLocation() throws EcoregionFinderException {
    ArrayList<EcoregionFinder> finders = new ArrayList<EcoregionFinder>() {

        {
            add(new EcoregionTestFinder("one:"));
            add(new EcoregionTestFinder("two:"));
            add(new EcoregionTestFinder("two:"));
            add(new EcoregionTestFinder("three:"));
        }
    };
    Collection<Ecoregion> ecoregion = new EcoregionFinderProxy(finders).findEcoregion(9.2, -79.91667);
    Collection<String> ids = new ArrayList<String>();
    for (Ecoregion region : ecoregion) {
        ids.add(region.getId());
    }
    assertThat(ids.contains("one:123"), is(true));
    assertThat(ids.contains("two:123"), is(true));
    assertThat(ids.contains("three:123"), is(true));
    assertThat(ecoregion.size(), is(3));
}
Also used : EcoregionFinder(org.eol.globi.geo.EcoregionFinder) Ecoregion(org.eol.globi.geo.Ecoregion) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Ecoregion (org.eol.globi.geo.Ecoregion)5 EcoregionFinder (org.eol.globi.geo.EcoregionFinder)4 EcoregionFinderException (org.eol.globi.geo.EcoregionFinderException)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 JsonNode (org.codehaus.jackson.JsonNode)1 Test (org.junit.Test)1 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1