git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineGeoSpatialExtension@73541 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
e5008ea09c
commit
a09aba7a06
|
@ -0,0 +1,173 @@
|
|||
package org.gcube.dataanalysis.geo.insertion;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
||||
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
|
||||
import org.gcube.dataanalysis.geo.meta.NetCDFMetadata;
|
||||
import org.gcube.dataanalysis.geo.meta.OGCFormatter;
|
||||
import org.gcube.dataanalysis.geo.meta.features.FeaturesManager;
|
||||
import org.gcube.dataanalysis.geo.utils.ThreddsDataExplorer;
|
||||
import org.opengis.metadata.Metadata;
|
||||
|
||||
import ucar.nc2.dataset.CoordinateAxis;
|
||||
import ucar.nc2.dt.GridDatatype;
|
||||
import ucar.nc2.dt.grid.GridDataset;
|
||||
import ucar.nc2.units.DateRange;
|
||||
|
||||
import com.ibm.icu.text.SimpleDateFormat;
|
||||
|
||||
public class ThreddsFetcher {
|
||||
|
||||
private FeaturesManager featurer;
|
||||
public static String NetCDFDateFormat = "time: E MMM dd HH:mm:ss zzz yyyy";
|
||||
public static String HumanDateFormat = "MM-dd-yy HH:mm";
|
||||
|
||||
public ThreddsFetcher(String scope) {
|
||||
featurer = new FeaturesManager();
|
||||
featurer.setScope(scope);
|
||||
}
|
||||
|
||||
public void fetch(String threddsCatalogURL) throws Exception {
|
||||
|
||||
List<String> filesURL = ThreddsDataExplorer.getFiles(threddsCatalogURL);
|
||||
for (String filename : filesURL) {
|
||||
// if (!filename.equalsIgnoreCase("cami_0000-09-01_64x128_L26_c030918.nc"))
|
||||
// continue;
|
||||
|
||||
String url = OGCFormatter.getOpenDapURL(threddsCatalogURL, filename);
|
||||
if (ThreddsDataExplorer.isGridDataset(url)) {
|
||||
// retrieve information
|
||||
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(url);
|
||||
|
||||
List<GridDatatype> gridTypes = gds.getGrids();
|
||||
for (GridDatatype gdt : gridTypes) {
|
||||
String description = gdt.getDescription();
|
||||
if ((description==null) || (description.length()==0))
|
||||
description = gdt.getFullName();
|
||||
// get date range
|
||||
DateRange dr = gdt.getCoordinateSystem().getDateRange();
|
||||
// SimpleDateFormat netcdfDF = new SimpleDateFormat(NetCDFDateFormat, Locale.ENGLISH);
|
||||
SimpleDateFormat humanDF = new SimpleDateFormat(HumanDateFormat, Locale.ROOT);
|
||||
String hStartDate = null;
|
||||
String hEndDate = null;
|
||||
String duration = null;
|
||||
String resolution = gdt.getTimeDimension()==null?null:""+gdt.getTimeDimension().getLength();
|
||||
|
||||
if (dr != null) {
|
||||
hStartDate = dr.getStart() == null ? null : humanDF.format(dr.getStart().getDate());
|
||||
hEndDate = dr.getEnd() == null ? null : humanDF.format(dr.getEnd().getDate());
|
||||
duration = dr.getDuration() == null ? null : "" + dr.getDuration();
|
||||
}
|
||||
|
||||
// control if the file is yet on GN
|
||||
String generatedTitle = generateTitle(filename, description, hStartDate, hEndDate);
|
||||
|
||||
Metadata previousmeta = featurer.checkForMetadatabyTitle(FeaturesManager.treatTitleForGN(generatedTitle), generatedTitle);
|
||||
if (previousmeta!=null){
|
||||
AnalysisLogger.getLogger().debug("***WARNING: layer yet found on GeoNetwork***");
|
||||
continue;
|
||||
}
|
||||
/*Layers check - for testing only
|
||||
else {
|
||||
AnalysisLogger.getLogger().debug("***layer retrieval failed***");
|
||||
if (true) System.exit(0);
|
||||
}
|
||||
*/
|
||||
|
||||
int numberOfDimensions = 2;
|
||||
if ((gdt.getZDimension()!=null)&&(gdt.getZDimension().getLength()>1)){
|
||||
numberOfDimensions = 3;
|
||||
AnalysisLogger.getLogger().debug("Length of Z Dimension: "+gdt.getZDimension().getLength());
|
||||
}
|
||||
else
|
||||
AnalysisLogger.getLogger().debug("Bidimensional Layer ");
|
||||
|
||||
// get resolution - take the maximum regular step
|
||||
CoordinateAxis xAxis = gdt.getCoordinateSystem().getXHorizAxis();
|
||||
CoordinateAxis yAxis = gdt.getCoordinateSystem().getYHorizAxis();
|
||||
double resolutionX = Math.abs((double) (xAxis.getMaxValue() - xAxis.getMinValue()) / (double) xAxis.getShape()[0]);
|
||||
double resolutionY = Math.abs((double) (yAxis.getMaxValue() - yAxis.getMinValue()) / (double) yAxis.getShape()[0]);
|
||||
|
||||
//build metadata
|
||||
NetCDFMetadata metadataInserter = new NetCDFMetadata();
|
||||
metadataInserter.setGeonetworkUrl(featurer.getGeonetworkURLFromScope());
|
||||
metadataInserter.setGeonetworkUser(featurer.getGeonetworkUserFromScope());
|
||||
metadataInserter.setGeonetworkPwd(featurer.getGeonetworkPasswordFromScope());
|
||||
// Build standard info:
|
||||
metadataInserter.setThreddsCatalogUrl(threddsCatalogURL);
|
||||
metadataInserter.setLayerUrl(url);
|
||||
metadataInserter.setLayerName(gdt.getFullName());
|
||||
metadataInserter.setSourceFileName(filename);
|
||||
// insert ranges and sampling
|
||||
metadataInserter.setTitle(generatedTitle);
|
||||
metadataInserter.setAbstractField(generateAbstractField(gdt.getFullName(), filename, description, gdt.getUnitsString().trim(), hStartDate, hEndDate, duration, resolution, numberOfDimensions));
|
||||
metadataInserter.setResolution(Math.max(resolutionX, resolutionY));
|
||||
// set Bounding box
|
||||
metadataInserter.setXLeftLow(ThreddsDataExplorer.getMinX(gdt.getCoordinateSystem()));
|
||||
metadataInserter.setYLeftLow(ThreddsDataExplorer.getMinY(gdt.getCoordinateSystem()));
|
||||
metadataInserter.setXRightUpper(ThreddsDataExplorer.getMaxX(gdt.getCoordinateSystem()));
|
||||
metadataInserter.setYRightUpper(ThreddsDataExplorer.getMaxY(gdt.getCoordinateSystem()));
|
||||
//set keywords
|
||||
metadataInserter.setCustomTopics(filename, description);
|
||||
//set Temporal Extent
|
||||
if (hStartDate!=null){
|
||||
metadataInserter.setStartDate(dr.getStart().getDate());
|
||||
metadataInserter.setEndDate(dr.getEnd().getDate());
|
||||
}
|
||||
|
||||
AnalysisLogger.getLogger().debug("title: " + metadataInserter.getTitle());
|
||||
AnalysisLogger.getLogger().debug("abstract: " + metadataInserter.getAbstractField());
|
||||
|
||||
metadataInserter.insertMetaData();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateTitle(String filename, String description, String startDate, String endDate) {
|
||||
String dateString = "";
|
||||
if (startDate != null){
|
||||
if (startDate.equals(endDate))
|
||||
dateString = " in [" + startDate + "]";
|
||||
else
|
||||
dateString = " from [" + startDate + "] to [" + endDate + "]";
|
||||
}
|
||||
return description.replaceAll("( )+", " ") + dateString+" (" + filename + ")";
|
||||
}
|
||||
|
||||
public static String generateAbstractField(String layername, String filename, String description, String unit, String startDate, String endDate, String duration, String timeInstants, int numberOfDimensions) {
|
||||
String timeresolutionString = "";
|
||||
String durationString = "";
|
||||
if ((timeInstants != null) && (timeInstants.length() > 0))
|
||||
timeresolutionString = " Number of time instants: " + timeInstants+".";
|
||||
|
||||
if ((duration != null) && (duration.length() > 0))
|
||||
durationString = " Time interval lenght: " + duration+".";
|
||||
|
||||
String dateString = "";
|
||||
if (startDate != null)
|
||||
dateString = " in the time range between [" + startDate + "] and [" + endDate + "].";
|
||||
|
||||
String unitString = "";
|
||||
if ((unit != null) && (unit.length()>0))
|
||||
unitString= " (" + unit + ")";
|
||||
|
||||
String numberOfDimensionsString = "";
|
||||
if (numberOfDimensions>0)
|
||||
numberOfDimensionsString = " Number of Dimensions: "+numberOfDimensions+".";
|
||||
return layername + ": " + description + unitString+dateString + durationString + timeresolutionString + numberOfDimensionsString+ " Taken from the file " + filename + " resident on a THREDDS instance.";
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
AnalysisLogger.setLogger("./cfg/"+AlgorithmConfiguration.defaultLoggerFile);
|
||||
// ThreddsFetcher tf = new ThreddsFetcher("/gcube/devsec");
|
||||
ThreddsFetcher tf = new ThreddsFetcher(null);
|
||||
tf.fetch("http://thredds.research-infrastructures.eu:8080/thredds/catalog/public/netcdf/catalog.xml");
|
||||
}
|
||||
|
||||
}
|
|
@ -19,6 +19,7 @@ import java.util.Map.Entry;
|
|||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.gcube.dataanalysis.geo.utils.NetCDFTemporalPrimitive;
|
||||
import org.geotoolkit.metadata.iso.DefaultIdentifier;
|
||||
import org.geotoolkit.metadata.iso.DefaultMetadata;
|
||||
import org.geotoolkit.metadata.iso.citation.DefaultCitation;
|
||||
|
@ -32,6 +33,8 @@ import org.geotoolkit.metadata.iso.distribution.DefaultDistribution;
|
|||
import org.geotoolkit.metadata.iso.distribution.DefaultFormat;
|
||||
import org.geotoolkit.metadata.iso.extent.DefaultExtent;
|
||||
import org.geotoolkit.metadata.iso.extent.DefaultGeographicBoundingBox;
|
||||
import org.geotoolkit.metadata.iso.extent.DefaultSpatialTemporalExtent;
|
||||
import org.geotoolkit.metadata.iso.extent.DefaultTemporalExtent;
|
||||
import org.geotoolkit.metadata.iso.identification.DefaultDataIdentification;
|
||||
import org.geotoolkit.metadata.iso.identification.DefaultKeywords;
|
||||
import org.geotoolkit.metadata.iso.identification.DefaultResolution;
|
||||
|
@ -62,6 +65,7 @@ import org.opengis.metadata.maintenance.ScopeCode;
|
|||
import org.opengis.metadata.spatial.GeometricObjectType;
|
||||
import org.opengis.metadata.spatial.SpatialRepresentationType;
|
||||
import org.opengis.metadata.spatial.TopologyLevel;
|
||||
import org.opengis.temporal.TemporalPrimitive;
|
||||
import org.opengis.util.InternationalString;
|
||||
|
||||
public class NetCDFMetadata {
|
||||
|
@ -80,13 +84,42 @@ public class NetCDFMetadata {
|
|||
private String contactInfo = "support@d4science.research-infrastructures.eu";
|
||||
private String abstractField = "T: temperature (degK) from 04091217ruc.nc resident on the THREDDS instance " + threddsCatalogUrl;
|
||||
private String purpose = "Maps publication";
|
||||
private String author = "gCube Ecological Engine Library";
|
||||
private String author = "i-Marine";
|
||||
private double res = 0.5d;
|
||||
private double xLL = -180;
|
||||
private double xRU = 180;
|
||||
private double yLL = -85.5;
|
||||
private double yRU = 85.5;
|
||||
private String layerUrl = "http://thredds.research-infrastructures.eu:8080/thredds/dodsC/public/netcdf/04091217_ruc.nc";
|
||||
private HashSet<String> customTopics;
|
||||
private Date startDate;
|
||||
private Date endDate;
|
||||
|
||||
public void setCustomTopics(String... topics){
|
||||
customTopics = new HashSet<String>();
|
||||
for (String topic:topics)
|
||||
customTopics.add(topic);
|
||||
}
|
||||
|
||||
public HashSet<String> getCustomTopics(){
|
||||
return customTopics;
|
||||
}
|
||||
|
||||
public void setStartDate(Date date){
|
||||
startDate=date;
|
||||
}
|
||||
|
||||
public void setEndDate(Date date){
|
||||
endDate=date;
|
||||
}
|
||||
|
||||
public Date getStartDate(){
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public Date getEndDate(){
|
||||
return endDate;
|
||||
}
|
||||
|
||||
public String getGeonetworkUrl() {
|
||||
return geonetworkUrl;
|
||||
|
@ -279,8 +312,20 @@ public class NetCDFMetadata {
|
|||
keySet.add("THREDDS");
|
||||
keySet.add("i-Marine");
|
||||
keySet.add("NetCDF");
|
||||
if (customTopics!=null)
|
||||
keySet.addAll(customTopics);
|
||||
|
||||
descriptiveKeyWords.put(KeywordType.THEME, keySet);
|
||||
|
||||
if (startDate!=null){
|
||||
HashSet<String> temporalkeySet = new HashSet<String>();
|
||||
temporalkeySet.add(startDate.toString());
|
||||
if (!endDate.equals(startDate))
|
||||
temporalkeySet.add(endDate.toString());
|
||||
descriptiveKeyWords.put(KeywordType.TEMPORAL, temporalkeySet);
|
||||
}
|
||||
|
||||
|
||||
// author:
|
||||
DefaultResponsibleParty party = new DefaultResponsibleParty();
|
||||
party.setIndividualName(author);
|
||||
|
@ -307,6 +352,7 @@ public class NetCDFMetadata {
|
|||
DefaultKeywords keywords = new DefaultKeywords();
|
||||
for (String key : entry.getValue())
|
||||
keywords.getKeywords().add(new DefaultInternationalString(key));
|
||||
|
||||
keywords.setType(entry.getKey());
|
||||
DefaultCitation thesaurus = new DefaultCitation();
|
||||
thesaurus.setTitle(new DefaultInternationalString("General"));
|
||||
|
@ -329,7 +375,7 @@ public class NetCDFMetadata {
|
|||
|
||||
// Spatial Rapresentation Info
|
||||
DefaultGeometricObjects geoObjs = new DefaultGeometricObjects();
|
||||
geoObjs.setGeometricObjectType(GeometricObjectType.SURFACE);
|
||||
geoObjs.setGeometricObjectType(GeometricObjectType.COMPLEX);
|
||||
DefaultVectorSpatialRepresentation spatial = new DefaultVectorSpatialRepresentation();
|
||||
spatial.setTopologyLevel(TopologyLevel.GEOMETRY_ONLY);
|
||||
spatial.getGeometricObjects().add(geoObjs);
|
||||
|
@ -338,6 +384,13 @@ public class NetCDFMetadata {
|
|||
DefaultExtent extent = new DefaultExtent();
|
||||
extent.setGeographicElements(Collections.singleton(new DefaultGeographicBoundingBox(xLL, xRU, yLL, yRU)));
|
||||
extent.setDescription(new DefaultInternationalString("Bounding box"));
|
||||
|
||||
/*Only with Geotoolkit 4.x
|
||||
DefaultTemporalExtent stext = new DefaultTemporalExtent(startDate,endDate);
|
||||
stext.setStartTime(startDate);
|
||||
stext.setEndTime(endDate);
|
||||
extent.setTemporalElements(Arrays.asList(stext));
|
||||
*/
|
||||
extent.freeze();
|
||||
|
||||
//resolution
|
||||
|
@ -347,7 +400,6 @@ public class NetCDFMetadata {
|
|||
DefaultResolution dres = new DefaultResolution();
|
||||
dres.setDistance(res);
|
||||
|
||||
|
||||
// layers access:
|
||||
DefaultDistribution distribution = new DefaultDistribution();
|
||||
DefaultDigitalTransferOptions transferOptions = new DefaultDigitalTransferOptions();
|
||||
|
@ -419,12 +471,12 @@ public class NetCDFMetadata {
|
|||
meta.getMetadataConstraints().add(constraints);
|
||||
meta.getDataQualityInfo().add(processQuality);
|
||||
meta.setLanguage(Locale.ENGLISH);
|
||||
|
||||
System.out.println(meta);
|
||||
GNClient client = new GNClient(geonetworkUrl);
|
||||
client.login(geonetworkUser, geonetworkPwd);
|
||||
File tmetafile = meta2File(meta);
|
||||
client.insertMetadata(new GNInsertConfiguration("3", "datasets", "_none_", true), tmetafile);
|
||||
tmetafile.delete();
|
||||
// System.out.println(meta);
|
||||
// tmetafile.delete();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,10 @@ public class OGCFormatter {
|
|||
return fileUrl.replace("dodsC", "wcs") + "?service=wcs&version=1.0.0" + "&request=GetCoverage&coverage=" + layerName + "&CRS=EPSG:4326" + "&bbox=" + bbox + "&width=676&height=330&format=geotiff";
|
||||
}
|
||||
|
||||
public static String getOpenDapURL(String threddsCatalog, String filename) {
|
||||
return threddsCatalog.replace("catalog.xml",filename).replace("catalog","dodsC");
|
||||
}
|
||||
|
||||
public static String buildBoundingBox(double x1, double y1, double x2, double y2) {
|
||||
// note: the bounding box is left,lower,right,upper
|
||||
return (x1 + "," + y1 + "," + x2 + "," + y2);
|
||||
|
|
|
@ -3,15 +3,21 @@ package org.gcube.dataanalysis.geo.meta.features;
|
|||
import it.geosolutions.geonetwork.util.GNSearchRequest;
|
||||
import it.geosolutions.geonetwork.util.GNSearchResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetwork;
|
||||
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
|
||||
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
|
||||
import org.gcube.spatial.data.geonetwork.configuration.ConfigurationManager;
|
||||
import org.opengis.metadata.Metadata;
|
||||
import org.opengis.metadata.citation.OnlineResource;
|
||||
import org.opengis.metadata.distribution.DigitalTransferOptions;
|
||||
|
||||
public class FeaturesManager {
|
||||
private String geonetworkUrl = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geonetwork/";
|
||||
private String geonetworkUrl = "http://geoserver-dev2.d4science-ii.research-infrastructures.eu/geonetwork/";
|
||||
private String geonetworkUser = "admin";
|
||||
private String geonetworkPwd = "admin";
|
||||
private String scope = "/gcube/devsec";
|
||||
|
@ -84,24 +90,106 @@ public class FeaturesManager {
|
|||
return (getOpenDapLink(meta) != null);
|
||||
}
|
||||
|
||||
public Metadata getGNInfobyTitle(String info) throws Exception {
|
||||
ScopeProvider.instance.set(scope);
|
||||
public GeoNetworkReader initGeoNetworkReader() throws Exception {
|
||||
if (scope!=null)
|
||||
ScopeProvider.instance.set(scope);
|
||||
else{
|
||||
ConfigurationManager.setConfiguration(new Configuration() {
|
||||
@Override
|
||||
public String getGeoNetworkUser() {
|
||||
return geonetworkUser;
|
||||
}
|
||||
@Override
|
||||
public String getGeoNetworkPassword() {
|
||||
return geonetworkPwd;
|
||||
}
|
||||
@Override
|
||||
public String getGeoNetworkEndpoint() {
|
||||
return geonetworkUrl;
|
||||
}
|
||||
});
|
||||
}
|
||||
GeoNetworkReader gn = GeoNetwork.get();
|
||||
return gn;
|
||||
}
|
||||
|
||||
public String getGeonetworkURLFromScope() throws Exception {
|
||||
GeoNetworkReader gn = initGeoNetworkReader();
|
||||
return gn.getConfiguration().getGeoNetworkEndpoint();
|
||||
}
|
||||
|
||||
public String getGeonetworkUserFromScope() throws Exception {
|
||||
GeoNetworkReader gn = initGeoNetworkReader();
|
||||
return gn.getConfiguration().getGeoNetworkUser();
|
||||
}
|
||||
|
||||
public String getGeonetworkPasswordFromScope() throws Exception {
|
||||
GeoNetworkReader gn = initGeoNetworkReader();
|
||||
return gn.getConfiguration().getGeoNetworkPassword();
|
||||
}
|
||||
|
||||
public Metadata getGNInfobyTitle(String info) throws Exception {
|
||||
|
||||
GeoNetworkReader gn = initGeoNetworkReader();
|
||||
// Form query object
|
||||
gn.login();
|
||||
GNSearchRequest req = new GNSearchRequest();
|
||||
req.addParam(GNSearchRequest.Param.title, info);
|
||||
// req.addConfig(GNSearchRequest.Config.similarity, "1");
|
||||
GNSearchResponse resp = gn.query(req);
|
||||
Metadata meta = null;
|
||||
if (resp.getCount() != 0)
|
||||
for (GNSearchResponse.GNMetadata metadata : resp) {
|
||||
meta = gn.getById(metadata.getUUID());
|
||||
break;
|
||||
try {
|
||||
meta = gn.getById(metadata.getUUID());
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
AnalysisLogger.getLogger().debug("Error retrieving information for some metadata");
|
||||
}
|
||||
}
|
||||
|
||||
return meta;
|
||||
}
|
||||
|
||||
public List<Metadata> getAllGNInfobyTitle(String info, String tolerance) throws Exception {
|
||||
|
||||
GeoNetworkReader gn = initGeoNetworkReader();
|
||||
// Form query object
|
||||
gn.login();
|
||||
GNSearchRequest req = new GNSearchRequest();
|
||||
req.addParam(GNSearchRequest.Param.title, info);
|
||||
req.addConfig(GNSearchRequest.Config.similarity, tolerance);
|
||||
GNSearchResponse resp = gn.query(req);
|
||||
Metadata meta = null;
|
||||
List<Metadata> metadatalist = new ArrayList<Metadata>();
|
||||
if (resp.getCount() != 0)
|
||||
for (GNSearchResponse.GNMetadata metadata : resp) {
|
||||
try {
|
||||
meta = gn.getById(metadata.getUUID());
|
||||
metadatalist.add(meta);
|
||||
} catch (Exception e) {
|
||||
AnalysisLogger.getLogger().debug("Error retrieving information for some metadata");
|
||||
}
|
||||
}
|
||||
|
||||
return metadatalist;
|
||||
}
|
||||
|
||||
public Metadata checkForMetadatabyTitle(String searchString, String completetitle) throws Exception {
|
||||
List<Metadata> mlist = getAllGNInfobyTitle(searchString, "1");
|
||||
AnalysisLogger.getLogger().debug("Searching for: "+searchString);
|
||||
Metadata mfound = null;
|
||||
for (Metadata m : mlist) {
|
||||
String title = m.getIdentificationInfo().iterator().next().getCitation().getTitle().toString();
|
||||
if (completetitle.equalsIgnoreCase(title)) {
|
||||
mfound = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return mfound;
|
||||
}
|
||||
|
||||
public String getGeonetworkUrl() {
|
||||
return geonetworkUrl;
|
||||
}
|
||||
|
@ -126,10 +214,31 @@ public class FeaturesManager {
|
|||
this.geonetworkPwd = geonetworkPwd;
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
public static String treatTitleForGN(String layerTitle) {
|
||||
int idx = layerTitle.indexOf("from");
|
||||
String layerTitle2 = layerTitle;
|
||||
if (idx>0)
|
||||
layerTitle2 = layerTitle.toLowerCase().substring(0, idx).trim();
|
||||
else{
|
||||
idx = layerTitle.indexOf("(");
|
||||
layerTitle2 = layerTitle.toLowerCase().substring(0, idx).trim();
|
||||
}
|
||||
layerTitle2 = layerTitle2.replaceAll("(\\(.*\\))", " ");
|
||||
|
||||
layerTitle2 = layerTitle2.replace("_", " ").replace("-", " ").replace("(", " ").replace(")", " ");
|
||||
String punct = "[!\"#$%&'*+,./:;<=>?@\\^_`{|}~-]";
|
||||
|
||||
layerTitle2 = layerTitle2.replaceAll("( |^)+[^A-Za-z]+("+punct+")*[^A-Za-z]*", " ").trim();
|
||||
|
||||
return layerTitle2.replaceAll(punct, " ").replaceAll("( )+", " ");
|
||||
}
|
||||
|
||||
public static void main1(String args[]) throws Exception {
|
||||
// String title = "temperature (04091217ruc.nc)";
|
||||
// String title = "Bathymetry";
|
||||
String title = "FAO aquatic species distribution map of Melanogrammus aeglefinus";
|
||||
// String title = "FAO aquatic species distribution map of Melanogrammus aeglefinus";
|
||||
// String title = "geopotential height from [12/09/2004 19:00] to [12/09/2004 22:00] (04091217_ruc.nc)";
|
||||
String title = "geopotential height";
|
||||
FeaturesManager fm = new FeaturesManager();
|
||||
Metadata meta = fm.getGNInfobyTitle(title);
|
||||
System.out.println("is file? " + fm.isThreddsFile(meta));
|
||||
|
@ -138,4 +247,8 @@ public class FeaturesManager {
|
|||
System.out.println("wms:" + fm.getWMSLink(meta));
|
||||
System.out.println("thredds:" + fm.getThreddsLink(meta));
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
System.out.println(treatTitleForGN("sea/land/lake/ice field composite mask from"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,10 @@ public class GeoIntersector {
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -32,7 +36,7 @@ public class GeoIntersector {
|
|||
// check if it is a NetCDF
|
||||
if (featurer.isThreddsFile(meta)) {
|
||||
System.out.println("found a netCDF file with title " + layerTitle+" and layer name "+layer);
|
||||
features = getFeaturesFromNetCDF(featurer.getOpenDapLink(meta), layer, x, y);
|
||||
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);
|
||||
|
@ -42,11 +46,11 @@ public class GeoIntersector {
|
|||
return features;
|
||||
}
|
||||
|
||||
private LinkedHashMap<String, Double> getFeaturesFromNetCDF(String opendapURL, String layer, double x, double y) {
|
||||
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);
|
||||
return ThreddsDataExplorer.retrieveDataFromNetCDF(opendapURL, layer, x, y, z);
|
||||
}
|
||||
|
||||
private LinkedHashMap<String, Double> getFeaturesFromWFS(String wfsUrl, String layer, double x, double y) {
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package org.gcube.dataanalysis.geo.utils;
|
||||
|
||||
import org.opengis.temporal.TemporalPrimitive;
|
||||
|
||||
public class NetCDFTemporalPrimitive implements TemporalPrimitive{
|
||||
|
||||
@Override
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "<gmd:extent/>";
|
||||
}
|
||||
|
||||
}
|
|
@ -59,12 +59,12 @@ public class ThreddsDataExplorer {
|
|||
return fileNames;
|
||||
}
|
||||
|
||||
public static LinkedHashMap<String, Double> retrieveDataFromNetCDF(String openDapLink, String layer, double x, double y) {
|
||||
public static LinkedHashMap<String, Double> retrieveDataFromNetCDF(String openDapLink, String layer, double x, double y, double z) {
|
||||
try {
|
||||
LinkedHashMap<String, Double> map = new LinkedHashMap<String, Double>();
|
||||
if (isGridDataset(openDapLink)) {
|
||||
AnalysisLogger.getLogger().debug("Managing Grid File");
|
||||
return manageGridDataset(layer, openDapLink, x, y);
|
||||
return manageGridDataset(layer, openDapLink, x, y, z);
|
||||
}
|
||||
/*
|
||||
* else if (isPointDataset(openDapLink)) { AnalysisLogger.getLogger().debug("Managing Points File"); }
|
||||
|
@ -81,7 +81,7 @@ public class ThreddsDataExplorer {
|
|||
}
|
||||
|
||||
// A GridDatatype is like a specialized Variable that explicitly handles X,Y,Z,T dimensions
|
||||
public static LinkedHashMap<String, Double> manageGridDataset(String layer, String filename, double x, double y) throws Exception {
|
||||
public static LinkedHashMap<String, Double> manageGridDataset(String layer, String filename, double x, double y, double z) throws Exception {
|
||||
LinkedHashMap<String, Double> valuesMap = new LinkedHashMap<String, Double>();
|
||||
GridDataset gds = ucar.nc2.dt.grid.GridDataset.open(filename);
|
||||
List<GridDatatype> gridTypes = gds.getGrids();
|
||||
|
@ -101,9 +101,14 @@ public class ThreddsDataExplorer {
|
|||
CoordinateAxis tAxis = gcs.getTimeAxis();
|
||||
timeSteps = tAxis.getSize();
|
||||
}
|
||||
|
||||
CoordinateAxis zAxis = gdt.getCoordinateSystem().getVerticalAxis();
|
||||
double resolutionZ = Math.abs((double) (zAxis.getMaxValue() - zAxis.getMinValue()) / (double) zAxis.getShape()[0]);
|
||||
int zint = (int) Math.round(z/resolutionZ);
|
||||
|
||||
int[] xy = gcs.findXYindexFromLatLon(y, x, null);
|
||||
for (int j = 0; j < timeSteps; j++) {
|
||||
Array data = grid.readDataSlice(j, 0, xy[1], xy[0]); // note order is t, z, y, x
|
||||
Array data = grid.readDataSlice(j, zint, xy[1], xy[0]); // note order is t, z, y, x
|
||||
Double val = takeFirstDouble(data);
|
||||
if (!val.isNaN()) {
|
||||
String date = "" + j;
|
||||
|
@ -197,6 +202,7 @@ public class ThreddsDataExplorer {
|
|||
// A GridDatatype is like a specialized Variable that explicitly handles X,Y,Z,T dimensions
|
||||
public static boolean isGridDataset(String filename) {
|
||||
try {
|
||||
AnalysisLogger.getLogger().debug("Analyzing file "+filename);
|
||||
Formatter errlog = new Formatter();
|
||||
FeatureDataset fdataset = FeatureDatasetFactoryManager.open(FeatureType.GRID, filename, null, errlog);
|
||||
if (fdataset == null) {
|
||||
|
@ -205,7 +211,7 @@ public class ThreddsDataExplorer {
|
|||
return false;
|
||||
} else
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -244,4 +250,42 @@ public class ThreddsDataExplorer {
|
|||
return isdataset;
|
||||
}
|
||||
|
||||
|
||||
public static double adjX(double x){
|
||||
if (x < -180)
|
||||
x = -180;
|
||||
if (x > 180)
|
||||
x = 180;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public static double adjY(double y){
|
||||
if (y < -90)
|
||||
y = -90;
|
||||
if (y > 90)
|
||||
y = 90;
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
public static double getMinX(GridCoordSystem gcs){
|
||||
CoordinateAxis xAxis = gcs.getXHorizAxis();
|
||||
return adjX(xAxis.getMinValue() - 180);
|
||||
}
|
||||
|
||||
public static double getMaxX(GridCoordSystem gcs){
|
||||
CoordinateAxis xAxis = gcs.getXHorizAxis();
|
||||
return adjX(xAxis.getMaxValue() - 180);
|
||||
}
|
||||
|
||||
public static double getMinY(GridCoordSystem gcs){
|
||||
CoordinateAxis yAxis = gcs.getYHorizAxis();
|
||||
return adjY(yAxis.getMinValue());
|
||||
}
|
||||
|
||||
public static double getMaxY(GridCoordSystem gcs){
|
||||
CoordinateAxis yAxis = gcs.getYHorizAxis();
|
||||
return adjY(yAxis.getMaxValue());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue