Gianpaolo Coro 2013-04-10 15:04:18 +00:00
parent 92717a59f4
commit 6c4d2f4b9e
8 changed files with 527 additions and 0 deletions

7
.classpath Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EcologicalEngineGeoSpatialExtension</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,4 @@
#Mon Apr 08 18:49:41 CEST 2013
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding/<project>=UTF-8

View File

@ -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

View File

@ -0,0 +1,5 @@
#Mon Apr 08 18:15:49 CEST 2013
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

155
pom.xml Normal file
View File

@ -0,0 +1,155 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.0.0</version>
<relativePath />
</parent>
<groupId>org.gcube.dataanalysis</groupId>
<artifactId>ecological-engine-external-algorithms</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>ecological-engine-geospatial-extension</name>
<description>ecological-engine-geospatial-extension</description>
<properties>
<distroDirectory>${project.basedir}/distro</distroDirectory>
</properties>
<dependencies>
<dependency>
<groupId>org.gcube.dataanalysis</groupId>
<artifactId>ecological-engine</artifactId>
<version>1.6.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>geonetwork</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.gcube.externals</groupId>
<artifactId>geo-utils-custom-opendap</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.gcube.externals</groupId>
<artifactId>geo-utils-custom-netcdfui</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.gcube.externals</groupId>
<artifactId>geo-utils-custom-netcdf</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.gcube.externals</groupId>
<artifactId>geo-utils-custom-bounce</artifactId>
<version>0.14.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>20041127.091804</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
<repositories>
<!-- <repository>
<id>GeoSolutions</id>
<url>http://maven.research-infrastructures.eu:8081/nexus/content/repositories/geo-solutions/</url>
</repository> -->
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository Mirror</name>
<url>http://maven.research-infrastructures.eu/nexus/content/repositories/osgeo//</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>${distroDirectory}</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -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<String> layerUris = new ArrayList<String>();
/*
* 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<KeywordType, HashSet<String>> descriptiveKeyWords = new HashMap<KeywordType, HashSet<String>>();
HashSet<String> keySet = new HashSet<String>();
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<DefaultCitationDate> citDates = new ArrayList<DefaultCitationDate>();
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<InternationalString> citAltTitle = new ArrayList<InternationalString>();
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<DefaultKeywords> keywordslist = new ArrayList<DefaultKeywords>();
for (Entry<KeywordType, HashSet<String>> 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<ResponsibleParty>(Arrays.asList(party)));
ArrayList<DefaultUsage> usages = new ArrayList<DefaultUsage>(Arrays.asList(usage));
ArrayList<TopicCategory> categories = new ArrayList<TopicCategory>();
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<DefaultExtent>(Arrays.asList(extent)));
DefaultNominalResolution resolution = new DefaultNominalResolution();
resolution.setGroundResolution(res);
resolution.setScanningResolution(res);
DefaultResolution dres = new DefaultResolution();
dres.setDistance(res);
ident.setSpatialRepresentationTypes(new ArrayList<SpatialRepresentationType>(Arrays.asList(SpatialRepresentationType.GRID)));
ident.setSpatialResolutions(new ArrayList<DefaultResolution>(Arrays.asList(dres)));
ident.setLanguages(new ArrayList<Locale>(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<DefaultFormat>(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<DefaultCitation>(Arrays.asList(sourceCitation)));
// processStep.setSources(new ArrayList<DefaultSource>(Arrays.asList(source)));
processStep.setDescription(new DefaultInternationalString(processdescription));
// processStep.setProcessors(new ArrayList<DefaultResponsibleParty>(Arrays.asList(party)));
DefaultLineage processLineage = new DefaultLineage();
processLineage.setProcessSteps(new ArrayList<ProcessStep>(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);
}
}

View File

@ -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);
}
}