Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java @ 521:1bf058f1a2d1
Generate seabed polygon to "Profilschnitte".
gnv-artifacts/trunk@615 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 24 Jan 2010 20:24:03 +0000 |
parents | 79e80c289018 |
children | f598702b2a10 |
comparison
equal
deleted
inserted
replaced
520:a8f6ca59b26e | 521:1bf058f1a2d1 |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.state.profile.verticalcrosssection; | 1 package de.intevation.gnv.state.profile.verticalcrosssection; |
2 | |
3 import com.vividsolutions.jts.geom.Coordinate; | |
4 | |
5 import de.intevation.artifacts.CallContext; | |
6 | |
7 import de.intevation.gnv.artifacts.cache.CacheFactory; | |
8 | |
9 import de.intevation.gnv.artifacts.context.GNVArtifactContext; | |
10 | |
11 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | |
12 | |
13 import de.intevation.gnv.chart.Chart; | |
14 import de.intevation.gnv.chart.ChartLabels; | |
15 import de.intevation.gnv.chart.VerticalCrossSectionChart; | |
16 | |
17 import de.intevation.gnv.geobackend.base.Result; | |
18 import de.intevation.gnv.geobackend.base.ResultDescriptor; | |
19 | |
20 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | |
21 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | |
22 | |
23 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | |
24 | |
25 import de.intevation.gnv.geobackend.sde.datasources.RasterObject; | |
26 | |
27 import de.intevation.gnv.jfreechart.PolygonDataset; | |
28 import de.intevation.gnv.jfreechart.PolygonSeries; | |
29 | |
30 import de.intevation.gnv.math.AttributedXYColumns; | |
31 import de.intevation.gnv.math.HeightValue; | |
32 import de.intevation.gnv.math.IJKey; | |
33 import de.intevation.gnv.math.Interpolation3D; | |
34 import de.intevation.gnv.math.LinearMetrics; | |
35 import de.intevation.gnv.math.QueriedXYDepth; | |
36 import de.intevation.gnv.math.XYColumn; | |
37 | |
38 import de.intevation.gnv.raster.Filter; | |
39 import de.intevation.gnv.raster.IsoAttributeGenerator; | |
40 import de.intevation.gnv.raster.IsoPolygonSeriesProducer; | |
41 import de.intevation.gnv.raster.Palette; | |
42 import de.intevation.gnv.raster.PaletteManager; | |
43 import de.intevation.gnv.raster.PolygonDatasetProducer; | |
44 import de.intevation.gnv.raster.Raster; | |
45 import de.intevation.gnv.raster.Vectorizer; | |
46 | |
47 import de.intevation.gnv.state.InputData; | |
48 | |
49 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | |
50 | |
51 import de.intevation.gnv.state.exception.StateException; | |
52 | |
53 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; | |
54 | |
55 import de.intevation.gnv.statistics.Statistics; | |
56 import de.intevation.gnv.statistics.VerticalCrossSectionStatistics; | |
57 | |
58 import de.intevation.gnv.utils.DistanceCalculator; | |
59 import de.intevation.gnv.utils.StringUtils; | |
60 import de.intevation.gnv.utils.WKTUtils; | |
61 | |
62 import java.awt.Dimension; | |
63 import java.awt.Paint; | |
5 | 64 |
6 import java.io.IOException; | 65 import java.io.IOException; |
7 import java.io.OutputStream; | 66 import java.io.OutputStream; |
8 import java.io.OutputStreamWriter; | |
9 import java.io.UnsupportedEncodingException; | 67 import java.io.UnsupportedEncodingException; |
10 | 68 |
69 import java.util.ArrayList; | |
70 import java.util.Arrays; | |
11 import java.util.Collection; | 71 import java.util.Collection; |
12 import java.util.HashMap; | 72 import java.util.HashMap; |
13 import java.util.Iterator; | 73 import java.util.Iterator; |
74 import java.util.List; | |
14 import java.util.Locale; | 75 import java.util.Locale; |
15 import java.util.Map; | 76 import java.util.Map; |
16 import java.util.ArrayList; | 77 |
17 import java.util.Arrays; | 78 import net.sf.ehcache.Element; |
18 import java.util.List; | |
19 | |
20 import java.awt.Dimension; | |
21 | 79 |
22 import org.apache.log4j.Logger; | 80 import org.apache.log4j.Logger; |
23 | 81 |
24 import org.jfree.chart.ChartTheme; | 82 import org.jfree.chart.ChartTheme; |
25 | |
26 import net.sf.ehcache.Element; | |
27 | |
28 import au.com.bytecode.opencsv.CSVWriter; | |
29 | |
30 import com.vividsolutions.jts.geom.Point; | |
31 import com.vividsolutions.jts.geom.Coordinate; | |
32 | |
33 import de.intevation.artifacts.CallContext; | |
34 | |
35 import de.intevation.gnv.artifacts.context.GNVArtifactContext; | |
36 | |
37 import de.intevation.gnv.artifacts.cache.CacheFactory; | |
38 import de.intevation.gnv.artifacts.ressource.RessourceFactory; | |
39 | |
40 import de.intevation.gnv.chart.Chart; | |
41 import de.intevation.gnv.chart.ChartLabels; | |
42 import de.intevation.gnv.chart.ChartStyle; | |
43 import de.intevation.gnv.chart.VerticalCrossSectionChart; | |
44 | |
45 import de.intevation.gnv.chart.exception.TechnicalChartException; | |
46 | |
47 import de.intevation.gnv.geobackend.base.Result; | |
48 import de.intevation.gnv.geobackend.base.ResultDescriptor; | |
49 | |
50 import de.intevation.gnv.geobackend.base.query.QueryExecutor; | |
51 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; | |
52 import de.intevation.gnv.geobackend.base.query.exception.QueryException; | |
53 | |
54 import de.intevation.gnv.math.AttributedXYColumns; | |
55 import de.intevation.gnv.math.HeightValue; | |
56 import de.intevation.gnv.math.QueriedXYDepth; | |
57 import de.intevation.gnv.math.XYColumn; | |
58 import de.intevation.gnv.math.IJKey; | |
59 import de.intevation.gnv.math.LinearMetrics; | |
60 import de.intevation.gnv.math.Interpolation3D; | |
61 | |
62 import de.intevation.gnv.state.InputData; | |
63 | |
64 import de.intevation.gnv.state.describedata.KeyValueDescibeData; | |
65 import de.intevation.gnv.state.exception.StateException; | |
66 import de.intevation.gnv.state.timeseries.TimeSeriesOutputState; | |
67 | |
68 import de.intevation.gnv.statistics.Statistics; | |
69 import de.intevation.gnv.statistics.VerticalCrossSectionStatistics; | |
70 | |
71 import de.intevation.gnv.utils.DistanceCalculator; | |
72 import de.intevation.gnv.utils.WKTUtils; | |
73 import de.intevation.gnv.utils.StringUtils; | |
74 | |
75 import de.intevation.gnv.raster.Filter; | |
76 import de.intevation.gnv.raster.PaletteManager; | |
77 import de.intevation.gnv.raster.Palette; | |
78 import de.intevation.gnv.raster.Raster; | |
79 import de.intevation.gnv.raster.PolygonDatasetProducer; | |
80 import de.intevation.gnv.raster.IsoAttributeGenerator; | |
81 import de.intevation.gnv.raster.IsoPolygonSeriesProducer; | |
82 import de.intevation.gnv.raster.Vectorizer; | |
83 | |
84 import de.intevation.gnv.jfreechart.PolygonDataset; | |
85 import de.intevation.gnv.jfreechart.PolygonSeries; | |
86 | |
87 import de.intevation.gnv.geobackend.sde.datasources.RasterObject; | |
88 | 83 |
89 /** | 84 /** |
90 * @author Tim Englich (tim.englich@intevation.de) | 85 * @author Tim Englich (tim.englich@intevation.de) |
91 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | 86 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) |
92 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | 87 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
93 */ | 88 */ |
94 public class VerticalCrossSectionOutputState extends TimeSeriesOutputState { | 89 public class VerticalCrossSectionOutputState extends TimeSeriesOutputState { |
95 | 90 |
96 public static final String CHART_TYPE = "verticalcrosssection"; | 91 public static final String CHART_TYPE = "verticalcrosssection"; |
92 | |
93 public static final Integer GROUND_FILL_INDEX = Integer.valueOf(-2); | |
97 | 94 |
98 public static final String[] ATTRIBUTE_LIST = { | 95 public static final String[] ATTRIBUTE_LIST = { |
99 "SHAPE", | 96 "SHAPE", |
100 "Z", | 97 "Z", |
101 "YORDINATE", | 98 "YORDINATE", |
284 return palettes != null | 281 return palettes != null |
285 ? palettes | 282 ? palettes |
286 : new HashMap<Integer, PaletteManager>(); | 283 : new HashMap<Integer, PaletteManager>(); |
287 } | 284 } |
288 | 285 |
286 private static Paint getGroundFill(CallContext callContext) { | |
287 GNVArtifactContext context = | |
288 (GNVArtifactContext)callContext.globalContext(); | |
289 Paint fill = (Paint)context.get( | |
290 GNVArtifactContext.VERTICAL_CROSS_SECTION_GROUND_FILL_KEY); | |
291 return fill != null | |
292 ? fill | |
293 : GNVArtifactContext.DEFAULT_VERTICAL_CROSS_SECTION_GROUND_FILL; | |
294 } | |
295 | |
289 public static final double EPSILON = 1e-5d; | 296 public static final double EPSILON = 1e-5d; |
290 | 297 |
291 protected Object process( | 298 protected Object process( |
292 List<Coordinate> path, | 299 List<Coordinate> path, |
293 AttributedXYColumns columns, | 300 AttributedXYColumns columns, |
375 int numRegions = new Vectorizer(intRaster, rasterSize.width) | 382 int numRegions = new Vectorizer(intRaster, rasterSize.width) |
376 .process(pdsp); | 383 .process(pdsp); |
377 | 384 |
378 PolygonDataset pds = pdsp.getPolygonDataset(); | 385 PolygonDataset pds = pdsp.getPolygonDataset(); |
379 | 386 |
387 // Count number of colors before generating seabed | |
388 // because its used to determine the number of iso lines. | |
380 int numColors = pds.getSeriesCount(); | 389 int numColors = pds.getSeriesCount(); |
381 | 390 |
382 if (debug) { | 391 if (debug) { |
383 log.debug("number of regions: " + numRegions); | 392 log.debug("number of regions: " + numRegions); |
384 log.debug("number of colors: " + numColors); | 393 log.debug("number of colors: " + numColors); |
394 } | |
395 | |
396 // generate seabed polygon | |
397 | |
398 PolygonSeries seabed = OutputHelper.createSeabedPolygon( | |
399 interpolation, | |
400 GROUND_FILL_INDEX); | |
401 | |
402 if (seabed != null) { | |
403 pds.addSeries(seabed); | |
385 } | 404 } |
386 | 405 |
387 // generate iso lines | 406 // generate iso lines |
388 | 407 |
389 int numIso; | 408 int numIso; |
522 if (!(result instanceof AttributedXYColumns)) { | 541 if (!(result instanceof AttributedXYColumns)) { |
523 log.error("result of wrong type"); | 542 log.error("result of wrong type"); |
524 return null; | 543 return null; |
525 } | 544 } |
526 | 545 |
527 AttributedXYColumns columns = | 546 AttributedXYColumns columns = (AttributedXYColumns)result; |
528 (AttributedXYColumns)result; | |
529 | 547 |
530 Integer parameterId = | 548 Integer parameterId = |
531 (Integer)columns.getAttribute("GROUP1"); // XXX: hardcoded | 549 (Integer)columns.getAttribute("GROUP1"); // XXX: hardcoded |
532 | 550 |
533 if (parameterId == null) { | 551 if (parameterId == null) { |
543 if (paletteManager == null) { | 561 if (paletteManager == null) { |
544 log.error("no palette found for parameter id " + parameterId); | 562 log.error("no palette found for parameter id " + parameterId); |
545 return null; | 563 return null; |
546 } | 564 } |
547 | 565 |
566 HashMap<Integer, Paint> special = new HashMap<Integer, Paint>(); | |
567 special.put(GROUND_FILL_INDEX, getGroundFill(callContext)); | |
568 | |
548 chart = new VerticalCrossSectionChart( | 569 chart = new VerticalCrossSectionChart( |
549 columns, | 570 columns, |
550 paletteManager.getBase(), | 571 paletteManager.getBase(), |
572 special, | |
551 locale, | 573 locale, |
552 chartLables); | 574 chartLables); |
553 | 575 |
554 chart.generateChart(); | 576 chart.generateChart(); |
555 | 577 |
558 purifyChart(chart, uuid); | 580 purifyChart(chart, uuid); |
559 } | 581 } |
560 | 582 |
561 return chart; | 583 return chart; |
562 } | 584 } |
563 | |
564 | |
565 /** | |
566 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#createChart(java.io.OutputStream, | |
567 * java.util.Collection, java.util.Collection, java.lang.String, | |
568 * de.intevation.gnv.chart.ChartStyle, | |
569 * de.intevation.gnv.chart.ChartLabels) | |
570 */ | |
571 /* | |
572 @Override | |
573 protected void createChart(OutputStream outputStream, | |
574 Collection<KeyValueDescibeData> parameters, | |
575 Collection<KeyValueDescibeData> measurements, | |
576 Collection<KeyValueDescibeData> dates, | |
577 ChartStyle chartStyle, ChartLabels chartLables, | |
578 String uuid) throws IOException, | |
579 TechnicalChartException { | |
580 new VerticalCrossSectionChartFactory().createProfileChart(chartLables, | |
581 chartStyle, parameters, measurements, dates, outputStream, this | |
582 .getChartResult(uuid)); | |
583 } | |
584 */ | |
585 | 585 |
586 /** | 586 /** |
587 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() | 587 * @see de.intevation.gnv.state.timeseries.TimeSeriesOutputState#getStatisticsGenerator() |
588 */ | 588 */ |
589 @Override | 589 @Override |
599 OutputStream outputStream, | 599 OutputStream outputStream, |
600 Collection<Result> chartResult | 600 Collection<Result> chartResult |
601 ) | 601 ) |
602 throws UnsupportedEncodingException, IOException, StateException | 602 throws UnsupportedEncodingException, IOException, StateException |
603 { | 603 { |
604 /* // TODO: Implement a substitution which makes sense. | 604 // TODO: Implement a substitution which makes sense. |
605 if (chartResult != null) { | |
606 try { | |
607 CSVWriter writer = new CSVWriter(new OutputStreamWriter( | |
608 outputStream, "ISO-8859-1"), ','); | |
609 // USE THIS ENCODING BECAUSE OF | |
610 // PROBLEMS WITH EXCEL AND UTF-8 | |
611 Iterator<Result> it = chartResult.iterator(); | |
612 WKTReader wktReader = new WKTReader(); | |
613 while (it.hasNext()) { | |
614 Result result = it.next(); | |
615 int i = 0; | |
616 String[] entries = new String[9]; | |
617 Point p = (Point)wktReader.read(result.getString("SHAPE")); | |
618 entries[i++] = ""+p.getX(); | |
619 entries[i++] = ""+p.getY(); | |
620 entries[i++] = result.getString("Z"); | |
621 entries[i++] = result.getString("YORDINATE"); | |
622 entries[i++] = result.getString("GROUP1"); | |
623 entries[i++] = result.getString("GROUP2"); | |
624 entries[i++] = result.getString("IPOSITION"); | |
625 entries[i++] = result.getString("JPOSITION"); | |
626 entries[i++] = result.getString("KPOSITION"); | |
627 writer.writeNext(entries); | |
628 } | |
629 writer.close(); | |
630 } catch (ParseException e) { | |
631 log.error(e,e); | |
632 throw new StateException( | |
633 "Exception occured while parsing an Point from WKT."); | |
634 } | |
635 } else { | |
636 log.error("No Data given for generating an CSV-File."); | |
637 throw new StateException( | |
638 "No Data given for generating an CSV-File."); | |
639 } | |
640 */ | |
641 } | 605 } |
642 } | 606 } |
643 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 607 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |