1 | /*
|
---|
2 | * Copyright (c) 2003 Objectix Pty Ltd All rights reserved.
|
---|
3 | *
|
---|
4 | * This library is free software; you can redistribute it and/or
|
---|
5 | * modify it under the terms of the GNU Lesser General Public
|
---|
6 | * License as published by the Free Software Foundation.
|
---|
7 | *
|
---|
8 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
|
---|
9 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
10 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
11 | * DISCLAIMED. IN NO EVENT SHALL OBJECTIX PTY LTD BE LIABLE FOR ANY
|
---|
12 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
13 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
---|
14 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
15 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
---|
16 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
---|
17 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
---|
18 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
19 | */
|
---|
20 | package org.openstreetmap.josm.data.projection.datum;
|
---|
21 |
|
---|
22 | import java.io.Serializable;
|
---|
23 |
|
---|
24 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * A value object for storing Longitude and Latitude of a point, the
|
---|
28 | * Lon and Lat shift values to get from one datum to another, and the
|
---|
29 | * Lon and Lat accuracy of the shift values.
|
---|
30 | * <p>All values are stored as Positive West Seconds, but accessors
|
---|
31 | * are also provided for Positive East Degrees.
|
---|
32 | *
|
---|
33 | * @author Peter Yuill
|
---|
34 | * Modifified for JOSM :
|
---|
35 | * - add a constructor for JOSM LatLon (Pieren)
|
---|
36 | */
|
---|
37 | public class NTV2GridShift implements Serializable {
|
---|
38 |
|
---|
39 | private static final long serialVersionUID = 1L;
|
---|
40 |
|
---|
41 | private static final double METRE_PER_SECOND = 2.0 * Math.PI * 6378137.0 / 3600.0 / 360.0;
|
---|
42 | private static final double RADIANS_PER_SECOND = 2.0 * Math.PI / 3600.0 / 360.0;
|
---|
43 | private double lon;
|
---|
44 | private double lat;
|
---|
45 | private double lonShift;
|
---|
46 | private double latShift;
|
---|
47 | private double lonAccuracy;
|
---|
48 | private double latAccuracy;
|
---|
49 | private boolean latAccuracyAvailable;
|
---|
50 | private boolean lonAccuracyAvailable;
|
---|
51 | private String subGridName;
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Constructs a new {@code NTV2GridShift}.
|
---|
55 | */
|
---|
56 | public NTV2GridShift() {
|
---|
57 | }
|
---|
58 |
|
---|
59 | public NTV2GridShift(LatLon p) {
|
---|
60 | setLatDegrees(p.lat());
|
---|
61 | setLonPositiveEastDegrees(p.lon());
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Data access function for latitude value
|
---|
66 | * @return latitude in seconds
|
---|
67 | */
|
---|
68 | public double getLatSeconds() {
|
---|
69 | return lat;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Data access function for latitude value
|
---|
74 | * @return latitude in degree
|
---|
75 | */
|
---|
76 | public double getLatDegrees() {
|
---|
77 | return lat / 3600.0;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Data access function for latitude shift value
|
---|
82 | * @return latitude shift in seconds
|
---|
83 | */
|
---|
84 | public double getLatShiftSeconds() {
|
---|
85 | return latShift;
|
---|
86 | }
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Data access function for latitude shift value
|
---|
90 | * @return latitude shift in degree
|
---|
91 | */
|
---|
92 | public double getLatShiftDegrees() {
|
---|
93 | return latShift / 3600.0;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Data access function for already shifted latitude value
|
---|
98 | * @return shifted latitude in seconds
|
---|
99 | */
|
---|
100 | public double getShiftedLatSeconds() {
|
---|
101 | return lat + latShift;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Data access function for already shifted latitude value
|
---|
106 | * @return shifted latitude in degree
|
---|
107 | */
|
---|
108 | public double getShiftedLatDegrees() {
|
---|
109 | return (lat + latShift) / 3600.0;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * Checks whether latitude accuracy is available or not
|
---|
114 | * @return <code>true</code> if latitude accuracy is available
|
---|
115 | */
|
---|
116 | public boolean isLatAccuracyAvailable() {
|
---|
117 | return latAccuracyAvailable;
|
---|
118 | }
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Data access function for latitude accuracy
|
---|
122 | * @return latitude accuracy in seconds
|
---|
123 | */
|
---|
124 | public double getLatAccuracySeconds() {
|
---|
125 | if (!latAccuracyAvailable)
|
---|
126 | throw new IllegalStateException("Latitude Accuracy not available");
|
---|
127 | return latAccuracy;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Data access function for latitude accuracy
|
---|
132 | * @return latitude accuracy in degree
|
---|
133 | */
|
---|
134 | public double getLatAccuracyDegrees() {
|
---|
135 | if (!latAccuracyAvailable)
|
---|
136 | throw new IllegalStateException("Latitude Accuracy not available");
|
---|
137 | return latAccuracy / 3600.0;
|
---|
138 | }
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Data access function for latitude accuracy
|
---|
142 | * @return latitude accuracy in meter
|
---|
143 | */
|
---|
144 | public double getLatAccuracyMetres() {
|
---|
145 | if (!latAccuracyAvailable)
|
---|
146 | throw new IllegalStateException("Latitude Accuracy not available");
|
---|
147 | return latAccuracy * METRE_PER_SECOND;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Data access function for longitude value, positive values in west direction
|
---|
152 | * @return longitude in seconds
|
---|
153 | */
|
---|
154 | public double getLonPositiveWestSeconds() {
|
---|
155 | return lon;
|
---|
156 | }
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Data access function for longitude value, positive values in east direction
|
---|
160 | * @return longitude in degree
|
---|
161 | */
|
---|
162 | public double getLonPositiveEastDegrees() {
|
---|
163 | return lon / -3600.0;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Data access function for longitude shift value, positive values in west direction
|
---|
168 | * @return longitude shift in seconds
|
---|
169 | */
|
---|
170 | public double getLonShiftPositiveWestSeconds() {
|
---|
171 | return lonShift;
|
---|
172 | }
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * Data access function for longitude shift value, positive values in east direction
|
---|
176 | * @return longitude shift in degree
|
---|
177 | */
|
---|
178 | public double getLonShiftPositiveEastDegrees() {
|
---|
179 | return lonShift / -3600.0;
|
---|
180 | }
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Data access function for shifted longitude value, positive values in west direction
|
---|
184 | * @return shifted longitude in seconds
|
---|
185 | */
|
---|
186 | public double getShiftedLonPositiveWestSeconds() {
|
---|
187 | return lon + lonShift;
|
---|
188 | }
|
---|
189 |
|
---|
190 | /**
|
---|
191 | * Data access function for shifted longitude value, positive values in east direction
|
---|
192 | * @return shifted longitude in degree
|
---|
193 | */
|
---|
194 | public double getShiftedLonPositiveEastDegrees() {
|
---|
195 | return (lon + lonShift) / -3600.0;
|
---|
196 | }
|
---|
197 |
|
---|
198 | /**
|
---|
199 | * Checks whether longitude accuracy is available or not
|
---|
200 | * @return <code>true</code> if longitude accuracy is available
|
---|
201 | */
|
---|
202 | public boolean isLonAccuracyAvailable() {
|
---|
203 | return lonAccuracyAvailable;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Data access function for longitude accuracy
|
---|
208 | * @return longitude accuracy in seconds
|
---|
209 | */
|
---|
210 | public double getLonAccuracySeconds() {
|
---|
211 | if (!lonAccuracyAvailable)
|
---|
212 | throw new IllegalStateException("Longitude Accuracy not available");
|
---|
213 | return lonAccuracy;
|
---|
214 | }
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Data access function for longitude accuracy
|
---|
218 | * @return longitude accuracy in degree
|
---|
219 | */
|
---|
220 | public double getLonAccuracyDegrees() {
|
---|
221 | if (!lonAccuracyAvailable)
|
---|
222 | throw new IllegalStateException("Longitude Accuracy not available");
|
---|
223 | return lonAccuracy / 3600.0;
|
---|
224 | }
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Data access function for longitude accuracy
|
---|
228 | * @return longitude accuracy in meter
|
---|
229 | */
|
---|
230 | public double getLonAccuracyMetres() {
|
---|
231 | if (!lonAccuracyAvailable)
|
---|
232 | throw new IllegalStateException("Longitude Accuracy not available");
|
---|
233 | return lonAccuracy * METRE_PER_SECOND * Math.cos(RADIANS_PER_SECOND * lat);
|
---|
234 | }
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * Data store function for latitude
|
---|
238 | * @param d latitude value in seconds
|
---|
239 | */
|
---|
240 | public final void setLatSeconds(double d) {
|
---|
241 | lat = d;
|
---|
242 | }
|
---|
243 |
|
---|
244 | /**
|
---|
245 | * Data store function for latitude
|
---|
246 | * @param d latitude value in degree
|
---|
247 | */
|
---|
248 | public final void setLatDegrees(double d) {
|
---|
249 | lat = d * 3600.0;
|
---|
250 | }
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Data store function for latitude accuracy availability
|
---|
254 | * @param b availability of latitude accuracy
|
---|
255 | */
|
---|
256 | public final void setLatAccuracyAvailable(boolean b) {
|
---|
257 | latAccuracyAvailable = b;
|
---|
258 | }
|
---|
259 |
|
---|
260 | /**
|
---|
261 | * Data store function for latitude accuracy
|
---|
262 | * @param d latitude accuracy in seconds
|
---|
263 | */
|
---|
264 | public final void setLatAccuracySeconds(double d) {
|
---|
265 | latAccuracy = d;
|
---|
266 | }
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Data store function for latitude shift
|
---|
270 | * @param d latitude shift in seconds
|
---|
271 | */
|
---|
272 | public final void setLatShiftSeconds(double d) {
|
---|
273 | latShift = d;
|
---|
274 | }
|
---|
275 |
|
---|
276 | /**
|
---|
277 | * Data store function for longitude
|
---|
278 | * @param d latitude value in seconds, west direction is positive
|
---|
279 | */
|
---|
280 | public final void setLonPositiveWestSeconds(double d) {
|
---|
281 | lon = d;
|
---|
282 | }
|
---|
283 |
|
---|
284 | /**
|
---|
285 | * Data store function for longitude
|
---|
286 | * @param d latitude value in degree, est direction is positive
|
---|
287 | */
|
---|
288 | public final void setLonPositiveEastDegrees(double d) {
|
---|
289 | lon = d * -3600.0;
|
---|
290 | }
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Data store function for longitude accuracy availability
|
---|
294 | * @param b availability of longitude accuracy
|
---|
295 | */
|
---|
296 | public final void setLonAccuracyAvailable(boolean b) {
|
---|
297 | lonAccuracyAvailable = b;
|
---|
298 | }
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * Data store function for longitude accuracy
|
---|
302 | * @param d longitude accuracy in seconds
|
---|
303 | */
|
---|
304 | public final void setLonAccuracySeconds(double d) {
|
---|
305 | lonAccuracy = d;
|
---|
306 | }
|
---|
307 |
|
---|
308 | /**
|
---|
309 | * Data store function for longitude shift value
|
---|
310 | * @param d longitude shift in seconds, west direction is positive
|
---|
311 | */
|
---|
312 | public final void setLonShiftPositiveWestSeconds(double d) {
|
---|
313 | lonShift = d;
|
---|
314 | }
|
---|
315 |
|
---|
316 | /**
|
---|
317 | * Get the name of the sub grid
|
---|
318 | * @return name of the sub grid
|
---|
319 | */
|
---|
320 | public String getSubGridName() {
|
---|
321 | return subGridName;
|
---|
322 | }
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Set the name of the sub grid
|
---|
326 | * @param string name of the sub grid
|
---|
327 | */
|
---|
328 | public void setSubGridName(String string) {
|
---|
329 | subGridName = string;
|
---|
330 | }
|
---|
331 |
|
---|
332 | /**
|
---|
333 | * Make this object a copy of the supplied GridShift
|
---|
334 | * @param gs grid to copy data from
|
---|
335 | */
|
---|
336 | public void copy(NTV2GridShift gs) {
|
---|
337 | this.lon = gs.lon;
|
---|
338 | this.lat = gs.lat;
|
---|
339 | this.lonShift = gs.lonShift;
|
---|
340 | this.latShift = gs.latShift;
|
---|
341 | this.lonAccuracy = gs.lonAccuracy;
|
---|
342 | this.latAccuracy = gs.latAccuracy;
|
---|
343 | this.latAccuracyAvailable = gs.latAccuracyAvailable;
|
---|
344 | this.lonAccuracyAvailable = gs.lonAccuracyAvailable;
|
---|
345 | this.subGridName = gs.subGridName;
|
---|
346 | }
|
---|
347 |
|
---|
348 | }
|
---|