Search in sources :

Example 1 with LatLng

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

the class StudyImporterForRaymond method calculateCentroidOfBBox.

protected static LatLng calculateCentroidOfBBox(double left, double top, double right, double bottom) {
    LatLng latLng;
    if (left == right && top == bottom) {
        latLng = new LatLng(top, left);
    } else {
        Coordinate[] points = { GeoUtil.getCoordinate(top, left), GeoUtil.getCoordinate(top, right), GeoUtil.getCoordinate(bottom, right), GeoUtil.getCoordinate(bottom, left), GeoUtil.getCoordinate(top, left) };
        GeometryFactory geometryFactory = new GeometryFactory();
        Polygon polygon = geometryFactory.createPolygon(points);
        Point centroid = polygon.getCentroid();
        latLng = new LatLng(centroid.getCoordinate().y, centroid.getCoordinate().x);
    }
    return latLng;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) LatLng(org.eol.globi.geo.LatLng) Point(com.vividsolutions.jts.geom.Point) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 2 with LatLng

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

the class StudyImporterForSzoboszlai method importLink.

protected Map<String, String> importLink(LabeledCSVParser parser, Map<Integer, LatLng> localeMap) throws IOException, StudyImporterException {
    TreeMap<String, String> link = new TreeMap<String, String>();
    link.put(STUDY_SOURCE_CITATION, getSourceCitationLastAccessed());
    String predNum = StringUtils.trim(parser.getValueByLabel("PredatorSciNameTSN"));
    if (StringUtils.isNotBlank(predNum)) {
        link.put(SOURCE_TAXON_ID, TaxonomyProvider.ITIS.getIdPrefix() + predNum);
    }
    String predName = StringUtils.trim(parser.getValueByLabel("PredatorSciName"));
    if (StringUtils.isNotBlank(predName)) {
        link.put(SOURCE_TAXON_NAME, predName);
    }
    String preyNum = StringUtils.trim(parser.getValueByLabel("PreySciNameTSN"));
    if (StringUtils.isNotBlank(preyNum)) {
        link.put(TARGET_TAXON_ID, TaxonomyProvider.ITIS.getIdPrefix() + preyNum);
    }
    String preyName = StringUtils.trim(parser.getValueByLabel("PreySciName"));
    if (StringUtils.isNotBlank(preyName)) {
        link.put(TARGET_TAXON_NAME, preyName);
    }
    String[] citeFields = { "CiteAuth", "CiteYear", "CiteTitle", "CiteSource", "CiteVolume", "CitePages" };
    List<String> citeValues = new ArrayList<String>();
    for (String citeField : citeFields) {
        String value = StringUtils.trim(parser.getValueByLabel(citeField));
        if (StringUtils.isNotBlank(value)) {
            String prefix;
            if ("CiteVolume".equals(citeField)) {
                prefix = "v.";
            } else if ("CitePages".equals(citeField)) {
                prefix = "pp.";
            } else {
                prefix = "";
            }
            citeValues.add(prefix + value);
        }
    }
    String referenceCitation = StringUtils.join(citeValues, ". ");
    link.put(REFERENCE_ID, getSourceDOI() + '/' + MD5.getHashString(referenceCitation));
    link.put(REFERENCE_CITATION, referenceCitation);
    link.put(INTERACTION_TYPE_NAME, "preysOn");
    link.put(INTERACTION_TYPE_ID, "RO:0002439");
    link.put(LOCALITY_NAME, StringUtils.trim(parser.getValueByLabel("LocatName")));
    String locatNum = StringUtils.trim(parser.getValueByLabel("LocatNum"));
    if (StringUtils.isNotBlank(locatNum)) {
        try {
            LatLng latLng = localeMap.get(Integer.parseInt(locatNum));
            if (latLng != null) {
                link.put(DECIMAL_LATITUDE, Double.toString(latLng.getLat()));
                link.put(DECIMAL_LONGITUDE, Double.toString(latLng.getLng()));
            }
        } catch (NumberFormatException ex) {
            throw new StudyImporterException("found invalid LocalNum [" + locatNum + "] " + parser.lastLineNumber(), ex);
        }
    }
    return link;
}
Also used : ArrayList(java.util.ArrayList) LatLng(org.eol.globi.geo.LatLng) TreeMap(java.util.TreeMap)

Example 3 with LatLng

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

the class StudyImporterForSzoboszlai method importShapes.

protected Map<Integer, LatLng> importShapes() throws StudyImporterException {
    Map<Integer, LatLng> localityMap = new TreeMap<>();
    FileDataStore dataStore = null;
    try {
        InputStream shapeZipArchive = getDataset().getResource("shapes");
        File tmpFolder = new File(FileUtils.getTempDirectory(), UUID.randomUUID().toString());
        tmpFolder.deleteOnExit();
        unpackZip(shapeZipArchive, tmpFolder);
        dataStore = FileDataStoreFinder.getDataStore(new File(tmpFolder, "LocatPolygonsPoints.shp"));
        if (dataStore == null) {
            throw new StudyImporterException("failed to parse shapefiles");
        }
        FeatureReader<SimpleFeatureType, SimpleFeature> featureReader = dataStore.getFeatureReader();
        while (featureReader.hasNext()) {
            SimpleFeature feature = featureReader.next();
            Object geom = feature.getAttribute("the_geom");
            if (geom instanceof Point) {
                Coordinate coordinate = ((Point) geom).getCoordinate();
                Object localNum = feature.getAttribute("LocatNum");
                if (localNum instanceof Integer) {
                    localityMap.put((Integer) localNum, new LatLng(coordinate.y, coordinate.x));
                }
            }
        }
        featureReader.close();
    } catch (IOException e) {
        throw new StudyImporterException(e);
    } finally {
        if (dataStore != null) {
            dataStore.dispose();
        }
    }
    return localityMap;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) Point(com.vividsolutions.jts.geom.Point) IOException(java.io.IOException) TreeMap(java.util.TreeMap) SimpleFeature(org.opengis.feature.simple.SimpleFeature) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Coordinate(com.vividsolutions.jts.geom.Coordinate) LatLng(org.eol.globi.geo.LatLng) FileDataStore(org.geotools.data.FileDataStore) File(java.io.File)

Example 4 with LatLng

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

the class StudyImporterForRoopnarine method importStudy.

@Override
public void importStudy() throws StudyImporterException {
    String suffix = ".csv";
    String prefix = "roopnarine/857470.item.";
    String trophicGuildLookup = prefix + 4 + suffix;
    final Map<Integer, List<String>> trophicGuildNumberToSpeciesMap = buildGuildLookup(trophicGuildLookup);
    Map<String, LatLng> resourceLocation = resourceLocationMap(suffix, prefix);
    Study study = nodeFactory.getOrCreateStudy(new StudyImpl("Roopnarine et al 2013", "Roopnarine, P.D. & Hertog, R., 2013. Detailed Food Web Networks of Three Greater Antillean Coral Reef Systems: The Cayman Islands, Cuba, and Jamaica. DatasetImpl Papers in Ecology, 2013, pp.1–9. Available at: http://dx.doi.org/10.7167/2013/857470.", "http://dx.doi.org/10.7167/2013/857470", null));
    for (Map.Entry<String, LatLng> resourceLatLngEntry : resourceLocation.entrySet()) {
        LatLng latLng = resourceLatLngEntry.getValue();
        Location location;
        try {
            location = nodeFactory.getOrCreateLocation(new LocationImpl(latLng.getLat(), latLng.getLng(), 0.0, null));
        } catch (NodeFactoryException e) {
            throw new StudyImporterException("failed to create location", e);
        }
        String studyResource = resourceLatLngEntry.getKey();
        getLogger().info(study, "import of [" + studyResource + "] started...");
        List<Specimen> predatorSpecimen = importTrophicInteractions(trophicGuildLookup, trophicGuildNumberToSpeciesMap, studyResource, study, location);
        getLogger().info(study, "import of [" + studyResource + "] done.");
    }
}
Also used : Study(org.eol.globi.domain.Study) StudyImpl(org.eol.globi.domain.StudyImpl) Specimen(org.eol.globi.domain.Specimen) LocationImpl(org.eol.globi.domain.LocationImpl) ArrayList(java.util.ArrayList) List(java.util.List) LatLng(org.eol.globi.geo.LatLng) HashMap(java.util.HashMap) Map(java.util.Map) Location(org.eol.globi.domain.Location)

Example 5 with LatLng

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

the class StudyImporterForRoopnarine method resourceLocationMap.

private Map<String, LatLng> resourceLocationMap(String suffix, String prefix) {
    LatLng jamaica = new LatLng(18.1315, -77.2736);
    LatLng cuba = new LatLng(22.0289, -79.9370);
    LatLng caymanIslands = new LatLng(19.30, -80.40);
    Map<String, LatLng> resourceLocation = new HashMap<String, LatLng>();
    resourceLocation.put(prefix + 1 + suffix, caymanIslands);
    resourceLocation.put(prefix + 2 + suffix, cuba);
    resourceLocation.put(prefix + 3 + suffix, jamaica);
    return resourceLocation;
}
Also used : HashMap(java.util.HashMap) LatLng(org.eol.globi.geo.LatLng)

Aggregations

LatLng (org.eol.globi.geo.LatLng)40 Test (org.junit.Test)17 IOException (java.io.IOException)10 LocationImpl (org.eol.globi.domain.LocationImpl)9 Location (org.eol.globi.domain.Location)8 HashMap (java.util.HashMap)6 Specimen (org.eol.globi.domain.Specimen)6 Study (org.eol.globi.domain.Study)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 StudyImpl (org.eol.globi.domain.StudyImpl)4 GeoNamesService (org.eol.globi.service.GeoNamesService)4 List (java.util.List)3 LabeledCSVParser (com.Ostermiller.util.LabeledCSVParser)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 Point (com.vividsolutions.jts.geom.Point)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)2