source: josm/trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2Datum.java

Last change on this file was 14440, checked in by Don-vip, 5 years ago

fix #17018 - NPE

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection.datum;
3
4import java.io.IOException;
5import java.util.Objects;
6
7import org.openstreetmap.josm.data.coor.LatLon;
8import org.openstreetmap.josm.data.projection.Ellipsoid;
9import org.openstreetmap.josm.tools.JosmRuntimeException;
10
11/**
12 * Datum based of NTV2 grid shift file.
13 * @since 5073
14 */
15public 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}
Note: See TracBrowser for help on using the repository browser.