78 lines
3.1 KiB
Java
78 lines
3.1 KiB
Java
package org.gcube.dataanalysis.geo.retrieval;
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
|
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
|
|
import org.gcube.dataanalysis.geo.meta.features.FeaturesManager;
|
|
import org.gcube.dataanalysis.geo.utils.EnvDataExplorer;
|
|
import org.gcube.dataanalysis.geo.utils.ThreddsDataExplorer;
|
|
import org.opengis.metadata.Metadata;
|
|
import org.opengis.metadata.identification.Identification;
|
|
|
|
public class GeoIntersector {
|
|
|
|
private FeaturesManager featurer;
|
|
|
|
public GeoIntersector(String scope) {
|
|
featurer = new FeaturesManager();
|
|
featurer.setScope(scope);
|
|
}
|
|
|
|
public LinkedHashMap<String, Double> getFeaturesInTime(String layerTitle, double x, double y) throws Exception {
|
|
return getFeaturesInTime(layerTitle, x, y, 0);
|
|
}
|
|
|
|
public LinkedHashMap<String, Double> getFeaturesInTime(String layerTitle, double x, double y, double z) throws Exception {
|
|
LinkedHashMap<String, Double> features = new LinkedHashMap<String, Double>();
|
|
// get the layer
|
|
// Metadata meta = featurer.getGNInfobyTitle(layerTitle);
|
|
Metadata meta = featurer.checkForMetadatabyTitle(FeaturesManager.treatTitleForGN(layerTitle),layerTitle);
|
|
// if the layer is good
|
|
if (meta != null) {
|
|
String layer = featurer.getLayerName(meta);
|
|
|
|
if (layer == null)
|
|
layer = layerTitle;
|
|
|
|
// check if it is a NetCDF
|
|
if (featurer.isThreddsFile(meta)) {
|
|
Identification id = meta.getIdentificationInfo().iterator().next();
|
|
String title = id.getCitation().getTitle().toString();
|
|
|
|
System.out.println("found a netCDF file with title " +title +" and layer name "+layer);
|
|
features = getFeaturesFromNetCDF(featurer.getOpenDapLink(meta), layer, x, y, z);
|
|
} else {
|
|
System.out.println("found a Geo Layer with title " + layerTitle+" and layer name "+layer);
|
|
features = getFeaturesFromWFS(featurer.getWFSLink(meta), layer, x, y);
|
|
}
|
|
}
|
|
|
|
return features;
|
|
}
|
|
|
|
private LinkedHashMap<String, Double> getFeaturesFromNetCDF(String opendapURL, String layer, double x, double y, double z) {
|
|
if (opendapURL == null)
|
|
return null;
|
|
|
|
return ThreddsDataExplorer.retrieveDataFromNetCDF(opendapURL, layer, x, y, z);
|
|
}
|
|
|
|
private LinkedHashMap<String, Double> getFeaturesFromWFS(String wfsUrl, String layer, double x, double y) {
|
|
if (wfsUrl == null)
|
|
return null;
|
|
|
|
return EnvDataExplorer.getFeatures(wfsUrl, layer, x, y);
|
|
}
|
|
|
|
public static void main(String args[] ) throws Exception{
|
|
AnalysisLogger.setLogger("./cfg/"+AlgorithmConfiguration.defaultLoggerFile);
|
|
// GeoIntersector inters = new GeoIntersector("/gcube/devsec");
|
|
GeoIntersector inters = new GeoIntersector(null);
|
|
|
|
// System.out.println(inters.getFeaturesInTime("temperature (04091217ruc.nc)", 0.1, 0.1));
|
|
System.out.println(inters.getFeaturesInTime("wind stress from [05-01-07 14:00] to [04-01-12 14:00] (2D) {CERSAT-GLO-CLIM_WIND_L4-OBS_FULL_TIME_SERIE_CLIMATOLOGY_METEOROLOGY_ATMOSPHERE_1366217956317.nc}", 0.1, 0.1,3000));
|
|
}
|
|
|
|
}
|