annotate gnv-artifacts/src/main/java/de/intevation/gnv/utils/WKTUtils.java @ 429:bed9735adf84

Finished preprocessing data for interpolation in verticalcrosssection charts.ß gnv-artifacts/trunk@477 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 22 Dec 2009 17:19:10 +0000
parents 2402173a1490
children eb2ac62e853a
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;
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.math.LinearFunction;
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.state.InputData;
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 import java.util.Map;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
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.OptimizationException;
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.fitting.CurveFitter;
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.general.GaussNewtonOptimizer;
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.FunctionEvaluationException;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 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
27
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 public abstract class WKTUtils {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 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
31
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 NAUTICAL_MILE = 1852.216d;
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 KILOMETER = 1000d;
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
423
2402173a1490 Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 420
diff changeset
35 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
36 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
37 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
38 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
39
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 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
41 continue;
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 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
45 return true;
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 if (!oa.equals(ob)) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 if (log.isDebugEnabled()) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 log.debug("+++++++++++++++ differs ++++++++++++++");
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 log.debug(" " + oa + " != " + ob);
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 return true;
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 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 return false;
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 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
61 try {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 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
63 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 catch (ParseException pe) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 log.error(pe);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 return null;
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 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
72 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
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 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
77 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
78 sb.append(coordinate.x)
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 .append(' ')
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 .append(coordinate.y)
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 .append(')');
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 return sb.toString();
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85
423
2402173a1490 Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 420
diff changeset
86 public static String worldCoordinatesToIndex(
420
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87 Collection<Result> result,
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 Map<String, InputData> inputData,
423
2402173a1490 Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 420
diff changeset
89 String ijkQueryID
420
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 ) throws ParseException, QueryException
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 // 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
93 LineString ls = (LineString)new WKTReader().read(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 inputData.get("mesh_linestring").getValue());
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 Coordinate[] coords = ls.getCoordinates();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 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
99
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 String meshid = inputData.get("meshid").getValue();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 QueryExecutor queryExecutor = QueryExecutorFactory
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 .getInstance()
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 .getQueryExecutor();
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 ArrayList missingPoints = new ArrayList();
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 additionWhere = "FEATUREID=FEATUREID";
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 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
110
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 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
112
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 result = queryExecutor.executeQuery(ijkQueryID,
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 new String[]{meshid,wkt});
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 if (!result.isEmpty()){
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 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
117 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
118 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
119 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
120 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
121 }else{
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 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
123 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
124 points.add(i, null);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125 // 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
126 }
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
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 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
130 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
131 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 else { // generate index filter
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133 boolean remainsMissingPoints = !missingPoints.isEmpty();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 if (remainsMissingPoints) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 // 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
137 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
138 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
139
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 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
141 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
142 if (p != null) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 Coordinate coord = coords[i];
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 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
145 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
146 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 try {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 // 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
150 // 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
151 // 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
152 double [] iParams = iFitter.fit(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 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
154
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 double [] jParams = jFitter.fit(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156 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
157
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 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
159 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
160 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
161 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
162 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
163 points.set(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 ((Integer)a[0]).intValue(),
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 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
166 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 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
169 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170 catch (FunctionEvaluationException fee) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 log.error(fee);
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 catch (OptimizationException oe) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 log.error(oe);
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 if (!remainsMissingPoints) {
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 // 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
180 IndexBuffer ib = new IndexBuffer(
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 points,
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 "MEDIAN.MESHPOINT.IPOSITION",
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183 "MEDIAN.MESHPOINT.JPOSITION" );
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 additionWhere = ib.toWhereClause();
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 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
186 // 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
187 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 } // if generate index filter
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189
423
2402173a1490 Moved some methods back to old place.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 420
diff changeset
190 return additionWhere;
420
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 }
c6a287398379 Outsourcing of some methods for preparing results for chart creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192 }

http://dive4elements.wald.intevation.org