source: josm/trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java@ 5040

Last change on this file since 5040 was 5040, checked in by Don-vip, 12 years ago

Allow plugins to retrieve known Lambert projection parameters

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
4import org.openstreetmap.josm.data.projection.datum.Datum;
5import org.openstreetmap.josm.data.projection.proj.Proj;
6import org.openstreetmap.josm.data.coor.EastNorth;
7import org.openstreetmap.josm.data.coor.LatLon;
8
9/**
10 * Implementation of the Projection interface that represents a coordinate reference system and delegates
11 * the real projection and datum conversion to other classes.
12 *
13 * It handles false easting and northing, central meridian and general scale factor before calling the
14 * delegate projection.
15 *
16 * Forwards lat/lon values to the real projection in units of radians.
17 *
18 * The fields are named after Proj.4 parameters.
19 *
20 * Subclasses of AbstractProjection must set ellps and proj to a non-null value.
21 * In addition, either datum or nadgrid has to be initialized to some value.
22 *
23 * FIXME: nadgrids should probably be implemented as a Datum
24 */
25abstract public class AbstractProjection implements Projection {
26
27 protected Ellipsoid ellps;
28 protected Datum datum;
29 protected Proj proj;
30 protected double x_0 = 0.0; /* false easting (in meters) */
31 protected double y_0 = 0.0; /* false northing (in meters) */
32 protected double lon_0 = 0.0; /* central meridian */
33 protected double k_0 = 1.0; /* general scale factor */
34 protected NTV2GridShiftFile nadgrids = null;
35
36 public final Ellipsoid getEllipsoid() {
37 return ellps;
38 }
39
40 public final Datum getDatum() {
41 return datum;
42 }
43
44 public final Proj getProj() {
45 return proj;
46 }
47
48 public final double getFalseEasting() {
49 return x_0;
50 }
51
52 public final double getFalseNorthing() {
53 return y_0;
54 }
55
56 public final double getCentralMeridian() {
57 return lon_0;
58 }
59
60 public final double getScaleFactor() {
61 return k_0;
62 }
63
64 @Override
65 public EastNorth latlon2eastNorth(LatLon ll) {
66 if (nadgrids != null) {
67 NTV2GridShift gs = new NTV2GridShift(ll);
68 nadgrids.gridShiftReverse(gs);
69 ll = new LatLon(ll.lat()+gs.getLatShiftDegrees(), ll.lon()+gs.getLonShiftPositiveEastDegrees());
70 } else {
71 ll = datum.fromWGS84(ll);
72 }
73 double[] en = proj.project(Math.toRadians(ll.lat()), Math.toRadians(ll.lon() - lon_0));
74 return new EastNorth(ellps.a * k_0 * en[0] + x_0, ellps.a * k_0 * en[1] + y_0);
75 }
76
77 @Override
78 public LatLon eastNorth2latlon(EastNorth en) {
79 double[] latlon_rad = proj.invproject((en.east() - x_0) / ellps.a / k_0, (en.north() - y_0) / ellps.a / k_0);
80 LatLon ll = new LatLon(Math.toDegrees(latlon_rad[0]), Math.toDegrees(latlon_rad[1]) + lon_0);
81 if (nadgrids != null) {
82 NTV2GridShift gs = new NTV2GridShift(ll);
83 nadgrids.gridShiftForward(gs);
84 ll = new LatLon(ll.lat()+gs.getLatShiftDegrees(), ll.lon()+gs.getLonShiftPositiveEastDegrees());
85 } else {
86 ll = datum.toWGS84(ll);
87 }
88 return ll;
89 }
90
91 @Override
92 public double getDefaultZoomInPPD() {
93 // this will set the map scaler to about 1000 m
94 return 10;
95 }
96
97 /**
98 * @return The EPSG Code of this CRS, null if it doesn't have one.
99 */
100 public abstract Integer getEpsgCode();
101
102 /**
103 * Default implementation of toCode().
104 * Should be overridden, if there is no EPSG code for this CRS.
105 */
106 @Override
107 public String toCode() {
108 return "EPSG:" + getEpsgCode();
109 }
110
111 protected static final double convertMinuteSecond(double minute, double second) {
112 return (minute/60.0) + (second/3600.0);
113 }
114
115 protected static final double convertDegreeMinuteSecond(double degree, double minute, double second) {
116 return degree + convertMinuteSecond(minute, second);
117 }
118}
Note: See TracBrowser for help on using the repository browser.