annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java @ 454:04cfb4e3da4f

Refactored statistics classes a bit. Added class for vertical cross sections. gnv-artifacts/trunk@503 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 04 Jan 2010 15:20:14 +0000
parents eb2ac62e853a
children 7ba4c7222265
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;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 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
6 import com.vividsolutions.jts.io.ParseException;
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.WKTReader;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 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
10 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
11 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
12 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
13
420
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.math.LinearFunction;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import java.util.ArrayList;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import java.util.Collection;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import java.util.List;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 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
21 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
22 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
23 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
24
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 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
26
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 public abstract class WKTUtils {
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 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
30
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 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
32 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
33
423
2402173a1490 Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 420
diff changeset
34 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
35 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
36 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
37 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
38
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 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
40 continue;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 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
44 return true;
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 if (!oa.equals(ob)) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 if (log.isDebugEnabled()) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 log.debug("+++++++++++++++ differs ++++++++++++++");
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 log.debug(" " + oa + " != " + ob);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 return true;
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 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 return false;
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 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
60 try {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 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
62 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 catch (ParseException pe) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 log.error(pe);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 return null;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 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
71 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
72 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 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
76 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
77 sb.append(coordinate.x)
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 .append(' ')
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 .append(coordinate.y)
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 .append(')');
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 return sb.toString();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84
423
2402173a1490 Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 420
diff changeset
85 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
86 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
87 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
88 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
89 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
90 )
eb2ac62e853a Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 423
diff changeset
91 throws QueryException
420
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 // 1. IJK Anfragen für Stuetzpunkte im Netz ausführen.
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 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
96
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 QueryExecutor queryExecutor = QueryExecutorFactory
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 .getInstance()
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 .getQueryExecutor();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 ArrayList missingPoints = new ArrayList();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 String additionWhere = "FEATUREID=FEATUREID";
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 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
106
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 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
108
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 result = queryExecutor.executeQuery(ijkQueryID,
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 new String[]{meshid,wkt});
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 if (!result.isEmpty()){
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 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
113 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
114 int jPos = resultValue.getInteger(0);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 log.debug("Found Pos "+iPos+"/"+jPos +" for "+wkt);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 points.add(i, new java.awt.Point(iPos,jPos));
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 }else{
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 log.debug("No i/j Pos found for "+wkt);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 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
120 points.add(i, null);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 // 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
122 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 if (missingPoints.size() == coords.length) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 log.debug("cannot create index buffer");
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128 else { // generate index filter
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 boolean remainsMissingPoints = !missingPoints.isEmpty();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131 if (remainsMissingPoints) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 // try to guess the missing (i, j)
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 CurveFitter iFitter = new CurveFitter(new GaussNewtonOptimizer(true));
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 CurveFitter jFitter = new CurveFitter(new GaussNewtonOptimizer(true));
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 for (int i = 0, N = points.size(); i < N; ++i) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 java.awt.Point p = (java.awt.Point)points.get(i);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 if (p != null) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 Coordinate coord = coords[i];
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 iFitter.addObservedPoint(coord.x, p.x);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 jFitter.addObservedPoint(coord.y, p.y);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 try {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 // XXX: Assumption: (i, j) are created by componentwise linear function.
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 // This is surely not correct because (x, y) are in a ellipsoid projection.
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 // TODO: use ellipsoid functions and fit with Levenberg Marquardt.
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 double [] iParams = iFitter.fit(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 LinearFunction.INSTANCE, new double [] { 1d, 1d });
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 double [] jParams = jFitter.fit(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 LinearFunction.INSTANCE, new double [] { 1d, 1d });
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 for (int i = missingPoints.size()-1; i >= 0; --i) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 Object [] a = (Object [])missingPoints.get(i);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 Coordinate coord = (Coordinate)a[1];
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 int pi = (int)Math.round(iParams[0]*coord.x + iParams[1]);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 int pj = (int)Math.round(jParams[0]*coord.y + jParams[1]);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 points.set(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 ((Integer)a[0]).intValue(),
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 new java.awt.Point(pi, pj));
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 remainsMissingPoints = false; // we filled the gaps
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166 catch (FunctionEvaluationException fee) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 log.error(fee);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 catch (OptimizationException oe) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 log.error(oe);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 if (!remainsMissingPoints) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 // TODO: Make Tablenames and Columns Configurable
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 IndexBuffer ib = new IndexBuffer(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 points,
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 "MEDIAN.MESHPOINT.IPOSITION",
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 "MEDIAN.MESHPOINT.JPOSITION" );
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180 additionWhere = ib.toWhereClause();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 log.debug("Additional Where Clause = "+additionWhere);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 // 2. Aus diesen Stuetzpunkten den Resultset generieren.
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 } // if generate index filter
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185
423
2402173a1490 Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 420
diff changeset
186 return additionWhere;
420
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 }
440
eb2ac62e853a Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 423
diff changeset
188
eb2ac62e853a Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 423
diff changeset
189 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
190 try {
eb2ac62e853a Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 423
diff changeset
191 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
192 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
193 }
eb2ac62e853a Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 423
diff changeset
194 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
195 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
196 }
eb2ac62e853a Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 423
diff changeset
197 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
198 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
199 }
eb2ac62e853a Cleaned up messy code a bit in "Horizontales Schnittprofil" and "Profilschnitt".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 423
diff changeset
200 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
201 }
420
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 }

http://dive4elements.wald.intevation.org