Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java @ 480:211cad2fb5ba
Rebased "Horizonalschnitte" to own state class to break from the not
well fitting TimeSeriesOutputState.
gnv-artifacts/trunk@552 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 17 Jan 2010 12:22:56 +0000 |
parents | 06887e2e3f7a |
children | 64e65daa65e9 |
rev | line source |
---|---|
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.utils; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import com.vividsolutions.jts.geom.Coordinate; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 import com.vividsolutions.jts.geom.Point; |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
5 import com.vividsolutions.jts.geom.Polygon; |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 import com.vividsolutions.jts.geom.LineString; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import com.vividsolutions.jts.io.ParseException; |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
8 |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 import com.vividsolutions.jts.io.WKTReader; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.gnv.geobackend.base.Result; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import de.intevation.gnv.geobackend.base.query.QueryExecutor; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import de.intevation.gnv.geobackend.base.query.exception.QueryException; |
440
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
15 |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 import de.intevation.gnv.math.LinearFunction; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 import java.util.ArrayList; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 import java.util.Collection; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 import java.util.List; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 import org.apache.commons.math.optimization.OptimizationException; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 import org.apache.commons.math.optimization.fitting.CurveFitter; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import org.apache.commons.math.optimization.general.GaussNewtonOptimizer; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 import org.apache.commons.math.FunctionEvaluationException; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 import org.apache.log4j.Logger; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 public abstract class WKTUtils { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 private static Logger log = Logger.getLogger(WKTUtils.class); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 public static final double NAUTICAL_MILE = 1852.216d; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 public static final double KILOMETER = 1000d; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
36 public static final String I_NAME = "MEDIAN.MESHPOINT.IPOSITION"; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
37 public static final String J_NAME = "MEDIAN.MESHPOINT.JPOSITION"; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
38 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
39 public static final String TRUE_EXPRESSION = "FEATUREID=FEATUREID"; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
40 |
423
2402173a1490
Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
420
diff
changeset
|
41 public static boolean different(Result a, Result b, int [] indices) { |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 for (int i = 0; i < indices.length; ++i) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 String oa = a.getString(indices[i]); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 String ob = b.getString(indices[i]); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 if (oa == null && ob == null) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 continue; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 if (oa == null || ob == null) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 return true; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 if (!oa.equals(ob)) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 return true; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 return false; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 public static Coordinate toCoordinate(String shape) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 try { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 return ((Point)(new WKTReader().read(shape))).getCoordinate(); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 catch (ParseException pe) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 log.error(pe); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 } |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
68 catch (ClassCastException cce) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
69 log.error("cannot read WKT point", cce); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
70 } |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 return null; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
74 public static Polygon toPolygon(String shape) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
75 try { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
76 return (Polygon)new WKTReader().read(shape); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
77 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
78 catch (ParseException pe) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
79 log.error(pe); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
80 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
81 catch (ClassCastException cce) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
82 log.error("cannot read WKT polygon", cce); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
83 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
84 return null; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
85 } |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 public static final double toKM(double distance) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 return (distance * NAUTICAL_MILE) / KILOMETER; |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 public static String toWKT(Coordinate coordinate) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 StringBuilder sb = new StringBuilder("POINT("); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 sb.append(coordinate.x) |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 .append(' ') |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 .append(coordinate.y) |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 .append(')'); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 return sb.toString(); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
101 public static final String indexBox( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
102 java.awt.Point a, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
103 java.awt.Point b, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
104 String iName, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
105 String jName |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
106 ) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
107 int minI = Math.min(a.x, b.x) - 1; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
108 int maxI = Math.max(a.x, b.x) + 1; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
109 int minJ = Math.min(a.y, b.y) - 1; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
110 int maxJ = Math.max(a.y, b.y) + 1; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
111 StringBuilder sb = new StringBuilder("(") |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
112 .append(iName).append(" >= ").append(minI) |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
113 .append(" AND ").append(iName).append(" <= ").append(maxI) |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
114 .append(" AND ").append(jName).append(" >= ").append(minJ) |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
115 .append(" AND ").append(jName).append(" <= ").append(maxJ) |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
116 .append(')'); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
117 return sb.toString(); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
118 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
119 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
120 public static final String diagonalBox(List<java.awt.Point> points) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
121 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
122 if (points.get(0) != null && points.get(2) != null) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
123 return indexBox( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
124 points.get(0), points.get(2), |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
125 I_NAME, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
126 J_NAME); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
127 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
128 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
129 if (points.get(1) != null && points.get(3) != null) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
130 return indexBox( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
131 points.get(1), points.get(3), |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
132 I_NAME, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
133 J_NAME); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
134 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
135 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
136 return null; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
137 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
138 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
139 public static String worldEnvelopeCoordinatesToIndex( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
140 Coordinate [] coords, |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
141 String meshid, |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
142 String ijkQueryID |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
143 ) |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
144 throws QueryException |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
145 { |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
146 List<java.awt.Point> points = |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
147 new ArrayList<java.awt.Point>(coords.length); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
148 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
149 ArrayList<Object []> missingPoints = |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
150 new ArrayList<Object []>(); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
151 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
152 createIJKPoints(coords, meshid, ijkQueryID, points, missingPoints); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
153 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
154 String additionWhere = null; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
155 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
156 if (missingPoints.size() == coords.length) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
157 log.debug("cannot create index buffer"); |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
158 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
159 else { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
160 additionWhere = diagonalBox(points); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
161 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
162 if (additionWhere == null) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
163 // 3 Points are missing or are on one side of the envelope |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
164 boolean remainsMissingPoints = calculateIJ4MissingPoints( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
165 coords, points, missingPoints); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
166 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
167 if (!remainsMissingPoints) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
168 additionWhere = diagonalBox(points); |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
169 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
170 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
171 } |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
172 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
173 return additionWhere != null |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
174 ? additionWhere |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
175 : TRUE_EXPRESSION; |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
176 } |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
177 |
423
2402173a1490
Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
420
diff
changeset
|
178 public static String worldCoordinatesToIndex( |
440
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
179 Coordinate [] coords, |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
180 Collection<Result> result, |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
181 String meshid, |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
182 String ijkQueryID |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
183 ) |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
184 throws QueryException |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 List<java.awt.Point> points = new ArrayList<java.awt.Point>(coords.length); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
188 ArrayList<Object []> missingPoints = new ArrayList<Object []>(); |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
189 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
190 createIJKPoints(coords, meshid, ijkQueryID, points, missingPoints); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
191 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
192 String additionWhere = TRUE_EXPRESSION; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
193 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
194 if (missingPoints.size() == coords.length) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
195 log.debug("cannot create index buffer"); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
196 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
197 else { // generate index filter |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
198 boolean remainsMissingPoints = calculateIJ4MissingPoints( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
199 coords, points, missingPoints); |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
200 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
201 if (!remainsMissingPoints) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
202 // TODO: Make Tablenames and Columns Configurable |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
203 IndexBuffer ib = new IndexBuffer( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
204 points, |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
205 I_NAME, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
206 J_NAME ); |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
207 additionWhere = ib.toWhereClause(); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
208 log.debug("Additional Where Clause = "+additionWhere); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
209 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
210 } // if generate index filter |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
212 return additionWhere; |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
213 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
214 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
215 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
216 /** |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
217 * @param coords |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
218 * @param points |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
219 * @param missingPoints |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
220 * @return |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
221 */ |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
222 private static boolean calculateIJ4MissingPoints( |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
223 Coordinate [] coords, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
224 List<java.awt.Point> points, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
225 ArrayList<Object[]> missingPoints |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
226 ) { |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
227 boolean remainsMissingPoints = !missingPoints.isEmpty(); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
228 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
229 if (remainsMissingPoints) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
230 // try to guess the missing (i, j) |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
231 CurveFitter iFitter = new CurveFitter(new GaussNewtonOptimizer(true)); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
232 CurveFitter jFitter = new CurveFitter(new GaussNewtonOptimizer(true)); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
233 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
234 for (int i = 0, N = points.size(); i < N; ++i) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
235 java.awt.Point p = (java.awt.Point)points.get(i); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
236 if (p != null) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
237 Coordinate coord = coords[i]; |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
238 iFitter.addObservedPoint(coord.x, p.x); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
239 jFitter.addObservedPoint(coord.y, p.y); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
240 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
241 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
242 try { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
243 // XXX: Assumption: (i, j) are created by componentwise linear function. |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
244 // This is surely not correct because (x, y) are in a ellipsoid projection. |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
245 // TODO: use ellipsoid functions and fit with Levenberg Marquardt. |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
246 double [] iParams = iFitter.fit( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
247 LinearFunction.INSTANCE, new double [] { 1d, 1d }); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
248 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
249 double [] jParams = jFitter.fit( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
250 LinearFunction.INSTANCE, new double [] { 1d, 1d }); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
251 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
252 for (int i = missingPoints.size()-1; i >= 0; --i) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
253 Object [] a = (Object [])missingPoints.get(i); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
254 Coordinate coord = (Coordinate)a[1]; |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
255 int pi = (int)Math.round(iParams[0]*coord.x + iParams[1]); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
256 int pj = (int)Math.round(jParams[0]*coord.y + jParams[1]); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
257 points.set( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
258 ((Integer)a[0]).intValue(), |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
259 new java.awt.Point(pi, pj)); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
260 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
261 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
262 remainsMissingPoints = false; // we filled the gaps |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
263 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
264 catch (FunctionEvaluationException fee) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
265 log.error(fee); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
266 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
267 catch (OptimizationException oe) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
268 log.error(oe); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
269 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
270 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
271 return remainsMissingPoints; |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
272 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
273 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
274 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
275 /** |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
276 * @param coords |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
277 * @param meshid |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
278 * @param ijkQueryID |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
279 * @param points |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
280 * @param missingPoints |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
281 * @throws QueryException |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
282 */ |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
283 private static void createIJKPoints( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
284 Coordinate[] coords, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
285 String meshid, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
286 String ijkQueryID, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
287 List<java.awt.Point> points, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
288 ArrayList<Object []> missingPoints |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
289 ) |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
290 throws QueryException |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
291 { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
292 boolean debug = log.isDebugEnabled(); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
293 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
294 QueryExecutor queryExecutor = QueryExecutorFactory |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
295 .getInstance() |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
296 .getQueryExecutor(); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
297 |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
298 for (int i = 0; i < coords.length; i++) { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
299 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
300 String wkt = toWKT(coords[i]); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
301 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
302 Collection<Result> result = queryExecutor.executeQuery( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
303 ijkQueryID, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
304 new String [] {meshid, wkt}); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
305 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
306 if (!result.isEmpty()) { |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
307 Result resultValue = result.iterator().next(); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
308 int iPos = resultValue.getInteger(1); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
309 int jPos = resultValue.getInteger(0); |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
310 if (debug) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
311 log.debug("Found Pos "+iPos+"/"+jPos +" for "+wkt); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
312 } |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
313 points.add(i, new java.awt.Point(iPos,jPos)); |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
314 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
315 else { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
316 if (debug) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
317 log.debug("No i/j Pos found for "+wkt); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
318 } |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
319 missingPoints.add(new Object [] { Integer.valueOf(i), coords[i] }); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
320 points.add(i, null); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
321 // Special Case no i,j found for Coordinate |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
322 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
323 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
324 } |
440
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
325 |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
326 public static Coordinate [] toCoordinates(String wkt) { |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
327 try { |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
328 LineString ls = (LineString)new WKTReader().read(wkt); |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
329 return ls.getCoordinates(); |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
330 } |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
331 catch (ParseException pe) { |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
332 log.error("cannot read WKT line string", pe); |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
333 } |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
334 catch (ClassCastException cce) { |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
335 log.error("cannot read WKT line string", cce); |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
336 } |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
337 return null; |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
338 } |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
339 } |