diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..756245a
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..cdb59e9
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+
+
+ EcologicalEngineGeoSpatialExtension
+
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.m2e.core.maven2Nature
+ org.eclipse.jdt.core.javanature
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..11ad4d0
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,4 @@
+#Mon Apr 08 18:49:41 CEST 2013
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding/=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..30b5aca
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,13 @@
+#Mon Apr 08 18:49:41 CEST 2013
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..dd42b7f
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,5 @@
+#Mon Apr 08 18:15:49 CEST 2013
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..68a6ed7
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,155 @@
+
+ 4.0.0
+
+ maven-parent
+ org.gcube.tools
+ 1.0.0
+
+
+ org.gcube.dataanalysis
+ ecological-engine-external-algorithms
+ 1.0.0-SNAPSHOT
+ ecological-engine-geospatial-extension
+ ecological-engine-geospatial-extension
+
+ ${project.basedir}/distro
+
+
+
+ org.gcube.dataanalysis
+ ecological-engine
+ 1.6.1-SNAPSHOT
+
+
+ org.gcube.spatial.data
+ geonetwork
+ 1.0.0-SNAPSHOT
+
+
+ org.jdom
+ jdom
+ 1.1
+
+
+ org.gcube.externals
+ geo-utils-custom-opendap
+ 2.2.0
+
+
+ org.gcube.externals
+ geo-utils-custom-netcdfui
+ 4.2.0
+
+
+ org.gcube.externals
+ geo-utils-custom-netcdf
+ 4.2.0
+
+
+ org.gcube.externals
+ geo-utils-custom-bounce
+ 0.14.0
+
+
+ commons-codec
+ commons-codec
+ 20041127.091804
+
+
+ commons-httpclient
+ commons-httpclient
+ 3.1
+
+
+ commons-logging
+ commons-logging
+ 1.1.1
+
+
+ com.google.code.gson
+ gson
+ 1.7.1
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.6.4
+
+
+
+
+
+ osgeo
+ Open Source Geospatial Foundation Repository Mirror
+ http://maven.research-infrastructures.eu/nexus/content/repositories/osgeo//
+
+
+
+
+
+ maven-compiler-plugin
+
+
+ 1.6
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.12
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 2.5
+
+
+ copy-profile
+ install
+
+ copy-resources
+
+
+ target
+
+
+ ${distroDirectory}
+ true
+
+ profile.xml
+
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 2.2
+
+
+ ${distroDirectory}/descriptor.xml
+
+
+
+
+ servicearchive
+ install
+
+ single
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/gcube/dataanalysis/geo/meta/NetCDFMetadata.java b/src/main/java/org/gcube/dataanalysis/geo/meta/NetCDFMetadata.java
new file mode 100644
index 0000000..da6ec7d
--- /dev/null
+++ b/src/main/java/org/gcube/dataanalysis/geo/meta/NetCDFMetadata.java
@@ -0,0 +1,283 @@
+package org.gcube.dataanalysis.geo.meta;
+
+import it.geosolutions.geonetwork.GNClient;
+import it.geosolutions.geonetwork.util.GNInsertConfiguration;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map.Entry;
+
+import javax.xml.bind.JAXBException;
+
+import org.geotoolkit.metadata.iso.DefaultIdentifier;
+import org.geotoolkit.metadata.iso.DefaultMetadata;
+import org.geotoolkit.metadata.iso.citation.DefaultCitation;
+import org.geotoolkit.metadata.iso.citation.DefaultCitationDate;
+import org.geotoolkit.metadata.iso.citation.DefaultContact;
+import org.geotoolkit.metadata.iso.citation.DefaultOnlineResource;
+import org.geotoolkit.metadata.iso.citation.DefaultResponsibleParty;
+import org.geotoolkit.metadata.iso.constraint.DefaultLegalConstraints;
+import org.geotoolkit.metadata.iso.distribution.DefaultDigitalTransferOptions;
+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.identification.DefaultDataIdentification;
+import org.geotoolkit.metadata.iso.identification.DefaultKeywords;
+import org.geotoolkit.metadata.iso.identification.DefaultResolution;
+import org.geotoolkit.metadata.iso.identification.DefaultUsage;
+import org.geotoolkit.metadata.iso.lineage.DefaultLineage;
+import org.geotoolkit.metadata.iso.lineage.DefaultNominalResolution;
+import org.geotoolkit.metadata.iso.lineage.DefaultProcessStep;
+import org.geotoolkit.metadata.iso.lineage.DefaultProcessing;
+import org.geotoolkit.metadata.iso.lineage.DefaultSource;
+import org.geotoolkit.metadata.iso.maintenance.DefaultMaintenanceInformation;
+import org.geotoolkit.metadata.iso.quality.DefaultDataQuality;
+import org.geotoolkit.metadata.iso.quality.DefaultScope;
+import org.geotoolkit.metadata.iso.spatial.DefaultGeometricObjects;
+import org.geotoolkit.metadata.iso.spatial.DefaultVectorSpatialRepresentation;
+import org.geotoolkit.util.DefaultInternationalString;
+import org.geotoolkit.xml.XML;
+import org.opengis.metadata.Metadata;
+import org.opengis.metadata.citation.DateType;
+import org.opengis.metadata.citation.PresentationForm;
+import org.opengis.metadata.citation.ResponsibleParty;
+import org.opengis.metadata.citation.Role;
+import org.opengis.metadata.constraint.Restriction;
+import org.opengis.metadata.identification.KeywordType;
+import org.opengis.metadata.identification.TopicCategory;
+import org.opengis.metadata.lineage.ProcessStep;
+import org.opengis.metadata.maintenance.MaintenanceFrequency;
+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.util.InternationalString;
+
+public class NetCDFMetadata {
+
+
+
+ static File meta2File(Metadata meta) throws IOException, JAXBException {
+ File temp = File.createTempFile("meta", ".xml");
+ FileWriter writer = new FileWriter(temp);
+ writer.write(XML.marshal(meta));
+ writer.close();
+ return temp;
+ }
+
+ public static void main(String[] args) throws Exception {
+
+ // basic data:
+ String geonetworkUrl = "http://geoserver-dev.d4science-ii.research-infrastructures.eu/geonetwork/";
+ String geonetworkUser = "admin";
+ String geonetworkPwd = "admin";
+
+ String threddsCatalogUrl = "http://thredds.research-infrastructures.eu:8080/thredds/catalog/public/netcdf/catalog.xml";
+ String title = "temperature 04091217ruc.nc";
+ String layerName = "T";
+ String usageField = "Environmental enrichment";
+ String processdescription = "Maps publication";
+ String usageLimitations = "Not for commercial scopes";
+ Date sourceGenerationDate = new Date(System.currentTimeMillis());
+ String sourceTableName = "04091217_ruc.nc";
+ String contactInfo = "support@d4science.research-infrastructures.eu";
+ String abstractField = "T: temperature (degK) from 04091217ruc.nc resident on the THREDDS instance " + threddsCatalogUrl;
+ String purpose = "Maps publication";
+ String author = "gCube Ecological Engine Library";
+ double res = 0.5d;
+ double xLL = -180;
+ double xRU = 180;
+ double yLL = -85.5;
+ double yRU = 85.5;
+
+ String layerUrl = "http://thredds.research-infrastructures.eu:8080/thredds/dodsC/public/netcdf/04091217_ruc.nc";
+
+ // layer uri: wms, wfs wcs
+ List layerUris = new ArrayList();
+ /*
+ * layerUris.add("http://geoserver2.d4science.research-infrastructures.eu/geoserver/aquamaps/wms?service=WMS&version=1.1.0&request=GetMap&layers=aquamaps:lphotoblepharonpalpebratum20121207161220677cet&styles=&bbox=-180.0,-85.5,180.0,90.0&width=676&height=330&srs=EPSG:4326&format=application/openlayers"); layerUris.add("http://geoserver2.d4science.research-infrastructures.eu/geoserver/aquamaps/wcs/kml?layers=aquamaps:lphotoblepharonpalpebratum20121207161220677cet"); layerUris.add("http://geoserver2.d4science.research-infrastructures.eu/geoserver/aquamaps/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=aquamaps:lphotoblepharonpalpebratum20121207161220677cet&maxFeatures=50&outputFormat=GML2");
+ */
+ layerUris.add(OGCFormatter.getWmsNetCDFUrl(layerUrl, layerName, OGCFormatter.buildBoundingBox(xLL, yLL, xRU, yRU)));
+// layerUris.add(getWfsUrl(layerUrl, layerName, buildBoundingBox(xLL, yLL, xRU, yRU), 0, "json"));
+ layerUris.add(layerUrl);
+ layerUris.add(OGCFormatter.getWcsNetCDFUrl(layerUrl, layerName, OGCFormatter.buildBoundingBox(xLL, yLL, xRU, yRU)));
+ layerUris.add(threddsCatalogUrl);
+
+ // layer keywords
+ HashMap> descriptiveKeyWords = new HashMap>();
+ HashSet keySet = new HashSet();
+ keySet.add("THREDDS");
+ keySet.add("i-marine");
+ keySet.add("NetCDF");
+ descriptiveKeyWords.put(KeywordType.THEME, keySet);
+
+ // author:
+ DefaultResponsibleParty party = new DefaultResponsibleParty();
+ party.setIndividualName(author);
+ DefaultContact contact = new DefaultContact();
+ contact.setContactInstructions(new DefaultInternationalString(contactInfo));
+ party.setContactInfo(contact);
+ party.setRole(Role.ORIGINATOR);
+
+ // citation:
+ DefaultCitation citation = new DefaultCitation();
+ citation.setTitle(new DefaultInternationalString(title));
+ ArrayList citDates = new ArrayList();
+ citDates.add(new DefaultCitationDate(sourceGenerationDate, DateType.CREATION));
+ citDates.add(new DefaultCitationDate(sourceGenerationDate, DateType.PUBLICATION));
+ citDates.add(new DefaultCitationDate(sourceGenerationDate, DateType.REVISION));
+ citation.setDates(citDates);
+ ArrayList citAltTitle = new ArrayList();
+ citAltTitle.add(new DefaultInternationalString(title));
+ citation.setAlternateTitles(citAltTitle);
+ citation.setEditionDate(sourceGenerationDate);
+
+ citation.getPresentationForms().add(PresentationForm.MAP_DIGITAL);
+ DefaultDataIdentification ident = new DefaultDataIdentification();
+ ident.setCitation(citation);
+ ident.setAbstract(new DefaultInternationalString(abstractField));
+ ident.setPurpose(new DefaultInternationalString(purpose));
+ ident.getResourceMaintenances().add(new DefaultMaintenanceInformation(MaintenanceFrequency.AS_NEEDED));
+ ArrayList keywordslist = new ArrayList();
+ for (Entry> entry : descriptiveKeyWords.entrySet()) {
+ 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"));
+ thesaurus.setDates(citDates);
+ keywords.setThesaurusName(thesaurus);
+
+ keywordslist.add(keywords);
+ }
+
+ ident.setDescriptiveKeywords(keywordslist);
+
+ //usage:
+ DefaultUsage usage = new DefaultUsage();
+ usage.setSpecificUsage(new DefaultInternationalString(usageField));
+ usage.setUsageDate(sourceGenerationDate);
+ usage.setUserDeterminedLimitations(new DefaultInternationalString(usageLimitations));
+ usage.setUserContactInfo(new ArrayList(Arrays.asList(party)));
+ ArrayList usages = new ArrayList(Arrays.asList(usage));
+
+
+ ArrayList categories = new ArrayList();
+ categories.add(TopicCategory.BIOTA);
+ categories.add(TopicCategory.ENVIRONMENT);
+ categories.add(TopicCategory.OCEANS);
+ ident.setTopicCategories(categories);
+
+ ident.setResourceSpecificUsages(usages);
+
+ // Spatial Rapresentation Info
+ DefaultGeometricObjects geoObjs = new DefaultGeometricObjects();
+ geoObjs.setGeometricObjectType(GeometricObjectType.SURFACE);
+ DefaultVectorSpatialRepresentation spatial = new DefaultVectorSpatialRepresentation();
+ spatial.setTopologyLevel(TopologyLevel.GEOMETRY_ONLY);
+ spatial.getGeometricObjects().add(geoObjs);
+
+ // Extent:
+ DefaultExtent extent = new DefaultExtent();
+
+ extent.setGeographicElements(Collections.singleton(new DefaultGeographicBoundingBox(xLL, xRU, yLL, yRU)));
+ extent.setDescription(new DefaultInternationalString("Bounding box"));
+ extent.freeze();
+
+ ident.setExtents(new ArrayList(Arrays.asList(extent)));
+
+ DefaultNominalResolution resolution = new DefaultNominalResolution();
+ resolution.setGroundResolution(res);
+ resolution.setScanningResolution(res);
+
+ DefaultResolution dres = new DefaultResolution();
+ dres.setDistance(res);
+
+ ident.setSpatialRepresentationTypes(new ArrayList(Arrays.asList(SpatialRepresentationType.GRID)));
+ ident.setSpatialResolutions(new ArrayList(Arrays.asList(dres)));
+ ident.setLanguages(new ArrayList(Arrays.asList(Locale.ENGLISH)));
+
+ // layers access:
+ DefaultDistribution distribution = new DefaultDistribution();
+ DefaultDigitalTransferOptions transferOptions = new DefaultDigitalTransferOptions();
+ for (String uri : layerUris)
+ transferOptions.getOnLines().add(new DefaultOnlineResource(new URI(uri)));
+ distribution.getTransferOptions().add(transferOptions);
+ DefaultFormat format1 = new DefaultFormat();
+ format1.setName(new DefaultInternationalString("WMS"));
+ format1.setVersion(new DefaultInternationalString("1.1.0"));
+ DefaultFormat format2 = new DefaultFormat();
+ format2.setName(new DefaultInternationalString("WFS"));
+ format2.setVersion(new DefaultInternationalString("1.1.0"));
+ DefaultFormat format3 = new DefaultFormat();
+ format3.setName(new DefaultInternationalString("WCS"));
+ format3.setVersion(new DefaultInternationalString("1.0.0"));
+
+ distribution.setDistributionFormats(new ArrayList(Arrays.asList(format1, format2, format3)));
+
+ // legal constraints
+ DefaultLegalConstraints constraints = new DefaultLegalConstraints();
+ constraints.getUseLimitations().add(new DefaultInternationalString("Licensed"));
+ constraints.getAccessConstraints().add(Restriction.LICENSE);
+ constraints.getUseConstraints().add(Restriction.LICENSE);
+
+ // quality declaration:
+ DefaultDataQuality processQuality = new DefaultDataQuality();
+ DefaultSource source = new DefaultSource();
+
+ DefaultCitation sourceCitation = new DefaultCitation();
+ sourceCitation.setTitle(new DefaultInternationalString(title));
+ sourceCitation.getDates().add(new DefaultCitationDate(sourceGenerationDate, DateType.CREATION));
+ sourceCitation.getIdentifiers().add(new DefaultIdentifier(sourceTableName));
+
+ source.setResolution(resolution);
+ source.setDescription(new DefaultInternationalString(title));
+ source.setSourceCitation(sourceCitation);
+
+ // provenance
+ DefaultProcessStep preprocessStep = new DefaultProcessStep();
+ DefaultProcessStep processStep = new DefaultProcessStep(preprocessStep);
+ DefaultProcessing processing = new DefaultProcessing();
+ processing.setSoftwareReferences(new ArrayList(Arrays.asList(sourceCitation)));
+// processStep.setSources(new ArrayList(Arrays.asList(source)));
+ processStep.setDescription(new DefaultInternationalString(processdescription));
+// processStep.setProcessors(new ArrayList(Arrays.asList(party)));
+
+ DefaultLineage processLineage = new DefaultLineage();
+ processLineage.setProcessSteps(new ArrayList(Arrays.asList(processStep)));
+ processQuality.setLineage(processLineage);
+ processQuality.setScope(new DefaultScope(ScopeCode.DATASET));
+
+ // Metadata Obj:
+ DefaultMetadata meta = new DefaultMetadata(party, new Date(System.currentTimeMillis()), ident);
+ meta.getSpatialRepresentationInfo().add(spatial);
+ meta.setDistributionInfo(distribution);
+
+ 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);
+ client.insertMetadata(new GNInsertConfiguration("3", "datasets", "_none_", true), meta2File(meta));
+
+ // GeoServerRESTPublisher publisher=new GeoServerRESTManager(new URL(geonetworkUrl), geonetworkUser, geonetworkPwd).getPublisher();
+ // GeoNetwork.get().insertMetadata(new GNInsertConfiguration("view-group", "datasets", "_none_", true),meta);
+
+ }
+}
diff --git a/src/main/java/org/gcube/dataanalysis/geo/meta/OGCFormatter.java b/src/main/java/org/gcube/dataanalysis/geo/meta/OGCFormatter.java
new file mode 100644
index 0000000..582ad98
--- /dev/null
+++ b/src/main/java/org/gcube/dataanalysis/geo/meta/OGCFormatter.java
@@ -0,0 +1,37 @@
+package org.gcube.dataanalysis.geo.meta;
+
+public class OGCFormatter {
+ public static String getWfsUrl(String geoServerUrl, String layerName, String bbox, int limit, String format) {
+ return geoServerUrl + "/wfs?service=wfs&version=1.1.0&REQUEST=GetFeature" + "&TYPENAME=" + layerName + "&BBOX=" + bbox + (limit == 0 ? "" : "&MAXFEATURES=" + limit) + (format == null ? "" : "&OUTPUTFORMAT=" + format);
+ }
+
+ public static String getWmsUrl(String geoServerUrl, String layerName, String style, String bbox) {
+ return geoServerUrl + "/wms?service=wms&version=1.1.0" + "&request=GetMap&layers=" + layerName + "&styles=" + (style == null ? "" : style) + "&bbox=" + bbox + "&width=676&height=330&srs=EPSG:4326&format=application/openlayers";
+ }
+
+ public static String getWcsUrl(String geoServerUrl, String layerName, String bbox) {
+ return geoServerUrl + "/wcs?service=wcs&version=1.0.0" + "&request=GetCoverage&layers=" + layerName + "&CRS=EPSG:4326" + "&bbox=" + bbox + "&width=676&height=330&srs=EPSG:4326&format=geotiff";
+ }
+
+ public static String getWmsNetCDFUrl(String fileUrl, String layerName, String bbox) {
+ return fileUrl.replace("dodsC", "wms") + "?service=wms&version=1.3.0" + "&request=GetMap&layers=" + layerName + "&bbox=" + bbox + "&styles=&width=676&height=330&srs=EPSG:4326&CRS=EPSG:4326&format=image/png";
+ }
+
+ public static String getWcsNetCDFUrl(String fileUrl, String layerName, String bbox) {
+ return fileUrl.replace("dodsC", "wcs") + "?service=wcs&version=1.0.0" + "&request=GetCoverage&layers=" + layerName + "&CRS=EPSG:4326" + "&bbox=" + bbox + "&srs=EPSG:4326&format=geotiff";
+ }
+
+ public static String buildBoundingBox(double x1, double y1, double x2, double y2) {
+ // note: the bounding box is left,lower,right,upper
+ return (y1 + "," + x1 + "," + y2 + "," + x2);
+ }
+
+ public static String pointToBoundingBox(double x1, double y1, double tolerance) {
+ // note: the bounding box is left,lower,right,upper
+ double x11 = x1 - tolerance;
+ double y11 = y1 - tolerance;
+ double x22 = x1 + tolerance;
+ double y22 = y1 + tolerance;
+ return OGCFormatter.buildBoundingBox(x11, y11, x22, y22);
+ }
+}