Project

General

Profile

Download (9.45 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / sitools-idoc / hesiod / javaExt / src / fr / ias / sitools / vo / ssa / AbstractSqlGeometryConstraint.java @ 779bac69

1
 /*******************************************************************************
2
 * Copyright 2010-2013 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
 *
4
 * This file is part of SITools2.
5
 *
6
 * SITools2 is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * SITools2 is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
 ******************************************************************************/
19
package fr.ias.sitools.vo.ssa;
20

    
21
import java.util.ArrayList;
22
import java.util.Arrays;
23
import java.util.List;
24
import java.util.logging.Logger;
25

    
26
/**
27
 * Interface to define a SQL spatial constraint.
28
 * @author Jean-Christophe Malapert <jean-christophe.malapert@cnes.fr>
29
 */
30
public abstract class AbstractSqlGeometryConstraint {
31
    
32
    /**
33
     * LOGGER
34
     */
35
     private static final Logger LOG = Logger.getLogger(AbstractSqlGeometryConstraint.class.getName());
36

    
37
  /**
38
   * Index where the min value of a range is located.
39
   */
40
  protected static final int MIN = 0;
41
  /**
42
   * Index where the max value of a range is located.
43
   */
44
  protected static final int MAX = 1;
45

    
46
  /**
47
   * Size parameter given by the user.
48
   */
49
  private transient double[] sizeArray = new double[2];
50
  /**
51
   * Central position along right ascension axis.
52
   */
53
  private transient double raUser;
54
  /**
55
   * Central position along declination axis.
56
   */
57
  private transient double decUser;
58
  /**
59
   * time.
60
   */
61
  private transient String[] timeUser = new String[2];
62
  /**
63
   * band.
64
   */
65
  private transient double[] bandUser = new double[2];
66

    
67
  /**
68
   * Sets the geometry attribute.
69
   * @param geometry the geometry attribute
70
   */
71
  public abstract void setGeometry(final Object geometry);
72

    
73
  /**
74
   * Sets user input parameters.
75
   * @param inputParameters user input parameters
76
   */
77
  public final void setInputParameters(final SimpleSpectralAccessInputParameters inputParameters) {
78
    this.raUser = inputParameters.getRa();
79
    this.decUser = inputParameters.getDec();
80
    if (inputParameters.getBand().length == 2) {
81
        this.bandUser = inputParameters.getBand();
82
    }else{
83
        this.bandUser[0] = inputParameters.getBand()[0];
84
        this.bandUser[1] = inputParameters.getBand()[0];
85
    }
86
    if (inputParameters.getTime().length == 2) {
87
        this.timeUser = inputParameters.getTime();
88
    }else{
89
        
90
        this.timeUser[0] = inputParameters.getTime()[0];
91
        this.timeUser[1] = inputParameters.getTime()[0];
92
    }
93
    if (inputParameters.getSize().length == 2) {
94
      this.sizeArray = inputParameters.getSize();
95
    } else { 
96
      this.sizeArray[0] = inputParameters.getSize()[0];
97
      this.sizeArray[1] = inputParameters.getSize()[0];
98
    }
99
  }
100

    
101
  /**
102
   * Detects when the SSA request has a collition with South pole.
103
   * @return True when the SSA request has a collition with South pole otherwise False
104
   */
105
  protected final boolean isSouthPoleCollision() {
106
    return (decUser - sizeArray[1] / 2.0 <= SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_DECLINATION) ? true : false;
107
  }
108

    
109
  /**
110
   * Detects when the SSA request has a collition with North pole.
111
   * @return True when the SSA request has a collition with North pole otherwise False
112
   */
113
  protected final boolean isNorthPoleCollision() {
114
    return (decUser + sizeArray[1] / 2.0 >= SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_DECLINATION) ? true : false;
115
  }
116

    
117
  /**
118
   * Detects when the SSA request has a collition with both North and South pole.
119
   * @return True when the SSA request has a collition with both North and South pole otherwise False
120
   */
121
  protected final boolean isPolesCollision() {
122
    return (isNorthPoleCollision() && isSouthPoleCollision()) ? true : false;
123
  }
124

    
125
  /**
126
   * Detects when the SSA request is a large polygon.
127
   *
128
   * <p>
129
   * A large polygon is a polygon where two points is separated by MAX_VALUE_FOR_RIGHT_ASCENSION / 2.0
130
   * along right ascension axis.
131
   * </p>
132
   * @return True when the SSA request is a large polygon otherwise False
133
   */
134
  protected final boolean isLargePolygon() {
135
    return (sizeArray[0] >= SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION / 2.0) ? true : false;
136
  }
137

    
138
  /**
139
   * Detects there is a collision with RA=MAX_VALUE_FOR_RIGHT_ASCENSION.
140
   * @return True when there is a collision with RA=MAX_VALUE_FOR_RIGHT_ASCENSION otherwise False
141
   */
142
  protected final boolean isMaxRaCollision() {
143
    return (raUser + sizeArray[0] / 2.0 >= SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION) ? true : false;
144
  }
145

    
146
  /**
147
   * Detects there is a collision with RA=MIN_VALUE_FOR_RIGHT_ASCENSION.
148
   * @return True when there is a collision with RA=MIN_VALUE_FOR_RIGHT_ASCENSION otherwise False
149
   */
150
  protected final boolean isMinRaCollision() {
151
    return (raUser - sizeArray[0] / 2.0 <= SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_RIGHT_ASCENSION) ? true : false;
152
  }
153

    
154
  /**
155
   * Detects if the SSA request has a collision with the border of CAR projection centered on 0,0.
156
   * @return True when the SSA request has a collision with the borders otherwise False
157
   */
158
  protected final boolean isBorderRaCollision() {
159
    return (isMinRaCollision() && isMaxRaCollision()) ? true : false;
160
  }
161

    
162
  /**
163
   * Detects if the SSA request is a ring on the sphere.
164
   * @return True when the SSA request is a ring otherwise False
165
   */
166
  protected final boolean isRing() {
167
    return (sizeArray[0] == SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION) ? true : false;
168
  }
169

    
170
  /**
171
   * SQL geometry predicat to add to the SQL constraint.
172
   * @return SQL geometry predicat
173
   */
174
  public abstract String getSqlPredicat();
175

    
176
  /**
177
   * Computes ranges of the SSA request along right ascension and declination axes.
178
   *
179
   * <p>
180
   * For the declination axis, returns [decmin, decmax].<br/>
181
   * For the right ascension axis, returns List<Double[]>. The ranges are computed
182
   * based on the CAR projection.
183
   * </p>
184
   *
185
   * @return an array [List<Ra[min,max]>, Dec[min,max])
186
   */
187
  protected final Object computeRange() {
188
    final List<Double[]> raRange = new ArrayList<Double[]>();
189
    final double[] decRange = new double[2];
190
    if (this.isPolesCollision()) {
191
      decRange[MIN] = SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_DECLINATION;
192
      decRange[MAX] = SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_DECLINATION;
193
      raRange.add(new Double[]{SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_RIGHT_ASCENSION, SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION});
194
    } else if (this.isNorthPoleCollision()) {
195
      decRange[MIN] = decUser - sizeArray[1] / 2.0;
196
      decRange[MAX] = SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_DECLINATION;
197
      raRange.add(new Double[]{SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_RIGHT_ASCENSION, SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION});
198
    } else if (this.isSouthPoleCollision()) {
199
      decRange[MIN] = SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_DECLINATION;
200
      decRange[MAX] = decUser + sizeArray[1] / 2.0;
201
      raRange.add(new Double[]{SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_RIGHT_ASCENSION, SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION});
202
    } else {
203
      decRange[MIN] = decUser - sizeArray[1] / 2.0;
204
      decRange[MAX] = decUser + sizeArray[1] / 2.0;
205
      if (this.isBorderRaCollision()) {
206
        raRange.add(new Double[]{SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_RIGHT_ASCENSION,
207
                                 SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION});
208
      } else if (this.isMaxRaCollision()) {
209
        raRange.add(new Double[]{raUser - sizeArray[0] / 2.0,
210
                                 SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION});
211
        raRange.add(new Double[]{SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_RIGHT_ASCENSION,
212
                                (raUser + sizeArray[0] / 2.0 + SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION) % SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION});
213
      } else if (this.isMinRaCollision()) {
214
        raRange.add(new Double[]{SimpleSpectralAccessProtocolLibrary.MIN_VALUE_FOR_RIGHT_ASCENSION,
215
                                raUser + sizeArray[0] / 2.0});
216
        raRange.add(new Double[]{(raUser - sizeArray[0] / 2.0 + SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION) % SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION,
217
                                  SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION});
218
      } else {
219
        raRange.add(new Double[]{(raUser - sizeArray[0] / 2.0 + SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION) % SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION,
220
                                 (raUser + sizeArray[0] / 2.0 + SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION) % SimpleSpectralAccessProtocolLibrary.MAX_VALUE_FOR_RIGHT_ASCENSION});
221
      }
222
    }
223
    return Arrays.asList(raRange, decRange);
224
  }
225
  protected final Object computeTimeAndBandRange() {
226
   
227
   return Arrays.asList(timeUser, bandUser);
228
  }
229
}