1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.projection.datum;
|
---|
3 |
|
---|
4 | import java.io.IOException;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
7 | import org.openstreetmap.josm.data.projection.Ellipsoid;
|
---|
8 | import org.openstreetmap.josm.tools.JosmRuntimeException;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Datum based of NTV2 grid shift file.
|
---|
12 | */
|
---|
13 | public class NTV2Datum extends AbstractDatum {
|
---|
14 |
|
---|
15 | private final NTV2GridShiftFileWrapper nadgrids;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Constructs a new {@code NTV2Datum}.
|
---|
19 | * @param name datum name
|
---|
20 | * @param proj4Id PROJ.4 id
|
---|
21 | * @param ellps ellipsoid
|
---|
22 | * @param nadgrids NTV2 grid shift file wrapper
|
---|
23 | */
|
---|
24 | public NTV2Datum(String name, String proj4Id, Ellipsoid ellps, NTV2GridShiftFileWrapper nadgrids) {
|
---|
25 | super(name, proj4Id, ellps);
|
---|
26 | this.nadgrids = nadgrids;
|
---|
27 | }
|
---|
28 |
|
---|
29 | @Override
|
---|
30 | public LatLon toWGS84(LatLon ll) {
|
---|
31 | NTV2GridShift gs = new NTV2GridShift(ll);
|
---|
32 | try {
|
---|
33 | nadgrids.getShiftFile().gridShiftForward(gs);
|
---|
34 | return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees());
|
---|
35 | } catch (IOException e) {
|
---|
36 | throw new JosmRuntimeException(e);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public LatLon fromWGS84(LatLon ll) {
|
---|
42 | NTV2GridShift gs = new NTV2GridShift(ll);
|
---|
43 | try {
|
---|
44 | nadgrids.getShiftFile().gridShiftReverse(gs);
|
---|
45 | return new LatLon(ll.lat() + gs.getLatShiftDegrees(), ll.lon() + gs.getLonShiftPositiveEastDegrees());
|
---|
46 | } catch (IOException e) {
|
---|
47 | throw new JosmRuntimeException(e);
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|