introducing Geo charts

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/EcologicalEngineGeoSpatialExtension@112288 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Gianpaolo Coro 2015-03-02 12:39:52 +00:00
parent ac76e5d9bd
commit 5df3b52b89
8 changed files with 1796 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,130 @@
package org.gcube.dataanalysis.geo.algorithms;
import java.awt.Image;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import javax.imageio.ImageIO;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.ecoengine.datatypes.ColumnType;
import org.gcube.dataanalysis.ecoengine.datatypes.ColumnTypesList;
import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType;
import org.gcube.dataanalysis.ecoengine.datatypes.InputTable;
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.TableTemplates;
import org.gcube.dataanalysis.ecoengine.transducers.charts.AbstractChartsProducer;
import org.gcube.dataanalysis.ecoengine.utils.IOHelper;
import org.gcube.dataanalysis.geo.charts.GeoMapChart;
import org.gcube.dataanalysis.geo.charts.GeoTemporalPoint;
public class StaticGeoChartProducer extends AbstractChartsProducer {
protected static String longitudeParameter = "Longitude";
protected static String latitudeParameter = "Latitude";
@Override
protected void setInputParameters() {
List<TableTemplates> templates = new ArrayList<TableTemplates>();
templates.add(TableTemplates.GENERIC);
InputTable tinput = new InputTable(templates, inputTableParameter, "The input table");
inputs.add(tinput);
ColumnType p1 = new ColumnType(inputTableParameter, longitudeParameter, "The column containing longitude decimal values", "long", false);
ColumnType p2 = new ColumnType(inputTableParameter, latitudeParameter, "The column containing latitude decimal values", "lat", false);
ColumnTypesList q = new ColumnTypesList(inputTableParameter, quantitiesParameter, "The numeric quantities to visualize ", true);
inputs.add(p1);
inputs.add(p2);
inputs.add(q);
DatabaseType.addDefaultDBPars(inputs);
}
@Override
public String getDescription() {
return "An algorithm producing a charts that displays quantities as colors of countries. The color indicates the sum of the values recorded in a country.";
}
public String InfoRetrievalQuery(String table, String[] dimensions, String quantity, String time) {
if (quantity.length() == 0)
return "select distinct " + Arrays.toString(dimensions).replace("[", "").replace("]", "") + " from " + table;
else
return "select distinct " + Arrays.toString(dimensions).replace("[", "").replace("]", "") + " , " + quantity + " as quanta232a from " + table;
}
public String[] getDimensions() {
String[] dimensions = { IOHelper.getInputParameter(config, longitudeParameter), IOHelper.getInputParameter(config, latitudeParameter) };
return dimensions;
}
@Override
public LinkedHashMap<String , Object> createCharts(String[] dimensions, String quantity, String time, List<Object> rows, boolean displaychart) {
if (dimensions == null)
dimensions = new String[0];
List<GeoTemporalPoint> xyvalues = new ArrayList<GeoTemporalPoint>();
long t0 = System.currentTimeMillis();
AnalysisLogger.getLogger().debug("StaticGeoChartProducer: building Geo dataset");
for (Object row : rows) {
Object[] array = (Object[]) row;
Double lat = null;
Double longitude = null;
Double q = null;
try {
longitude = Double.parseDouble("" + array[0]);
lat = Double.parseDouble("" + array[1]);
if (quantity.length() >0)
q = Double.parseDouble("" + array[2]);
else
q = 0d;
} catch (Exception e) {
}
if (lat != null && longitude != null && q != null)
xyvalues.add(new GeoTemporalPoint(longitude, lat, q));
else
AnalysisLogger.getLogger().debug("StaticGeoChartProducer: skipping these values "+longitude+","+lat+","+q);
}
AnalysisLogger.getLogger().debug("StaticGeoChartProducer: producing charts");
LinkedHashMap<String , Object> charts = new LinkedHashMap<String, Object>();
try {
String baseImageName = new File(config.getPersistencePath(), "" + UUID.randomUUID()).getAbsolutePath();
String pointsImage = baseImageName + "_points.jpg";
if (xyvalues.size()>0){
GeoMapChart.createWorldImageWithPoints(config.getConfigPath(),xyvalues, pointsImage);
charts.put("Distribution of latitudes and longitudes points",ImageIO.read(new File(pointsImage)));
if (quantity.length()>0) {
AnalysisLogger.getLogger().debug("StaticGeoChartProducer: quantity is present, producing all the static geocharts");
String eezImage = baseImageName + "_eez.jpg";
GeoMapChart.createEEZWeightedImage(config.getConfigPath(),xyvalues, eezImage, config.getPersistencePath());
try{charts.put("Distribution of summed quantities over Exclusive Economic Zone delimitations",ImageIO.read(new File(eezImage)));}catch(Exception e){AnalysisLogger.getLogger().debug("StaticGeoChartProducer: WARNING could not produce EEZ chart");}
String faoImage = baseImageName + "_FAO.jpg";
GeoMapChart.createFAOAreasWeightedImage(config.getConfigPath(),xyvalues, faoImage, config.getPersistencePath());
try{charts.put("Distribution of summed quantities over FAO Major Area delimitations",ImageIO.read(new File(faoImage)));}catch(Exception e){AnalysisLogger.getLogger().debug("StaticGeoChartProducer: WARNING could not produce FAO chart");}
String worldImage = baseImageName + "_world.jpg";
GeoMapChart.createWorldWeightedImage(config.getConfigPath(),xyvalues, worldImage, config.getPersistencePath(),null,null);
try{charts.put("Distribution of summed quantities over emerged lands, divided per country",ImageIO.read(new File(worldImage)));}catch(Exception e){AnalysisLogger.getLogger().debug("StaticGeoChartProducer: WARNING could not country chart");}
}
else{
AnalysisLogger.getLogger().debug("StaticGeoChartProducer: quantity is absent, producing only one geochart");
}
}
else
AnalysisLogger.getLogger().debug("StaticGeoChartProducer: no viable point was found");
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().debug("StaticGeoChartProducer: error in producing GeoCharts " + e.getMessage());
}
AnalysisLogger.getLogger().debug("StaticGeoChartProducer: procedure finished in ms " + (System.currentTimeMillis() - t0));
return charts;
}
}

View File

@ -0,0 +1,132 @@
package org.gcube.dataanalysis.geo.algorithms;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.datatypes.ColumnType;
import org.gcube.dataanalysis.ecoengine.datatypes.ColumnTypesList;
import org.gcube.dataanalysis.ecoengine.datatypes.DatabaseType;
import org.gcube.dataanalysis.ecoengine.datatypes.InputTable;
import org.gcube.dataanalysis.ecoengine.datatypes.enumtypes.TableTemplates;
import org.gcube.dataanalysis.ecoengine.transducers.charts.TimeSeriesChartsTransducerer;
import org.gcube.dataanalysis.ecoengine.utils.IOHelper;
import org.gcube.dataanalysis.geo.charts.GeoMapChart;
import org.gcube.dataanalysis.geo.charts.GeoTemporalPoint;
public class TimeGeoChartProducer extends TimeSeriesChartsTransducerer {
protected static String longitudeParameter = "Longitude";
protected static String latitudeParameter = "Latitude";
@Override
protected void setInputParameters() {
List<TableTemplates> templates = new ArrayList<TableTemplates>();
templates.add(TableTemplates.GENERIC);
InputTable tinput = new InputTable(templates, inputTableParameter, "The input table");
inputs.add(tinput);
ColumnType p1 = new ColumnType(inputTableParameter, longitudeParameter, "The column containing longitude decimal values", "long", false);
ColumnType p2 = new ColumnType(inputTableParameter, latitudeParameter, "The column containing latitude decimal values", "lat", false);
ColumnTypesList q = new ColumnTypesList(inputTableParameter, quantitiesParameter, "The numeric quantities to visualize ", false);
ColumnType t = new ColumnType(inputTableParameter, timeParameter, "The column containing time information", "year", false);
inputs.add(p1);
inputs.add(p2);
inputs.add(q);
inputs.add(t);
DatabaseType.addDefaultDBPars(inputs);
}
@Override
public String getDescription() {
return "An algorithm producing an animated gif displaying quantities as colors in time. The color indicates the sum of the values recorded in a country.";
}
public String InfoRetrievalQuery(String table, String[] dimensions, String quantity, String time) {
return "select distinct " + Arrays.toString(dimensions).replace("[", "").replace("]", "") + " , " + quantity + "," + time + " from " + table;
}
public String[] getDimensions() {
String[] dimensions = { IOHelper.getInputParameter(config, longitudeParameter), IOHelper.getInputParameter(config, latitudeParameter) };
return dimensions;
}
@Override
public LinkedHashMap<String, Object> createCharts(String[] dimensions, String quantity, String time, List<Object> rows, boolean displaychart) {
if (dimensions == null)
dimensions = new String[0];
List<GeoTemporalPoint> xyvalues = new ArrayList<GeoTemporalPoint>();
long t0 = System.currentTimeMillis();
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: building Geo dataset");
for (Object row : rows) {
Object[] array = (Object[]) row;
Double lat = null;
Double longitude = null;
Double q = null;
String timel = null;
try {
longitude = Double.parseDouble("" + array[0]);
lat = Double.parseDouble("" + array[1]);
q = Double.parseDouble("" + array[2]);
if (array[3] != null)
timel = "" + array[3];
} catch (Exception e) {
}
if (lat != null && longitude != null && q != null && timel != null) {
xyvalues.add(new GeoTemporalPoint(longitude, lat, q, timel));
} else
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: skipping these values " + longitude + "," + lat + "," + q + "," + timel);
}
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: producing charts");
LinkedHashMap<String, Object> charts = new LinkedHashMap<String, Object>();
try {
String baseImageName = new File(config.getPersistencePath(), "" + UUID.randomUUID()).getAbsolutePath();
String timeImage = baseImageName + "_time.gif";
String cumulativeImage = baseImageName + "_cutime.gif";
String faotimeImage = baseImageName + "_faotime.gif";
String eeztimeImage = baseImageName + "_eeztime.gif";
String pointsImage = baseImageName + "points.gif";
if (xyvalues.size() > 0) {
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: producing Points Chart in time " + pointsImage);
GeoMapChart.createPointsImageInTime(config.getConfigPath(), xyvalues, pointsImage, config.getPersistencePath());
charts.put("A GIF file displaying the points recorded in the time frames of the dataset", new File(pointsImage));
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: producing World Chart in time " + timeImage);
GeoMapChart.createWorldWeightedImageInTime(config.getConfigPath(), xyvalues, timeImage, config.getPersistencePath(), false);
charts.put("A GIF file displaying the temporal trend of quantities in each time instant over emerged lands, divided per country", new File(timeImage));
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: producing cumulative World Chart in time " + cumulativeImage);
GeoMapChart.createWorldWeightedImageInTime(config.getConfigPath(), xyvalues, cumulativeImage, config.getPersistencePath(), true);
charts.put("A GIF file displaying the temporal trend of cumulative quantities over emerged lands, divided per country", new File(cumulativeImage));
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: producing EEZ World Chart in time " + eeztimeImage);
GeoMapChart.createEEZWeightedImageInTime(config.getConfigPath(), xyvalues, eeztimeImage, config.getPersistencePath(), true);
charts.put("A GIF file displaying the temporal trend of cumulative quantities over Exclusive Economic Zones", new File(eeztimeImage));
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: producing FAO Areas World Chart in time " + faotimeImage);
GeoMapChart.createFAOAreasWeightedImageInTime(config.getConfigPath(), xyvalues, faotimeImage, config.getPersistencePath(), true);
charts.put("A GIF file displaying the temporal trend of cumulative quantities over FAO Areas", new File(faotimeImage));
}
else
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: no point was found");
} catch (Exception e) {
e.printStackTrace();
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: error in producing GeoCharts " + e.getMessage());
AnalysisLogger.getLogger().debug(e);
}
AnalysisLogger.getLogger().debug("TimeGeoChartProducer: procedure finished in ms " + (System.currentTimeMillis() - t0));
return charts;
}
}

View File

@ -0,0 +1,336 @@
package org.gcube.dataanalysis.geo.charts;
import java.awt.Color;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.utils.GifSequenceWriter;
import org.gcube.dataanalysis.ecoengine.utils.TimeAnalyzer;
import org.gcube.dataanalysis.ecoengine.utils.Tuple;
import org.gcube.dataanalysis.geo.connectors.asc.AscRaster;
import org.gcube.dataanalysis.geo.connectors.asc.AscRasterReader;
import org.gcube.dataanalysis.geo.connectors.asc.AscRasterWriter;
import density.Grid;
import density.LazyGrid;
import density.Sample;
import density.ShrunkGrid;
import density.WorldImageProducer;
public class GeoMapChart {
public static List<Tuple<Double>> generateRandomWorldPoints() {
List<Tuple<Double>> xyvalues = new ArrayList<Tuple<Double>>();
for (int j = 0; j < 8000; j++) {
double randomx = ((180) * Math.random()) - 180 * Math.random();
double randomy = ((90) * Math.random()) - 90 * Math.random();
xyvalues.add(new Tuple<Double>(randomx, randomy));
}
return xyvalues;
}
public static void createWorldImageWithPoints(String configFolder, List<GeoTemporalPoint> xyvalues, String outImageFileName) throws Exception {
// URL is = ClassLoader.getSystemResource("raster_res/templatelayerres05.asc");
// GeoMapChart.class.getClassLoader().getResource("raster_res/templatelayerres05.asc");
String is = (new File(configFolder,"templatelayerres05.asc")).getAbsolutePath();
createImage(is, outImageFileName, xyvalues, true, 100d, 10000d, false, false,null);
}
public static void createWorldImageWithPointsAndFixedTime(String configFolder, List<GeoTemporalPoint> xyvalues, String outImageFileName, Date time) throws Exception {
String is = (new File(configFolder,"templatelayerres05.asc")).getAbsolutePath();
createImage(is, outImageFileName, xyvalues, true, 100d, 10000d, false, false,time);
}
private static List<Date> extractTimefromPoints(List<GeoTemporalPoint> points){
List<Date> times = new ArrayList<Date>();
HashMap<Date, String> timesh = new HashMap<Date, String>();
for (GeoTemporalPoint p : points){
timesh.put(p.time,"");
}
for (Date t: timesh.keySet()){
int i=0;
for (Date d:times){
if (d.after(t))
break;
i++;
}
times.add(i, t);
}
return times;
}
private static void createImage(String filepath, String outImageFileName, List<GeoTemporalPoint> xypoints, boolean displaypoints, double min, double max, boolean makelegend, boolean logscale, Date fixedTime) throws Exception {
Grid g = new ShrunkGrid(new LazyGrid(filepath), 2000);
double cellsize = g.getDimension().getcellsize();
double xll = g.getDimension().getxllcorner();
double yll = g.getDimension().getyllcorner();
// int nrows = g.getDimension().getnrows();
// int ncols = g.getDimension().getncols();
WorldImageProducer d = new WorldImageProducer(g);
AscRaster raster = new AscRaster(cellsize, -1, -1, xll, yll);
Date minimumTime = new Date(System.currentTimeMillis());
Date maximumTime = new Date(0);
HashMap<Date,String> timeFrames = new HashMap<Date, String>();
if (xypoints != null) {
Sample[] samps = new Sample[xypoints.size()];
int i = 0;
for (GeoTemporalPoint t : xypoints) {
double longitude = t.x;
double latitude = t.y;
if (minimumTime.after(t.time))
minimumTime = new Date(t.time.getTime());
if (maximumTime.before(t.time))
maximumTime = new Date(t.time.getTime());
if (timeFrames.get(t.time)==null)
timeFrames.put(t.time, "");
if (fixedTime!=null && t.time.compareTo(fixedTime)!=0)
continue;
samps[i] = new Sample(1, raster.latitude2Index(latitude), raster.longitude2Index(longitude), latitude, longitude, "sample");
i++;
}
if (displaypoints)
d.setTestSamples(samps);
}
// we leave this piece of code here for future developments
boolean logScale = logscale;
if (!logScale) {
d.setMode(1);
}
d.minval = min;
d.maxval = max;
d.visible = false;
d.makeLegend = makelegend;
d.makeTimeline = fixedTime!=null;
if (d.makeTimeline){
SimpleDateFormat sdf = new SimpleDateFormat(xypoints.get(0).timePattern, Locale.ENGLISH);
int timeidx = TimeAnalyzer.getTimeIndexInTimeRange(maximumTime, minimumTime, fixedTime, timeFrames.size());
d.setTime(timeFrames.size(), timeidx, sdf.format(minimumTime), sdf.format(fixedTime));
}
d.makeImage();
d.writeImage(outImageFileName, 1);
}
public static HashMap<Double, Double> createWorldWeightedImage(String configFolder,List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir, Date fixedTime, HashMap<Double, Double> weights) throws Exception {
String is = (new File(configFolder,"worldcountries_hires.asc")).getAbsolutePath();
return createWeightedImage(is, xypoints, outImageFileName, tempdir, false,fixedTime,weights);
}
public static void createWorldWeightedImageInTime(String configFolder,List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir, boolean cumulative) throws Exception {
String is = (new File(configFolder,"worldcountries_hires.asc")).getAbsolutePath();
createImageInTime(is, configFolder, xypoints, outImageFileName, tempdir, cumulative);
}
public static void createEEZWeightedImageInTime(String configFolder,List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir, boolean cumulative) throws Exception {
String is = (new File(configFolder,"eez.asc")).getAbsolutePath();
createImageInTime(is, configFolder, xypoints, outImageFileName, tempdir, cumulative);
}
public static void createFAOAreasWeightedImageInTime(String configFolder,List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir, boolean cumulative) throws Exception {
String is = (new File(configFolder,"faoareas.asc")).getAbsolutePath();
createImageInTime(is, configFolder, xypoints, outImageFileName, tempdir, cumulative);
}
public static void createImageInTime(String rastersupport, String configFolder,List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir, boolean cumulative) throws Exception {
List<Date> times = extractTimefromPoints(xypoints);
int i=1;
List<String> images = new ArrayList<String>();
HashMap<Double, Double> weights = null;
for (Date t:times){
String tempimg = new File(tempdir,i+"_"+UUID.randomUUID()+".png").getAbsolutePath();
if (!cumulative)
weights=null;
HashMap<Double, Double> weightstemp = createWeightedImage(rastersupport, xypoints, tempimg, tempdir, false, t,weights);
if (weightstemp!=null){
images.add(tempimg);
weights=weightstemp;
}
i++;
}
AnalysisLogger.getLogger().debug("GeoMapChart: Writing GIF "+outImageFileName);
GifSequenceWriter.writeGif(outImageFileName, images, 1500);
for (String image:images){
new File(image).delete();
}
}
public static void createPointsImageInTime(String configFolder,List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir) throws Exception {
List<Date> times = extractTimefromPoints(xypoints);
int i=1;
List<String> images = new ArrayList<String>();
for (Date t:times){
String tempimg = new File(tempdir,i+"_"+UUID.randomUUID()+".png").getAbsolutePath();
createWorldImageWithPointsAndFixedTime(configFolder,xypoints, tempimg, t);
images.add(tempimg);
i++;
}
AnalysisLogger.getLogger().debug("GeoMapChart: Writing GIF");
GifSequenceWriter.writeGif(outImageFileName, images, 1500);
for (String image:images){
new File(image).delete();
}
}
public static void createEEZWeightedImage(String configFolder,List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir) throws Exception {
String is = (new File(configFolder,"eez.asc")).getAbsolutePath();
createWeightedImage(is, xypoints, outImageFileName, tempdir, true,null,null);
}
public static void createFAOAreasWeightedImage(String configFolder,List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir) throws Exception {
String is = (new File(configFolder,"faoareas.asc")).getAbsolutePath();
createWeightedImage(is, xypoints, outImageFileName, tempdir, false,null,null);
}
public static HashMap<Double, Double> createWeightedImage(String rasterSupportFilePath, List<GeoTemporalPoint> xypoints, String outImageFileName, String tempdir, boolean logscale, Date fixedTime, HashMap<Double, Double> previousweights) throws Exception {
AscRasterReader reader = new AscRasterReader();
AscRaster raster = reader.readRaster(rasterSupportFilePath);
HashMap<Double, Double> countryweights = new HashMap<Double, Double>();
double max = -Double.MAX_VALUE;
double min = Double.MAX_VALUE;
for (GeoTemporalPoint triplet : xypoints) {
double x = triplet.x;
double y = triplet.y;
double weigh = triplet.weight;
Date time = triplet.time;
if (fixedTime!=null && time.compareTo(fixedTime)!=0)
continue;
int latid = raster.latitude2Index(y);
int lonid = raster.longitude2Index(x);
Double value = raster.getValue(latid, lonid);
// int[] lats = { latid - 1, latid + 1, latid - 2, latid + 2};
// int[] longs = { lonid - 1, lonid + 1, lonid - 2, lonid + 2};
int[] lats = { latid - 1, latid + 1};
int[] longs = { lonid - 1, lonid + 1};
// search nearby
if (Double.isNaN(value)) {
for (int la = 0; la < lats.length; la++) {
for (int lo = 0; lo < longs.length; lo++) {
value = raster.getValue(lats[la], longs[lo]);
if (!Double.isNaN(value))
break;
}
if (!Double.isNaN(value))
break;
}
}
//check again if the value is NaN
if (!Double.isNaN(value)) {
Double currentw = countryweights.get(value);
if (currentw != null) {
weigh += currentw;
}
else{
if (previousweights!=null){
currentw = previousweights.get(value);
if (currentw != null)
weigh += currentw;
}
}
if (weigh > max)
max = weigh;
if (weigh < min)
min = weigh;
countryweights.put(value, weigh);
}
}
//case in which we did not find any country in this year
if (countryweights.size()==0)
return null;
//add the previous missing weights
if (previousweights!=null){
for (Double country:previousweights.keySet()){
if (countryweights.get(country)==null){
Double pweigh = previousweights.get(country);
countryweights.put(country,pweigh);
if (pweigh > max)
max = pweigh;
if (pweigh < min)
min = pweigh;
}
}
}
//adjust min and max
if (min==max){
if (max>0)
min = 0;
else
max = 0;
}
/*
* for (Double key:countryweights.keySet()){ Double weigh = countryweights.get(key);
*
* if (weigh==0) System.out.println(key+":"+weigh); }
*/
AscRasterWriter writer = new AscRasterWriter();
int ncols = raster.getCols();
int nrows = raster.getRows();
for (int i = 0; i < nrows; i++) {
for (int j = 0; j < ncols; j++) {
double country = raster.getValue(i, j);
if (!Double.isNaN(country)) {
Double weigh = countryweights.get(country);
if (weigh != null)
raster.setValue(i, j, weigh);
else
raster.setValue(i, j, 0);
}
}
}
String ascfile = new File(tempdir, "" + UUID.randomUUID() + ".asc").getAbsolutePath();
writer.writeRaster(ascfile, raster);
createImage(ascfile, outImageFileName, xypoints, false, min, max, true, logscale,fixedTime);
System.gc();
boolean deleted = new File(ascfile).delete();
AnalysisLogger.getLogger().debug("GeoMapChart: deleted ASC file "+ascfile+" :"+deleted);
return countryweights;
}
}

View File

@ -0,0 +1,45 @@
package org.gcube.dataanalysis.geo.charts;
import java.util.Date;
import org.gcube.dataanalysis.ecoengine.utils.TimeAnalyzer;
public class GeoTemporalPoint {
public double x;
public double y;
public double z;
public double weight;
public Date time;
public String timePattern = "MM/dd/yyyy";
public GeoTemporalPoint(double x, double y, double z, double weight, String time) {
this.x = x;
this.y = y;
this.z = z;
this.weight = weight;
if (time == null)
this.time = new Date(System.currentTimeMillis());
else {
TimeAnalyzer tsa = new TimeAnalyzer();
Date timedate = tsa.string2Date(time);
String timePattern = tsa.getPattern();
this.time = timedate;
this.timePattern = timePattern;
}
}
public GeoTemporalPoint(double x, double y, String time) {
this(x, y, 0d, 1d, time);
}
public GeoTemporalPoint(double x, double y, double weight, String time) {
this(x, y, 0d, weight, time);
}
public GeoTemporalPoint(double x, double y, double weight) {
this(x, y, 0d, weight, null);
}
}

View File

@ -157,7 +157,7 @@ public class AscRaster {
}
public double getValue(int row, int column) {
if (row < rows && column < cols)
if (row < rows && column < cols && row>-1 && column>-1)
if (data[row][column]!= Double.parseDouble(NDATA))
return data[row][column];
else

View File

@ -0,0 +1,116 @@
package org.gcube.dataanalysis.geo.test;
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
import org.gcube.dataanalysis.ecoengine.configuration.AlgorithmConfiguration;
import org.gcube.dataanalysis.geo.algorithms.StaticGeoChartProducer;
import org.gcube.dataanalysis.geo.algorithms.TimeGeoChartProducer;
import org.junit.Test;
public class TestGeoCharts {
@Test
public void testStaticChart() throws Exception{
AnalysisLogger.setLogger("./cfg/" + AlgorithmConfiguration.defaultLoggerFile);
AlgorithmConfiguration config = new AlgorithmConfiguration();
config.setConfigPath("./cfg/");
config.setPersistencePath("./chartstmp/");
config.setParam("DatabaseUserName", "utente");
config.setParam("DatabasePassword", "d4science");
config.setParam("DatabaseURL", "jdbc:postgresql://statistical-manager.d.d4science.research-infrastructures.eu/testdb");
config.setParam("DatabaseDriver", "org.postgresql.Driver");
config.setParam("InputTable", "timeseries_id08b3abb9_c7b0_4b82_8117_64b69055416f");
config.setParam("Longitude", "x");
config.setParam("Latitude", "y");
config.setParam("Quantities", "fvalue");
config.setGcubeScope("/gcube/devsec/devVRE");
StaticGeoChartProducer cscreator = new StaticGeoChartProducer();
cscreator.setConfiguration(config);
cscreator.compute();
System.out.println("DONE! "+cscreator.getOutput());
}
@Test
public void testStaticChartNoQuantities() throws Exception{
AnalysisLogger.setLogger("./cfg/" + AlgorithmConfiguration.defaultLoggerFile);
AlgorithmConfiguration config = new AlgorithmConfiguration();
config.setConfigPath("./cfg/");
config.setPersistencePath("./chartstmp/");
config.setParam("DatabaseUserName", "utente");
config.setParam("DatabasePassword", "d4science");
config.setParam("DatabaseURL", "jdbc:postgresql://statistical-manager.d.d4science.research-infrastructures.eu/testdb");
config.setParam("DatabaseDriver", "org.postgresql.Driver");
config.setParam("InputTable", "timeseries_id08b3abb9_c7b0_4b82_8117_64b69055416f");
config.setParam("Longitude", "x");
config.setParam("Latitude", "y");
config.setGcubeScope("/gcube/devsec/devVRE");
StaticGeoChartProducer cscreator = new StaticGeoChartProducer();
cscreator.setConfiguration(config);
cscreator.compute();
System.out.println("DONE! "+cscreator.getOutput());
}
@Test
public void testTimeChart() throws Exception{
AnalysisLogger.setLogger("./cfg/" + AlgorithmConfiguration.defaultLoggerFile);
AlgorithmConfiguration config = new AlgorithmConfiguration();
config.setConfigPath("./cfg/");
config.setPersistencePath("./chartstmp/");
config.setParam("DatabaseUserName", "utente");
config.setParam("DatabasePassword", "d4science");
config.setParam("DatabaseURL", "jdbc:postgresql://statistical-manager.d.d4science.research-infrastructures.eu/testdb");
config.setParam("DatabaseDriver", "org.postgresql.Driver");
config.setParam("InputTable", "timeseries_idf1ae1dbe_a2b2_41d9_8e8b_30c739a47903");
config.setParam("Longitude", "decimallongitude");
config.setParam("Latitude", "decimallatitude");
config.setParam("Quantities", "maxdepth");
config.setParam("Time", "time");
config.setGcubeScope("/gcube/devsec/devVRE");
TimeGeoChartProducer cscreator = new TimeGeoChartProducer();
cscreator.setConfiguration(config);
cscreator.compute();
System.out.println("DONE! "+cscreator.getOutput());
}
@Test
public void testSmallTimeChart() throws Exception{
AnalysisLogger.setLogger("./cfg/" + AlgorithmConfiguration.defaultLoggerFile);
AlgorithmConfiguration config = new AlgorithmConfiguration();
config.setConfigPath("./cfg/");
config.setPersistencePath("./chartstmp/");
config.setParam("DatabaseUserName", "utente");
config.setParam("DatabasePassword", "d4science");
config.setParam("DatabaseURL", "jdbc:postgresql://statistical-manager.d.d4science.research-infrastructures.eu/testdb");
config.setParam("DatabaseDriver", "org.postgresql.Driver");
config.setParam("InputTable", "generic_idc3f49110_995b_45cd_9846_240f25c136be");
config.setParam("Longitude", "decimallongitude");
config.setParam("Latitude", "decimallatitude");
config.setParam("Quantities", "maxdepth");
config.setParam("Time", "eventdate");
config.setGcubeScope("/gcube/devsec/devVRE");
TimeGeoChartProducer cscreator = new TimeGeoChartProducer();
cscreator.setConfiguration(config);
cscreator.compute();
System.out.println("DONE! "+cscreator.getOutput());
}
}

View File

@ -0,0 +1,16 @@
package org.gcube.dataanalysis.geo.test;
import java.net.URL;
import org.gcube.dataanalysis.geo.charts.GeoMapChart;
public class TestResourcesRetrieval {
public static void main(String args[]){
URL is = GeoMapChart.class.getClassLoader().getResource("raster_res/templatelayerres05.asc");
System.out.println(is.getPath());
}
}