Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/GridCell.java @ 775:eedad2ddad14
Removed race-condition while shapefile creation (issue164).
gnv-artifacts/trunk@841 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 26 Mar 2010 15:20:32 +0000 |
parents | b248531fa20b |
children | c4156275c1e1 |
rev | line source |
---|---|
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.math; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
593
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
3 import com.vividsolutions.jts.algorithm.CGAlgorithms; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
4 |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import com.vividsolutions.jts.geom.Coordinate; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 import com.vividsolutions.jts.geom.Envelope; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import com.vividsolutions.jts.geom.Geometry; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import com.vividsolutions.jts.geom.GeometryFactory; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 import com.vividsolutions.jts.geom.LinearRing; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import com.vividsolutions.jts.geom.Point; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import com.vividsolutions.jts.geom.Polygon; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import com.vividsolutions.jts.index.ItemVisitor; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import java.io.Serializable; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.util.ArrayList; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import java.util.HashMap; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import java.util.List; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
517
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
21 import org.apache.log4j.Logger; |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
22 |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 /** |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 */ |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 public class GridCell |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 implements Serializable |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 { |
517
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
29 private static Logger log = Logger.getLogger(GridCell.class); |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
30 |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 public static final class CellFinder |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 implements ItemVisitor |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 public GridCell found; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 protected Point point; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 public CellFinder() { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 public void prepare(Coordinate center) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 found = null; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 point = GEOMETRY_FACTORY.createPoint(center); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 public void visitItem(Object item) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 if (found == null) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 GridCell cell = (GridCell)item; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 if (cell.contains(point)) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 found = cell; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 } // class CellFinder |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 public Point2d p1; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 public Point2d p2; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 public Point2d p3; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 public Point2d p4; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 protected Polygon polygon; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 public static final GeometryFactory GEOMETRY_FACTORY |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 = new GeometryFactory(); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 public GridCell() { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 public GridCell(Point2d p1, Point2d p2, Point2d p3, Point2d p4) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 this.p1 = p1; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 this.p2 = p2; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 this.p3 = p3; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 this.p4 = p4; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 createPolygon(); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 protected void createPolygon() { |
593
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
78 Coordinate [] coords = new Coordinate [] { p1, p2, p3, p4, p1 }; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
79 if (!CGAlgorithms.isCCW(coords)) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
80 for (int i = 0, j = coords.length-1; i < j; ++i, --j) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
81 Coordinate c = coords[i]; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
82 coords[i] = coords[j]; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
83 coords[j] = c; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
84 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
85 } |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 LinearRing shell = GEOMETRY_FACTORY |
593
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
87 .createLinearRing(coords); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
88 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
89 if (!shell.isValid()) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
90 log.warn("linear ring is not valid"); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
91 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
92 |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 polygon = GEOMETRY_FACTORY.createPolygon(shell, null); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 public Envelope getEnvelope() { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 return polygon.getEnvelopeInternal(); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 public boolean contains(Geometry coord) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 return polygon.contains(coord); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 public static List<GridCell> pointsToGridCells( |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 List<? extends Point2d> points |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 ) { |
517
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
107 return pointsToGridCells(points, null); |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
108 } |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
109 |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
110 public static List<GridCell> pointsToGridCells( |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
111 List<? extends Point2d> points, |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
112 Envelope relevantArea |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
113 ) { |
593
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
114 return pointsToGridCells(points, relevantArea, 0); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
115 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
116 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
117 private static final int NEIGHBORS [][] = { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
118 { -1, -1 }, // 0 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
119 { -1, 0 }, // 1 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
120 { -1, +1 }, // 2 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
121 { 0, +1 }, // 3 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
122 { +1, +1 }, // 4 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
123 { +1, 0 }, // 5 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
124 { +1, -1 }, // 6 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
125 { 0, -1 } // 7 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
126 }; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
127 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
128 public static int extrapolate( |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
129 HashMap<Integer, HashMap<Integer, Point2d>> rows, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
130 int minI, int maxI, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
131 int minJ, int maxJ, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
132 int rounds, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
133 Envelope relevantArea |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
134 ) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
135 Point2d [] neighbors = new Point2d[NEIGHBORS.length]; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
136 Point2d [] positions = new Point2d[NEIGHBORS.length]; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
137 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
138 int total = 0; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
139 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
140 ArrayList<ArrayList<IJKey>> prio = |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
141 new ArrayList<ArrayList<IJKey>>(NEIGHBORS.length); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
142 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
143 for (int i = 0; i < NEIGHBORS.length; ++i) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
144 prio.add(new ArrayList<IJKey>()); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
145 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
146 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
147 while (rounds-- > 0) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
148 for (int i = minI; i <= maxI; ++i) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
149 for (int j = minJ; j <= maxJ; ++j) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
150 Point2d p = get(rows, i, j); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
151 if (p != null) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
152 continue; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
153 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
154 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
155 int count = 0; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
156 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
157 for (int k = 0; k < neighbors.length; ++k) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
158 neighbors[k] = positions[k] = null; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
159 int dij [] = NEIGHBORS[k]; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
160 Point2d n1 = get(rows, i+ dij[0], j+ dij[1]); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
161 Point2d n2 = get(rows, i+2*dij[0], j+2*dij[1]); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
162 if (n1 != null && n2 != null) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
163 ++count; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
164 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
165 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
166 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
167 if (count > 0) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
168 prio.get(count-1).add(new IJKey(i, j)); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
169 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
170 } // for all columns |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
171 } // for all rows |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
172 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
173 int N = 0; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
174 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
175 for (int l = NEIGHBORS.length-1; l >= 0; --l) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
176 ArrayList<IJKey> list = prio.get(l); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
177 for (IJKey ij: list) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
178 int i = ij.i; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
179 int j = ij.j; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
180 for (int k = 0; k < neighbors.length; ++k) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
181 neighbors[k] = positions[k] = null; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
182 int dij [] = NEIGHBORS[k]; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
183 Point2d n1 = get(rows, i+ dij[0], j+ dij[1]); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
184 Point2d n2 = get(rows, i+2*dij[0], j+2*dij[1]); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
185 if (n1 != null && n2 != null) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
186 neighbors[k] = n1; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
187 positions[k] = n1.extrapolate(-1d, n2); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
188 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
189 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
190 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
191 Point2d avg = Point2d.average(positions); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
192 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
193 if (avg != null && avg.near(positions) |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
194 && (relevantArea == null || relevantArea.contains(avg.x, avg.y))) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
195 avg.i = i; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
196 avg.j = j; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
197 avg.inverseDistanceWeighting(neighbors); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
198 put(rows, avg, i, j); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
199 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
200 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
201 N += list.size(); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
202 list.clear(); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
203 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
204 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
205 if (N == 0) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
206 break; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
207 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
208 total += N; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
209 } // for all rounds |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
210 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
211 return total; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
212 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
213 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
214 public static List<GridCell> pointsToGridCells( |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
215 List<? extends Point2d> points, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
216 Envelope relevantArea, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
217 int extrapolationRounds |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
218 ) { |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 int minI = Integer.MAX_VALUE; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 int maxI = Integer.MIN_VALUE; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 int minJ = Integer.MAX_VALUE; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 int maxJ = Integer.MIN_VALUE; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 HashMap<Integer, HashMap<Integer, Point2d>> rows = |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 new HashMap<Integer, HashMap<Integer, Point2d>>(); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 |
517
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
227 int culled = 0; |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
228 |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 for (Point2d p: points) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 |
517
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
231 if (relevantArea != null && !relevantArea.contains(p.x, p.y)) { |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
232 ++culled; |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
233 continue; |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
234 } |
96a1e92e7ed2
If the number of data points to generate a "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
514
diff
changeset
|
235 |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 if (p.i < minI) minI = p.i; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 if (p.i > maxI) maxI = p.i; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 if (p.j < minJ) minJ = p.j; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 if (p.j > maxJ) maxJ = p.j; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 HashMap<Integer, Point2d> row = rows.get(p.i); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 if (row == null) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 rows.put(p.i, row = new HashMap<Integer, Point2d>()); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 row.put(p.j, p); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 ArrayList<GridCell> cells = new ArrayList<GridCell>(points.size()); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 |
593
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
252 int extrapolated = extrapolate( |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
253 rows, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
254 minI, maxI, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
255 minJ, maxJ, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
256 extrapolationRounds, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
257 relevantArea); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
258 |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 for (int i = minI + 1; i <= maxI; ++i) { |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 HashMap<Integer, Point2d> row1 = rows.get(i-1); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 HashMap<Integer, Point2d> row2 = rows.get(i); |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 |
593
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
263 if (row1 == null || row2 == null) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
264 continue; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
265 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
266 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
267 for (int j = minJ + 1; j < maxJ; ++j) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
268 Point2d p1 = row1.get(j-1); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
269 Point2d p2 = row1.get(j); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
270 Point2d p3 = row2.get(j); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
271 Point2d p4 = row2.get(j-1); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
272 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
273 if (p1 != null && p2 != null && p3 != null && p4 != null) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
274 cells.add(new GridCell(p1, p2, p3, p4)); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
275 } |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 } // for all rows |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 |
519
4e347624ee7c
Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
279 if (log.isDebugEnabled()) { |
4e347624ee7c
Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
280 log.debug("culled points: " + culled); |
593
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
281 log.debug("extrapolated points: " + extrapolated); |
519
4e347624ee7c
Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
282 log.debug("min/max i: " + minI + " / " + maxI); |
4e347624ee7c
Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
283 log.debug("min/max j: " + minJ + " / " + maxJ); |
4e347624ee7c
Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
284 log.debug("cells found: " + cells.size()); |
4e347624ee7c
Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
285 } |
4e347624ee7c
Last part to fix gnv/issue153. Now 'Profilschnitte', 'Horizontalschnitte' and 'horizontale Schnittprofile'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
517
diff
changeset
|
286 |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 return cells; |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 } |
593
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
289 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
290 private static Point2d get( |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
291 HashMap<Integer, HashMap<Integer, Point2d>> rows, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
292 int i, int j |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
293 ) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
294 HashMap<Integer, Point2d> row = rows.get(i); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
295 return row != null ? row.get(j) : null; |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
296 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
297 |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
298 private static void put( |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
299 HashMap<Integer, HashMap<Integer, Point2d>> rows, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
300 Point2d point, |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
301 int i, int j |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
302 ) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
303 Integer I = Integer.valueOf(i); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
304 HashMap<Integer, Point2d> row = rows.get(I); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
305 if (row == null) { |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
306 rows.put(I, row = new HashMap<Integer, Point2d>()); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
307 } |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
308 row.put(j, point); |
b248531fa20b
Added experimental support for extrapolation in "Horizontalschnitte"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
519
diff
changeset
|
309 } |
514
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
310 } |
d9d933e06875
Fixed gnv/issue153
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
311 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |