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

Last change on this file since 11747 was 11642, checked in by Don-vip, 7 years ago

fix #14422 - Dynamic NTV2 grids

  • 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;
5
6import org.openstreetmap.josm.data.coor.LatLon;
7import org.openstreetmap.josm.data.projection.Ellipsoid;
8import org.openstreetmap.josm.tools.JosmRuntimeException;
9
10/**
11 * Datum based of NTV2 grid shift file.
12 */
13public 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}
Note: See TracBrowser for help on using the repository browser.