source: josm/trunk/src/org/openstreetmap/josm/data/projection/NTV2GridShift.java@ 3480

Last change on this file since 3480 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 7.0 KB
Line 
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 */
20package org.openstreetmap.josm.data.projection;
21
22import java.io.Serializable;
23
24import 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 */
37public class NTV2GridShift implements Serializable {
38
39 private static final double METRE_PER_SECOND = 2.0 * Math.PI * 6378137.0 / 3600.0 / 360.0;
40 private static final double RADIANS_PER_SECOND = 2.0 * Math.PI / 3600.0 / 360.0;
41 private double lon;
42 private double lat;
43 private double lonShift;
44 private double latShift;
45 private double lonAccuracy;
46 private double latAccuracy;
47 boolean latAccuracyAvailable;
48 boolean lonAccuracyAvailable;
49 private String subGridName;
50
51 public NTV2GridShift() {
52 }
53
54 public NTV2GridShift(LatLon p) {
55 setLatDegrees(p.lat());
56 setLonPositiveEastDegrees(p.lon());
57 }
58
59 /**
60 * @return
61 */
62 public double getLatSeconds() {
63 return lat;
64 }
65
66 /**
67 * @return
68 */
69 public double getLatDegrees() {
70 return lat / 3600.0;
71 }
72
73 /**
74 * @return
75 */
76 public double getLatShiftSeconds() {
77 return latShift;
78 }
79
80 /**
81 * @return
82 */
83 public double getLatShiftDegrees() {
84 return latShift / 3600.0;
85 }
86
87 /**
88 * @return
89 */
90 public double getShiftedLatSeconds() {
91 return lat + latShift;
92 }
93
94 /**
95 * @return
96 */
97 public double getShiftedLatDegrees() {
98 return (lat + latShift) / 3600.0;
99 }
100
101 /**
102 * @return
103 */
104 public boolean isLatAccuracyAvailable() {
105 return latAccuracyAvailable;
106 }
107
108 /**
109 * @return
110 */
111 public double getLatAccuracySeconds() {
112 if (!latAccuracyAvailable)
113 throw new IllegalStateException("Latitude Accuracy not available");
114 return latAccuracy;
115 }
116
117 /**
118 * @return
119 */
120 public double getLatAccuracyDegrees() {
121 if (!latAccuracyAvailable)
122 throw new IllegalStateException("Latitude Accuracy not available");
123 return latAccuracy / 3600.0;
124 }
125
126 /**
127 * @return
128 */
129 public double getLatAccuracyMetres() {
130 if (!latAccuracyAvailable)
131 throw new IllegalStateException("Latitude Accuracy not available");
132 return latAccuracy * METRE_PER_SECOND;
133 }
134
135 /**
136 * @return
137 */
138 public double getLonPositiveWestSeconds() {
139 return lon;
140 }
141
142 /**
143 * @return
144 */
145 public double getLonPositiveEastDegrees() {
146 return lon / -3600.0;
147 }
148
149 /**
150 * @return
151 */
152 public double getLonShiftPositiveWestSeconds() {
153 return lonShift;
154 }
155
156 /**
157 * @return
158 */
159 public double getLonShiftPositiveEastDegrees() {
160 return lonShift / -3600.0;
161 }
162
163 /**
164 * @return
165 */
166 public double getShiftedLonPositiveWestSeconds() {
167 return lon + lonShift;
168 }
169
170 /**
171 * @return
172 */
173 public double getShiftedLonPositiveEastDegrees() {
174 return (lon + lonShift) / -3600.0;
175 }
176
177 /**
178 * @return
179 */
180 public boolean isLonAccuracyAvailable() {
181 return lonAccuracyAvailable;
182 }
183
184 /**
185 * @return
186 */
187 public double getLonAccuracySeconds() {
188 if (!lonAccuracyAvailable)
189 throw new IllegalStateException("Longitude Accuracy not available");
190 return lonAccuracy;
191 }
192
193 /**
194 * @return
195 */
196 public double getLonAccuracyDegrees() {
197 if (!lonAccuracyAvailable)
198 throw new IllegalStateException("Longitude Accuracy not available");
199 return lonAccuracy / 3600.0;
200 }
201
202 /**
203 * @return
204 */
205 public double getLonAccuracyMetres() {
206 if (!lonAccuracyAvailable)
207 throw new IllegalStateException("Longitude Accuracy not available");
208 return lonAccuracy * METRE_PER_SECOND * Math.cos(RADIANS_PER_SECOND * lat);
209 }
210
211 /**
212 * @param d
213 */
214 public void setLatSeconds(double d) {
215 lat = d;
216 }
217
218 /**
219 * @param d
220 */
221 public void setLatDegrees(double d) {
222 lat = d * 3600.0;
223 }
224
225 /**
226 * @param b
227 */
228 public void setLatAccuracyAvailable(boolean b) {
229 latAccuracyAvailable = b;
230 }
231
232 /**
233 * @param d
234 */
235 public void setLatAccuracySeconds(double d) {
236 latAccuracy = d;
237 }
238
239 /**
240 * @param d
241 */
242 public void setLatShiftSeconds(double d) {
243 latShift = d;
244 }
245
246 /**
247 * @param d
248 */
249 public void setLonPositiveWestSeconds(double d) {
250 lon = d;
251 }
252
253 /**
254 * @param d
255 */
256 public void setLonPositiveEastDegrees(double d) {
257 lon = d * -3600.0;
258 }
259
260 /**
261 * @param b
262 */
263 public void setLonAccuracyAvailable(boolean b) {
264 lonAccuracyAvailable = b;
265 }
266
267 /**
268 * @param d
269 */
270 public void setLonAccuracySeconds(double d) {
271 lonAccuracy = d;
272 }
273
274 /**
275 * @param d
276 */
277 public void setLonShiftPositiveWestSeconds(double d) {
278 lonShift = d;
279 }
280
281 /**
282 * @return
283 */
284 public String getSubGridName() {
285 return subGridName;
286 }
287
288 /**
289 * @param string
290 */
291 public void setSubGridName(String string) {
292 subGridName = string;
293 }
294
295 /**
296 * Make this object a copy of the supplied GridShift
297 * @param gs
298 */
299 public void copy(NTV2GridShift gs) {
300 this.lon = gs.lon;
301 this.lat = gs.lat;
302 this.lonShift = gs.lonShift;
303 this.latShift = gs.latShift;
304 this.lonAccuracy = gs.lonAccuracy;
305 this.latAccuracy = gs.latAccuracy;
306 this.latAccuracyAvailable = gs.latAccuracyAvailable;
307 this.lonAccuracyAvailable = gs.lonAccuracyAvailable;
308 this.subGridName = gs.subGridName;
309 }
310
311}
Note: See TracBrowser for help on using the repository browser.