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