Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java @ 473:a6a33ef35809
Added support to step back to previous states. Add state names to xform nodes in describe document and append old targets to list of reachable targets.
gnv-artifacts/trunk@539 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 13 Jan 2010 23:10:56 +0000 |
parents | 06887e2e3f7a |
children | 211cad2fb5ba |
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 Collection<Result> result, |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
142 String meshid, |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
143 String ijkQueryID |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
144 ) |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
145 throws QueryException |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
146 { |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
147 List<java.awt.Point> points = |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
148 new ArrayList<java.awt.Point>(coords.length); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
149 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
150 ArrayList<Object []> missingPoints = |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
151 new ArrayList<Object []>(); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
152 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
153 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
|
154 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
155 String additionWhere = null; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
156 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
157 if (missingPoints.size() == coords.length) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
158 log.debug("cannot create index buffer"); |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
159 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
160 else { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
161 additionWhere = diagonalBox(points); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
162 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
163 if (additionWhere == null) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
164 // 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
|
165 boolean remainsMissingPoints = calculateIJ4MissingPoints( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
166 coords, points, missingPoints); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
167 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
168 if (!remainsMissingPoints) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
169 additionWhere = diagonalBox(points); |
468
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 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
172 } |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
173 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
174 return additionWhere != null |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
175 ? additionWhere |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
176 : TRUE_EXPRESSION; |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
177 } |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
178 |
423
2402173a1490
Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
420
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 ) |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
185 throws QueryException |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 { |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 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
|
188 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
189 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
|
190 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
191 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
|
192 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
193 String additionWhere = TRUE_EXPRESSION; |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
194 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
195 if (missingPoints.size() == coords.length) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
196 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
|
197 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
198 else { // generate index filter |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
199 boolean remainsMissingPoints = calculateIJ4MissingPoints( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
200 coords, points, missingPoints); |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
201 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
202 if (!remainsMissingPoints) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
203 // 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
|
204 IndexBuffer ib = new IndexBuffer( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
205 points, |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
206 I_NAME, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
207 J_NAME ); |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
208 additionWhere = ib.toWhereClause(); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
209 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
|
210 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
211 } // 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
|
212 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
213 return additionWhere; |
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 /** |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
218 * @param coords |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
219 * @param points |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
220 * @param missingPoints |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
221 * @return |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
222 */ |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
223 private static boolean calculateIJ4MissingPoints( |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
224 Coordinate [] coords, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
225 List<java.awt.Point> points, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
226 ArrayList<Object[]> missingPoints |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
227 ) { |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
228 boolean remainsMissingPoints = !missingPoints.isEmpty(); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
229 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
230 if (remainsMissingPoints) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
231 // 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
|
232 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
|
233 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
|
234 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
235 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
|
236 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
|
237 if (p != null) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
238 Coordinate coord = coords[i]; |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
239 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
|
240 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
|
241 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
242 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
243 try { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
244 // 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
|
245 // 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
|
246 // 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
|
247 double [] iParams = iFitter.fit( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
248 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
|
249 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
250 double [] jParams = jFitter.fit( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
251 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
|
252 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
253 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
|
254 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
|
255 Coordinate coord = (Coordinate)a[1]; |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
256 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
|
257 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
|
258 points.set( |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
259 ((Integer)a[0]).intValue(), |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
260 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
|
261 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
262 |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
263 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
|
264 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
265 catch (FunctionEvaluationException fee) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
266 log.error(fee); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
267 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
268 catch (OptimizationException oe) { |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
269 log.error(oe); |
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 } |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
272 return remainsMissingPoints; |
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 /** |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
277 * @param coords |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
278 * @param meshid |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
279 * @param ijkQueryID |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
280 * @param points |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
281 * @param missingPoints |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
282 * @throws QueryException |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
283 */ |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
284 private static void createIJKPoints( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
285 Coordinate[] coords, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
286 String meshid, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
287 String ijkQueryID, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
288 List<java.awt.Point> points, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
289 ArrayList<Object []> missingPoints |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
290 ) |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
291 throws QueryException |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
292 { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
293 boolean debug = log.isDebugEnabled(); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
294 |
468
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
295 QueryExecutor queryExecutor = QueryExecutorFactory |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
296 .getInstance() |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
297 .getQueryExecutor(); |
7ba4c7222265
Added ij-Index determination for horizontal-cross-sections.
Tim Englich <tim.englich@intevation.de>
parents:
440
diff
changeset
|
298 |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
299 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
|
300 |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
301 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
|
302 |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
303 Collection<Result> result = queryExecutor.executeQuery( |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
304 ijkQueryID, |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
305 new String [] {meshid, wkt}); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
306 |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
307 if (!result.isEmpty()) { |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
308 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
|
309 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
|
310 int jPos = resultValue.getInteger(0); |
471
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
311 if (debug) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
312 log.debug("Found Pos "+iPos+"/"+jPos +" for "+wkt); |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
313 } |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
314 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
|
315 } |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
316 else { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
317 if (debug) { |
06887e2e3f7a
Some minor code cleanup
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
468
diff
changeset
|
318 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
|
319 } |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
320 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
|
321 points.add(i, null); |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
322 // 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
|
323 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
324 } |
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
325 } |
440
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
326 |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
327 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
|
328 try { |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
329 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
|
330 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
|
331 } |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
332 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
|
333 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
|
334 } |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
335 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
|
336 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
|
337 } |
eb2ac62e853a
Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
423
diff
changeset
|
338 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
|
339 } |
420
c6a287398379
Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
340 } |