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

Last change on this file since 5889 was 5239, checked in by bastiK, 12 years ago

projections: minor stuff

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