diff --git a/src/main/java/org/gcube/dataanalysis/geo/insertion/RasterTable.java b/src/main/java/org/gcube/dataanalysis/geo/insertion/RasterTable.java new file mode 100644 index 0000000..31d91e1 --- /dev/null +++ b/src/main/java/org/gcube/dataanalysis/geo/insertion/RasterTable.java @@ -0,0 +1,101 @@ +package org.gcube.dataanalysis.geo.insertion; + +import java.util.List; +import java.util.UUID; + +import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger; +import org.gcube.contentmanagement.lexicalmatcher.utils.DatabaseFactory; +import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration; +import org.gcube.dataanalysis.ecoengine.utils.DatabaseUtils; +import org.gcube.dataanalysis.ecoengine.utils.Tuple; +import org.gcube.dataanalysis.geo.retrieval.GeoIntersector; +import org.gcube.dataanalysis.geo.utils.CSquareCodesConverter; +import org.gcube.dataanalysis.geo.utils.EnvDataExplorer; +import org.hibernate.SessionFactory; + +/** + * transforms a raster map into a table + * @author coro + * + */ +public class RasterTable { + + private double resolution; + private double valuesMatrix[][]; + double x1; + double x2; + double y1; + double y2; + double z; + double xResolution; + double yResolution; + + private AlgorithmConfiguration configuration; + private String tablename = ""+UUID.randomUUID(); + static String createTableStatement = "CREATE TABLE %1$s (csquarecode character varying, x real, y real, z real, probability real)"; + static String columnsnames = "csquarecode, x , y , z , probability"; + + public String getTablename() { + return tablename; + } + + + public void setTablename(String tablename) { + this.tablename = tablename; + } + + + + + public RasterTable(double x1, double x2, double y1, double y2, double z, double xResolution, double yResolution, double[][] values, AlgorithmConfiguration configuration){ + this.valuesMatrix=values; + this.configuration=configuration; + this.x1=x1; + this.x2=x2; + this.y1=y1; + this.y2=y2; + this.z=z; + this.xResolution=xResolution; + this.yResolution=yResolution; + } + + + public void dumpGeoTable(){ + + //open the connection to the db + SessionFactory dbconnection = DatabaseUtils.initDBSession(configuration); + try{ + //create a table + DatabaseFactory.executeSQLUpdate(String.format(createTableStatement, tablename), dbconnection); + List> coordinates = GeoIntersector.generateCoordinateTriplets(x1, x2, y1, y2, z, xResolution, yResolution); + List values = GeoIntersector.associateValueToCoordinates(coordinates, valuesMatrix); + //for each element in the matrix, build the corresponding csquare code + int triplets = coordinates.size(); + StringBuffer sb = new StringBuffer(); + for (int i=0;i cset = coordinates.get(i); + double x = cset.getElements().get(0); + double y = cset.getElements().get(1); + String csquare = CSquareCodesConverter.convertAtResolution(x, y, xResolution); + double value = values.get(i); + sb.append("("+csquare+","+x+","+y+","+z+","+value+")"); + if (i