Mercurial > dive4elements > gnv-client
changeset 432:6a70e8883307
Added some type safety. Fixed z value bug in reading database preprocessing. Only dissemble WKT points if really needed.
gnv-artifacts/trunk@480 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 23 Dec 2009 09:45:40 +0000 |
parents | 422275fc9927 |
children | 828df3ddb758 |
files | gnv-artifacts/ChangeLog gnv-artifacts/src/main/java/de/intevation/gnv/math/AttributedXYColumns.java gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java |
diffstat | 4 files changed, 66 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/gnv-artifacts/ChangeLog Wed Dec 23 06:53:46 2009 +0000 +++ b/gnv-artifacts/ChangeLog Wed Dec 23 09:45:40 2009 +0000 @@ -1,3 +1,20 @@ +2009-12-23 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java: + When preprocessing database data only dissamble WKT points if we + have to. + Read z values as double value now. + Commented out CSV export because it takes the database data + as data which is not correct here. TODO: We need to implement some output + based on the interpolated data. + Added some type safety to better match the 2D code. + + * src/main/java/de/intevation/gnv/math/AttributedXYColumns.java: Stores + XYColumns in ArrayList for better reused of the 2D code. + + * src/main/java/de/intevation/gnv/math/XYColumn.java: Removed toArray() + method because its not needed any longer. + 2009-12-23 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/gnv/math/XYColumn.java: Extends from
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/AttributedXYColumns.java Wed Dec 23 06:53:46 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/AttributedXYColumns.java Wed Dec 23 09:45:40 2009 +0000 @@ -2,22 +2,24 @@ import java.util.Map; import java.util.HashMap; +import java.util.List; + import java.io.Serializable; public class AttributedXYColumns implements Serializable { - protected XYColumn[] columns; - protected Map attributes; + protected List<? extends XYColumn> columns; + protected Map attributes; public AttributedXYColumns() { } - public AttributedXYColumns(XYColumn[] columns) { + public AttributedXYColumns(List<? extends XYColumn> columns) { this(columns, null); } - public AttributedXYColumns(XYColumn[] columns, Map attributes) { + public AttributedXYColumns(List<? extends XYColumn> columns, Map attributes) { this.columns = columns; this.attributes = attributes; } @@ -27,17 +29,19 @@ } public void setAttribute(Object key, Object value) { - if (attributes == null) + if (attributes == null) { attributes = new HashMap(); + } attributes.put(key, value); } - public XYColumn[] getXYColumns() { + public List<? extends XYColumn> getXYColumns() { return columns; } - public void setXYColumns(XYColumn[] columns) { + public void setXYColumns(List<? extends XYColumn> columns) { this.columns = columns; } } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java Wed Dec 23 06:53:46 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java Wed Dec 23 09:45:40 2009 +0000 @@ -10,7 +10,7 @@ public class XYColumn extends Point2d { - protected List values; + protected List<HeightValue> values; public XYColumn() { } @@ -21,13 +21,13 @@ public void add(HeightValue value) { if (values == null) { - values = new ArrayList(); + values = new ArrayList<HeightValue>(); } values.add(value); } - public HeightValue[] getValues() { - return (HeightValue[]) values.toArray(new HeightValue[values.size()]); + public List<HeightValue> getValues() { + return values; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Wed Dec 23 06:53:46 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java Wed Dec 23 09:45:40 2009 +0000 @@ -7,18 +7,18 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; + import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Locale; import java.util.Map; +import java.util.ArrayList; import org.apache.log4j.Logger; import org.jfree.chart.ChartTheme; -import org.w3c.dom.Node; - import net.sf.ehcache.Element; import au.com.bytecode.opencsv.CSVWriter; @@ -29,14 +29,17 @@ import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; -import de.intevation.artifactdatabase.Config; import de.intevation.gnv.artifacts.cache.CacheFactory; + import de.intevation.gnv.chart.Chart; import de.intevation.gnv.chart.ChartLabels; import de.intevation.gnv.chart.ChartStyle; + import de.intevation.gnv.chart.exception.TechnicalChartException; + import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.base.ResultDescriptor; + import de.intevation.gnv.geobackend.base.query.QueryExecutor; import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; import de.intevation.gnv.geobackend.base.query.exception.QueryException; @@ -49,8 +52,10 @@ import de.intevation.gnv.state.describedata.KeyValueDescibeData; import de.intevation.gnv.state.exception.StateException; import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; + import de.intevation.gnv.statistics.Statistics; import de.intevation.gnv.statistics.VerticalProfileStatistics; + import de.intevation.gnv.utils.WKTUtils; /** @@ -158,8 +163,9 @@ protected AttributedXYColumns preProcess(Collection results) { + AttributedXYColumns attColumns = new AttributedXYColumns(); - Map map = new HashMap(1013); + Map<IJKey, XYColumn> map = new HashMap<IJKey, XYColumn>(1013); Iterator iter = results.iterator(); int sIdx = -1; @@ -194,33 +200,27 @@ } } - try { - Point point = (Point) new WKTReader().read( - result.getString(sIdx)); - double v = result.getDouble(vIdx); - int i = result.getInteger(iIdx); - int j = result.getInteger(jIdx); - int k = result.getInteger(kIdx); - int z = result.getInteger(zIdx); - - IJKey key = new IJKey(i, j); + double v = result.getDouble(vIdx); + double z = result.getDouble(zIdx); + int i = result.getInteger(iIdx); + int j = result.getInteger(jIdx); + int k = result.getInteger(kIdx); - XYColumn col = (XYColumn)map.get(key); + IJKey key = new IJKey(i, j); - if (col == null) { - col = new XYColumn(point.getX(), point.getY(), i, j); - map.put(key, col); - } + XYColumn col = (XYColumn)map.get(key); - col.add(new HeightValue(z, v, k)); + if (col == null) { + Coordinate coord = WKTUtils.toCoordinate(result.getString(sIdx)); + if (coord == null) coord = new Coordinate(); + col = new XYColumn(coord.x, coord.z, i, j); + map.put(key, col); } - catch (ParseException pe) { - log.warn("Error while parsing geometry.", pe); - } + + col.add(new HeightValue(z, v, k)); } - XYColumn[] cols = (XYColumn[])map.values().toArray( - new XYColumn[map.size()]); + ArrayList<XYColumn> cols = new ArrayList<XYColumn>(map.values()); attColumns.setXYColumns(cols); return attColumns; @@ -317,11 +317,13 @@ * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createCSV(java.io.OutputStream, java.util.Collection) */ @Override - protected void createCSV(OutputStream outputStream, - Collection<Result> chartResult) - throws UnsupportedEncodingException, - IOException, - StateException { + protected void createCSV( + OutputStream outputStream, + Collection<Result> chartResult + ) + throws UnsupportedEncodingException, IOException, StateException + { + /* // TODO: Implement a substitution which makes sense. if (chartResult != null) { try { CSVWriter writer = new CSVWriter(new OutputStreamWriter( @@ -357,6 +359,7 @@ throw new StateException( "No Data given for generating an CSV-File."); } + */ } - } +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: