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