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

Last change on this file since 9105 was 9105, checked in by bastiK, 8 years ago

add support for proj.4 parameter +pm=* - prime meridian (see #12186)

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
4import org.openstreetmap.josm.data.coor.EastNorth;
5import org.openstreetmap.josm.data.coor.LatLon;
6import org.openstreetmap.josm.data.projection.datum.Datum;
7import org.openstreetmap.josm.data.projection.proj.Proj;
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 */
23public abstract class AbstractProjection implements Projection {
24
25 protected Ellipsoid ellps;
26 protected Datum datum;
27 protected Proj proj;
28 protected double x0; /* false easting (in meters) */
29 protected double y0; /* false northing (in meters) */
30 protected double lon0; /* central meridian */
31 protected double pm; /* prime meridian */
32 protected double k0 = 1.0; /* general scale factor */
33
34 public final Ellipsoid getEllipsoid() {
35 return ellps;
36 }
37
38 public final Datum getDatum() {
39 return datum;
40 }
41
42 /**
43 * Replies the projection (in the narrow sense)
44 * @return The projection object
45 */
46 public final Proj getProj() {
47 return proj;
48 }
49
50 public final double getFalseEasting() {
51 return x0;
52 }
53
54 public final double getFalseNorthing() {
55 return y0;
56 }
57
58 public final double getCentralMeridian() {
59 return lon0;
60 }
61
62 public final double getScaleFactor() {
63 return k0;
64 }
65
66 @Override
67 public EastNorth latlon2eastNorth(LatLon ll) {
68 ll = datum.fromWGS84(ll);
69 double[] en = proj.project(Math.toRadians(ll.lat()), Math.toRadians(ll.lon() - lon0 - pm));
70 return new EastNorth(ellps.a * k0 * en[0] + x0, ellps.a * k0 * en[1] + y0);
71 }
72
73 @Override
74 public LatLon eastNorth2latlon(EastNorth en) {
75 double[] latlon_rad = proj.invproject((en.east() - x0) / ellps.a / k0, (en.north() - y0) / ellps.a / k0);
76 LatLon ll = new LatLon(Math.toDegrees(latlon_rad[0]), Math.toDegrees(latlon_rad[1]) + lon0 + pm);
77 return datum.toWGS84(ll);
78 }
79
80 @Override
81 public double getDefaultZoomInPPD() {
82 // this will set the map scaler to about 1000 m
83 return 10;
84 }
85
86 /**
87 * @return The EPSG Code of this CRS, null if it doesn't have one.
88 */
89 public abstract Integer getEpsgCode();
90
91 /**
92 * Default implementation of toCode().
93 * Should be overridden, if there is no EPSG code for this CRS.
94 */
95 @Override
96 public String toCode() {
97 return "EPSG:" + getEpsgCode();
98 }
99
100 protected static final double convertMinuteSecond(double minute, double second) {
101 return (minute/60.0) + (second/3600.0);
102 }
103
104 protected static final double convertDegreeMinuteSecond(double degree, double minute, double second) {
105 return degree + (minute/60.0) + (second/3600.0);
106 }
107}
Note: See TracBrowser for help on using the repository browser.