annotate backend/src/main/java/org/dive4elements/river/model/River.java @ 8971:50416a0df385

Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
author mschaefer
date Tue, 03 Apr 2018 10:18:30 +0200
parents c4ce25093953
children 7c8d62867876
rev   line source
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5880
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5992
4c3ccf2b0304 Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5880
diff changeset
6 * documentation coming with Dive4Elements River for details.
5844
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4dd33b86dc61 Added header to river backend.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5829
18619c1e7c2a Repaired internal references.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5828
diff changeset
9 package org.dive4elements.river.model;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import java.io.Serializable;
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
12 import java.math.BigDecimal;
768
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 767
diff changeset
13 import java.math.MathContext;
4809
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
14 import java.util.Comparator;
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
15 import java.util.List;
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
16 import java.util.Map;
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
17 import java.util.TreeMap;
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
18
4809
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
19 import javax.persistence.Column;
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
20 import javax.persistence.Entity;
4809
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
21 import javax.persistence.GeneratedValue;
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
22 import javax.persistence.GenerationType;
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
23 import javax.persistence.Id;
4809
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
24 import javax.persistence.JoinColumn;
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
25 import javax.persistence.OneToMany;
2347
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
26 import javax.persistence.OneToOne;
4809
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
27 import javax.persistence.SequenceGenerator;
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
28 import javax.persistence.Table;
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
29
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
30 import org.apache.log4j.Logger;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
31 import org.dive4elements.river.backend.SessionHolder;
4809
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
32 import org.hibernate.Query;
472
1e196c75563b Added a new method to determine the selected gauge of a river based on a start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 465
diff changeset
33 import org.hibernate.Session;
8810
dbdb7c9bd51b Upgrade to new PostgreSQL JDBC-driver.
Tom Gottfried <tom@intevation.de>
parents: 8764
diff changeset
34 import org.hibernate.annotations.Type;
472
1e196c75563b Added a new method to determine the selected gauge of a river based on a start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 465
diff changeset
35
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
36 @Entity
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
37 @Table(name = "rivers")
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public class River
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 implements Serializable
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 {
8724
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
41 private static Logger log = Logger.getLogger(River.class);
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
42
768
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 767
diff changeset
43 public static final MathContext PRECISION = new MathContext(6);
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 767
diff changeset
44
2383
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
45 public static final double EPSILON = 1e-5;
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
46
8724
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
47 // Tolerance for determining whether we are at the station of a gauge
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
48 public static final double GAUGE_EPSILON = 0.1;
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
49
4809
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
50 public static final Comparator<Double> KM_CMP = new Comparator<Double>() {
2383
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
51 @Override
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
52 public int compare(final Double a, final Double b) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
53 final double diff = a - b;
2383
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
54 if (diff < -EPSILON) return -1;
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
55 if (diff > EPSILON) return +1;
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
56 return 0;
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
57 }
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
58 };
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
59
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
60 private Integer id;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
3946
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
62 private Long officialNumber;
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
63
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
64 private String name;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65
505
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
66 private boolean kmUp;
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
67
7750
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
68 private String modelUuid;
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
69
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
70 private List<Gauge> gauges;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
71
2347
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
72 private Unit wstUnit;
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
73
8683
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
74 private SeddbName seddbName;
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
75
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
76 @Id
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
77 @SequenceGenerator(
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
78 name = "SEQUENCE_RIVERS_ID_SEQ",
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
79 sequenceName = "RIVERS_ID_SEQ",
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
80 allocationSize = 1)
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
81 @GeneratedValue(
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
82 strategy = GenerationType.SEQUENCE,
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
83 generator = "SEQUENCE_RIVERS_ID_SEQ")
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
84 @Column(name = "id")
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
85 public Integer getId() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
86 return this.id;
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
87 }
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
88
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
89 public void setId(final Integer id) {
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 this.id = id;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92
3946
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
93 @Column(name = "official_number")
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
94 public Long getOfficialNumber() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
95 return this.officialNumber;
3946
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
96 }
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
97
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
98 public void setOfficialNumber(final Long officialNumber) {
3946
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
99 this.officialNumber = officialNumber;
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
100 }
948c7289fc42 Backend: Added 'official_number' column to rivers table to model the 'Bundeswasserstrassen Identnummer'.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3945
diff changeset
101
168
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
102 @Column(name = "name")
86a1bd9cc50e More Hibernate/JPA stuff
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 167
diff changeset
103 public String getName() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
104 return this.name;
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
107 public void setName(final String name) {
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108 this.name = name;
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110
8810
dbdb7c9bd51b Upgrade to new PostgreSQL JDBC-driver.
Tom Gottfried <tom@intevation.de>
parents: 8764
diff changeset
111 @Type(type="numeric_boolean")
505
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
112 @Column(name = "km_up")
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
113 public boolean getKmUp() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
114 return this.kmUp;
505
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
115 }
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
116
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
117 public void setKmUp(final boolean kmUp) {
505
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
118 this.kmUp = kmUp;
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
119 }
ce9c6f05f464 Schema: Added a column which tells if a river counts its km up or downwards.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 488
diff changeset
120
7750
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
121 @Column(name = "model_uuid")
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
122 public String getModelUuid() {
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
123 return this.modelUuid;
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
124 }
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
125
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
126 public void setModelUuid(final String modelUuid) {
7750
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
127 this.modelUuid = modelUuid;
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
128 }
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
129
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130 public River() {
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 }
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
132
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
133 public River(final String name, final Unit wstUnit, final String modelUuid) {
7750
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
134 this.name = name;
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
135 this.modelUuid = modelUuid;
6ff574778491 Added model_uuid column to river model.
Raimund Renkert <rrenkert@intevation.de>
parents: 6229
diff changeset
136 this.wstUnit = wstUnit;
169
7929f4144d2f Bound Apache Commons DBCP with Hibernate.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 168
diff changeset
137 }
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
138
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
139 @OneToMany
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
140 @JoinColumn(name="river_id")
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
141 public List<Gauge> getGauges() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
142 return this.gauges;
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
143 }
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
144
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
145 public void setGauges(final List<Gauge> gauges) {
174
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
146 this.gauges = gauges;
249390dd24e7 Added foreign key constraint annotations to model classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 171
diff changeset
147 }
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
148
2347
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
149 @OneToOne
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
150 @JoinColumn(name = "wst_unit_id" )
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
151 public Unit getWstUnit() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
152 return this.wstUnit;
2347
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
153 }
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
154
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
155 public void setWstUnit(final Unit wstUnit) {
2347
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
156 this.wstUnit = wstUnit;
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
157 }
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
158
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
159
8683
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
160 /**
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
161 * Get alternative seddb name.
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
162 *
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
163 * This is the name should be used in seddb queries
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
164 * and might differ from "our" backend db name.
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
165 *
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
166 * @return The name River in the seddb.
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
167 */
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
168 public String nameForSeddb() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
169 final SeddbName alt = getSeddbName();
8683
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
170 if (alt == null) {
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
171 return getName();
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
172 }
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
173 return alt.getName();
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
174 }
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
175
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
176
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
177 @OneToOne
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
178 @JoinColumn(name = "seddb_name_id" )
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
179 public SeddbName getSeddbName() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
180 return this.seddbName;
8683
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
181 }
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
182
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
183 public void setSeddbName(final SeddbName name) {
8683
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
184 this.seddbName = name;
cfafe5764509 (issue 1796) Scheme change! Add model for seddb_name lookup table.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8424
diff changeset
185 }
2347
0acf28a3d28a Removed the Unit from Wsts - added a WstUnit column to rivers.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2345
diff changeset
186
4809
8062b571884d Bugs in generated RiverAxis Mapfile fixed. Now the river axes are drawn by the WMS.
Christian Lins <christian.lins@intevation.de>
parents: 4262
diff changeset
187 @Override
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
188 public String toString() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
189 return this.name != null ? this.name : "";
188
003ac16812dd Store annotations in backend.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 174
diff changeset
190 }
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
191
472
1e196c75563b Added a new method to determine the selected gauge of a river based on a start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 465
diff changeset
192
1e196c75563b Added a new method to determine the selected gauge of a river based on a start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 465
diff changeset
193 /**
488
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
194 * This method returns the gauges that intersect with <i>a</i> and
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
195 * <i>b</i>,
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
196 *
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
197 * @param a A start point.
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
198 * @param b An end point.
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
199 *
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
200 * @return the intersecting gauges.
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
201 */
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
202 public List<Gauge> determineGauges(double a, double b) {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
203 final Session session = SessionHolder.HOLDER.get();
756
ca13926b8871 River: Make search for gauges independent of from/to order.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 505
diff changeset
204
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
205 if (a > b) { final double t = a; a = b; b = t; }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
206
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
207 final Query query = session.createQuery(
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
208 "from Gauge where river=:river " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
209 "and not " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
210 "((:b < least(range.a, range.b)) or" +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
211 " (:a > greatest(range.a, range.b)))" +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
212 "order by a");
488
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
213 query.setParameter("river", this);
769
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
214 query.setParameter("a", new BigDecimal(a, PRECISION));
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
215 query.setParameter("b", new BigDecimal(b, PRECISION));
488
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
216
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
217 return query.list();
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
218 }
b316d2106598 River got a new method that returns all gauges intersected by a given start and end point.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 472
diff changeset
219
769
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
220 public Gauge maxOverlap(double a, double b) {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
221 final List<Gauge> gauges = determineGauges(a, b);
769
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
222 if (gauges == null) {
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
223 return null;
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
224 }
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
225
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
226 if (a > b) { final double t = a; a = b; b = t; }
769
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
227
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
228 double max = -Double.MAX_VALUE;
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
229
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
230 Gauge result = null;
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
231
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
232 for (final Gauge gauge: gauges) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
233 final Range r = gauge.getRange();
769
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
234 double c = r.getA().doubleValue();
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
235 double d = r.getB().doubleValue();
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
236
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
237 if (c > d) { final double t = c; c = d; d = t; }
5878
a7b56219b362 Partial fix for flys/issue1247: When trying to find gauges take care of the fact that start and end position are in abitrary order.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5844
diff changeset
238
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
239 final double start = c >= a ? c : a;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
240 final double stop = d <= b ? d : b;
769
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
241
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
242 final double length = stop - start;
769
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
243
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
244 if (length > max) {
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
245 max = length;
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
246 result = gauge;
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
247 }
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
248 }
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
249
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
250 return result;
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
251 }
321b9e480f72 Added a method to river to find the gauge with the max overlap with a given interval.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 768
diff changeset
252
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
253 public Gauge determineGaugeByName(final String name) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
254 final Session session = SessionHolder.HOLDER.get();
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
255 final Query query = session.createQuery(
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
256 "from Gauge where river=:river and name=:name");
767
5572d051347e River: Added method to find gauge by its name.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 764
diff changeset
257 query.setParameter("river", this);
5572d051347e River: Added method to find gauge by its name.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 764
diff changeset
258 query.setParameter("name", name);
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
259 final List<Gauge> gauges = query.list();
767
5572d051347e River: Added method to find gauge by its name.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 764
diff changeset
260 return gauges.isEmpty() ? null : gauges.get(0);
5572d051347e River: Added method to find gauge by its name.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 764
diff changeset
261 }
5572d051347e River: Added method to find gauge by its name.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 764
diff changeset
262
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
263 public Gauge determineGaugeByPosition(final double p) {
8727
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
264 // Per default, we prefer the gauge downstream
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
265 return determineGaugeByPosition(p, getKmUp());
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
266 }
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
267
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
268 /**
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
269 * @param p Station on this river for which the gauge is searched
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
270 * @param kmLower At boundary of two gauge ranges, should gauge at lower
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
271 * km be returned?
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
272 */
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
273 public Gauge determineGaugeByPosition(final double p, final boolean kmLower) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
274 final Session session = SessionHolder.HOLDER.get();
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
275 final Query query = session.createQuery(
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
276 "from Gauge g where river=:river " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
277 "and :p between " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
278 "least(g.range.a, g.range.b) and " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
279 "greatest(g.range.a, g.range.b)");
764
e09f00ecb915 river model: Added method to find gauge by a position lying in its range.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 757
diff changeset
280 query.setParameter("river", this);
768
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 767
diff changeset
281 query.setParameter("p", new BigDecimal(p, PRECISION));
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
282 final List<Gauge> gauges = query.list();
8727
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
283 if (gauges.isEmpty()) {
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
284 return null;
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
285 }
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
286 if (gauges.size() == 1) {
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
287 return gauges.get(0);
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
288 }
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
289 if (gauges.size() > 2) {
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
290 // TODO: database schema should prevent this.
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
291 log.warn("More than two gauge ranges overlap km " + p +
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
292 ". Returning arbitrary result.");
8727
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
293 }
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
294 final Gauge g0 = gauges.get(0);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
295 final Gauge g1 = gauges.get(1);
8727
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
296 if (kmLower) {
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
297 return
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
298 g0.getStation().doubleValue() < g1.getStation().doubleValue()
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
299 ? g0
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
300 : g1;
8727
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
301 }
20b543616e6d (issue1801) Return defined gauge at limit between two gauge ranges.
Tom Gottfried <tom@intevation.de>
parents: 8724
diff changeset
302 return g0.getStation().doubleValue() > g1.getStation().doubleValue()
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
303 ? g0
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
304 : g1;
764
e09f00ecb915 river model: Added method to find gauge by a position lying in its range.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 757
diff changeset
305 }
e09f00ecb915 river model: Added method to find gauge by a position lying in its range.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 757
diff changeset
306
757
c19d4c643526 River: add method to find gauge by its station position.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
307
8724
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
308 /**
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
309 * @param s station at which the gauge is requested.
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
310 * @return Gauge within tolerance at given station. null if there is none.
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
311 */
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
312 public Gauge determineGaugeAtStation(final double s) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
313 final Session session = SessionHolder.HOLDER.get();
757
c19d4c643526 River: add method to find gauge by its station position.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
314
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
315 final Query query = session.createQuery(
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
316 "from Gauge where river.id=:river " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
317 "and station between :a and :b");
757
c19d4c643526 River: add method to find gauge by its station position.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
318 query.setParameter("river", getId());
8724
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
319 query.setParameter("a", new BigDecimal(s - GAUGE_EPSILON));
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
320 query.setParameter("b", new BigDecimal(s + GAUGE_EPSILON));
757
c19d4c643526 River: add method to find gauge by its station position.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
321
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
322 final List<Gauge> gauges = query.list();
8724
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
323 if (gauges.size() > 1) {
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
324 log.warn("More than one gauge found at km " + s +
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
325 " within +-" + GAUGE_EPSILON +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
326 ". Returning arbitrary result.");
8724
47199406994a (issue1801) Determine gauge at a station always with same tolerance.
Tom Gottfried <tom@intevation.de>
parents: 8683
diff changeset
327 }
757
c19d4c643526 River: add method to find gauge by its station position.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
328 return gauges.isEmpty() ? null : gauges.get(0);
c19d4c643526 River: add method to find gauge by its station position.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
329 }
c19d4c643526 River: add method to find gauge by its station position.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 756
diff changeset
330
3794
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
331 public double[] determineMinMaxQ() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
332 final Session session = SessionHolder.HOLDER.get();
3794
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
333
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
334 final Query query = session.createQuery(
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
335 "select min(wqr.q) as min, max(wqr.q) as max " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
336 "from Wst as w " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
337 "join w.columns as wc " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
338 "join wc.columnQRanges as wcqr " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
339 "join wcqr.wstQRange as wqr " +
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
340 "where w.kind = 0 and river_id = :river");
3794
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
341
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
342 query.setParameter("river", getId());
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
343
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
344 final double minmax[] = new double[] { Double.MAX_VALUE, -Double.MAX_VALUE };
3794
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
345
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
346 final List<Object> results = query.list();
3794
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
347
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
348 if (!results.isEmpty()) {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
349 final Object[] arr = (Object[]) results.get(0);
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
350 final BigDecimal minq = (BigDecimal)arr[0];
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
351 final BigDecimal maxq = (BigDecimal)arr[1];
3794
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
352 minmax[0] = minq.doubleValue();
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
353 minmax[1] = maxq.doubleValue();
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
354 }
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
355
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
356 return minmax;
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
357 }
42db09d101f3 Add new method determineMinMaxQ to the River class to fetch the mimimum and maximum q values
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 2384
diff changeset
358
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
359 /**
8755
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
360 * Determine reference gauge dependent on direction of calculation
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
361 * for a range calculation, otherwise dependent on flow direction.
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
362 */
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
363 public Gauge determineRefGauge(final double[] range, final boolean isRange) {
8755
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
364 if (isRange) {
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
365 return determineGaugeByPosition(
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
366 range[0],
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
367 range[0] > range[1]);
8755
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
368 }
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
369 else {
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
370 return determineGaugeByPosition(range[0]);
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
371 }
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
372 }
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
373
30b1ddadf275 (issue1801) Unify reference gauge finding code
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8727
diff changeset
374 /**
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
375 * Returns the min and max distance of this river. The first position in the
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
376 * resulting array contains the min distance, the second position the max
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
377 * distance.
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
378 *
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
379 * @return the min and max distance of this river.
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
380 */
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
381 public double[] determineMinMaxDistance() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
382 final Session session = SessionHolder.HOLDER.get();
2373
056b3a5aa181 Removed "NOT NULL" constraint from gauges.range_id because there are gauges which dont have a Gueltigkeitsbereich.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2347
diff changeset
383
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
384 final Query query = session.createQuery(
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
385 "select min(range.a), max(range.b) from Gauge "
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
386 + "where river=:river "
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
387 + "and range is not null");
8764
d5917ff74d8a (issue1838) Get min and max directly from database.
Tom Gottfried <tom@intevation.de>
parents: 8756
diff changeset
388 query.setParameter("river", this);
d5917ff74d8a (issue1838) Get min and max directly from database.
Tom Gottfried <tom@intevation.de>
parents: 8756
diff changeset
389
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
390 final List<Object[]> result = query.list();
8764
d5917ff74d8a (issue1838) Get min and max directly from database.
Tom Gottfried <tom@intevation.de>
parents: 8756
diff changeset
391
d5917ff74d8a (issue1838) Get min and max directly from database.
Tom Gottfried <tom@intevation.de>
parents: 8756
diff changeset
392 if (!result.isEmpty()) {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
393 final Object[] minMax = result.get(0);
8815
c4ce25093953 Avoid some annoying NPEs when developing with sparsely filled database.
Tom Gottfried <tom@intevation.de>
parents: 8810
diff changeset
394 if (minMax[0] != null && minMax[1] != null) {
c4ce25093953 Avoid some annoying NPEs when developing with sparsely filled database.
Tom Gottfried <tom@intevation.de>
parents: 8810
diff changeset
395 return new double[] { ((BigDecimal)minMax[0]).doubleValue(),
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
396 ((BigDecimal)minMax[1]).doubleValue() };
8815
c4ce25093953 Avoid some annoying NPEs when developing with sparsely filled database.
Tom Gottfried <tom@intevation.de>
parents: 8810
diff changeset
397 }
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
398 }
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
399
8764
d5917ff74d8a (issue1838) Get min and max directly from database.
Tom Gottfried <tom@intevation.de>
parents: 8756
diff changeset
400 return null;
465
c2c3ad4fda58 Added a method to River that returns the min and max distance of the river.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 188
diff changeset
401 }
2383
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
402
2384
385170ff7b34 River: (fix) Renamed function which is not a getter.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2383
diff changeset
403 public Map<Double, Double> queryGaugeDatumsKMs() {
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
404 final List<Gauge> gauges = getGauges();
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
405 final Map<Double, Double> result = new TreeMap<>(KM_CMP);
2383
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
406
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
407 for (final Gauge gauge: gauges) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
408 final BigDecimal km = gauge.getStation();
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
409 final BigDecimal datum = gauge.getDatum();
2383
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
410 if (km != null && datum != null) {
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
411 result.put(km.doubleValue(), datum.doubleValue());
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
412 }
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
413 }
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
414
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
415 return result;
6605dcd6745f Added a method to build a map from gauge stations to the datums of the gauges.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2373
diff changeset
416 }
3944
5fea100c5334 Add a new method to River and Gauge classes to return a http url for additional
Bjoern Ricks <bjoern.ricks@intevation.de>
parents: 3795
diff changeset
417
8971
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
418 /**
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
419 * Searches the gauges list of the river for a gauge number or a gauge name
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
420 */
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
421 public Gauge findGauge(final long number, final String name) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
422 for (final Gauge gauge : getGauges()) {
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
423 if (gauge.getOfficialNumber().longValue() == number)
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
424 return gauge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
425 if (gauge.getName().equalsIgnoreCase(name))
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
426 return gauge;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
427 }
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
428 return null;
50416a0df385 Importer for the Schifffahrt (S-INFO) and Oekologie (U-INFO) files
mschaefer
parents: 8815
diff changeset
429 }
167
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
430 }
15d515fe15f5 Added POJOs to be mapped to schema.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
431 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org