annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/PolygonDatasetProducer.java @ 752:7bc3d9f0cf3c

Modified the Workflow for Horizontalcrosssections so that the Inputvalues of the Mapviewer-Interface take affect. gnv-artifacts/trunk@795 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Fri, 19 Mar 2010 08:34:40 +0000
parents 1bf058f1a2d1
children 9a828e5a2390
rev   line source
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.raster;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.util.List;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.HashMap;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import gnu.trove.TDoubleArrayList;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import de.intevation.gnv.raster.Vectorizer.Edge;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import de.intevation.gnv.jfreechart.PolygonSeries;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import de.intevation.gnv.jfreechart.PolygonDataset;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 import de.intevation.gnv.jfreechart.CompactXYItems;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
14 /**
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
15 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
16 */
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 public class PolygonDatasetProducer
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 437
diff changeset
18 extends AbstractProducer
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 protected HashMap<Integer, PolygonSeries> polygonSeries;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 protected PolygonDatasetProducer() {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public PolygonDatasetProducer(
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 double minX, double minY,
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 double maxX, double maxY
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 ) {
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 437
diff changeset
30 super(minX, minY, maxX, maxY);
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 polygonSeries = new HashMap<Integer, PolygonSeries>();
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public void handleRings(
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 List<Edge> rings,
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 int value,
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 int width,
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 int height
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 ) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 if (value == -1) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 return;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 Integer v = Integer.valueOf(value);
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
465
f7038820df2e Added support to trace rasters to JTS multi polygons and multi line strings.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 437
diff changeset
46 PolygonSeries ps = polygonSeries.get(v);
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 if (ps == null) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 polygonSeries.put(v, ps = new PolygonSeries());
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 ps.setAttribute("fill", v);
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53 TDoubleArrayList vertices = new TDoubleArrayList();
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 /* minX = 0*m1 + b1 <=> b1 = minX
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 * maxX = (width-1)*m1 + b1
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 * m1 = (maxX - minX)/(width-1)
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 */
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
60 double b1 = minX;
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
61 double m1 = width != 1
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
62 ? (maxX - minX)/(width-1)
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
63 : 0d;
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
65 double b2 = minY;
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
66 double m2 = height != 1
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
67 ? (maxY - minY)/(height-1)
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
68 : 0d;
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 for (Edge head: rings) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71 Edge current = head;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 do {
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
73 vertices.add(m1*(current.a % width) + b1);
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
74 vertices.add(m2*(current.a / width) + b2);
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
76 while ((current = current.next) != head);
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 ps.addRing(new CompactXYItems(vertices.toNativeArray()));
521
1bf058f1a2d1 Generate seabed polygon to "Profilschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 465
diff changeset
78 vertices.reset();
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 public PolygonDataset getPolygonDataset() {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 return new PolygonDataset(polygonSeries.values());
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org