annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/PolygonDatasetProducer.java @ 458:92d6cf448598

Improved raster tile based height evaluation. gnv-artifacts/trunk@512 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 06 Jan 2010 10:09:51 +0000
parents b624879d2902
children f7038820df2e
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.RingsHandler;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 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
10
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.PolygonSeries;
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.PolygonDataset;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 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
14
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
15 /**
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
16 * @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
17 */
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 public class PolygonDatasetProducer
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 implements RingsHandler
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 protected double minX;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 protected double minY;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 protected double maxX;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 protected double maxY;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 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
27
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 protected PolygonDatasetProducer() {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 public PolygonDatasetProducer(
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 double minX, double minY,
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33 double maxX, double maxY
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 ) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 this.minX = minX;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 this.minY = minY;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 this.maxX = maxX;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 this.maxY = maxY;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 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
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 public void handleRings(
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 List<Edge> rings,
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 int value,
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 int width,
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 int height
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 ) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 if (value == -1) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 return;
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
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 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
55
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 PolygonSeries ps = (PolygonSeries)polygonSeries.get(v);
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 if (ps == null) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 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
60 ps.setAttribute("fill", v);
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 TDoubleArrayList vertices = new TDoubleArrayList();
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 /* 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
66 * 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
67 * 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
68 */
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
70 double b1 = minX;
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
71 double m1 = width != 1
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
72 ? (maxX - minX)/(width-1)
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
73 : 0d;
436
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
75 double b2 = minY;
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
76 double m2 = height != 1
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
77 ? (maxY - minY)/(height-1)
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
78 : 0d;
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 for (Edge head: rings) {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 Edge current = head;
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 do {
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
83 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
84 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
85 }
437
b624879d2902 Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 436
diff changeset
86 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
87 ps.addRing(new CompactXYItems(vertices.toNativeArray()));
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 vertices.clear();
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 public PolygonDataset getPolygonDataset() {
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 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
94 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 }
6642ab6c583c Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org