[4285] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.projection;
|
---|
| 3 |
|
---|
[5237] | 4 | import org.openstreetmap.josm.data.coor.EastNorth;
|
---|
| 5 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
[4285] | 6 | import org.openstreetmap.josm.data.projection.datum.Datum;
|
---|
| 7 | import 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 | */
|
---|
[6883] | 23 | public abstract class AbstractProjection implements Projection {
|
---|
[4285] | 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 */
|
---|
[5073] | 32 |
|
---|
[5039] | 33 | public final Ellipsoid getEllipsoid() {
|
---|
| 34 | return ellps;
|
---|
| 35 | }
|
---|
[4285] | 36 |
|
---|
[5039] | 37 | public final Datum getDatum() {
|
---|
| 38 | return datum;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[6135] | 41 | /**
|
---|
| 42 | * Replies the projection (in the narrow sense)
|
---|
| 43 | * @return The projection object
|
---|
| 44 | */
|
---|
[5040] | 45 | public final Proj getProj() {
|
---|
| 46 | return proj;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[5039] | 49 | public final double getFalseEasting() {
|
---|
| 50 | return x_0;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public final double getFalseNorthing() {
|
---|
| 54 | return y_0;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | public final double getCentralMeridian() {
|
---|
| 58 | return lon_0;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public final double getScaleFactor() {
|
---|
| 62 | return k_0;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[4285] | 65 | @Override
|
---|
| 66 | public EastNorth latlon2eastNorth(LatLon ll) {
|
---|
[5073] | 67 | ll = datum.fromWGS84(ll);
|
---|
[4285] | 68 | double[] en = proj.project(Math.toRadians(ll.lat()), Math.toRadians(ll.lon() - lon_0));
|
---|
| 69 | return new EastNorth(ellps.a * k_0 * en[0] + x_0, ellps.a * k_0 * en[1] + y_0);
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | @Override
|
---|
| 73 | public LatLon eastNorth2latlon(EastNorth en) {
|
---|
| 74 | double[] latlon_rad = proj.invproject((en.east() - x_0) / ellps.a / k_0, (en.north() - y_0) / ellps.a / k_0);
|
---|
| 75 | LatLon ll = new LatLon(Math.toDegrees(latlon_rad[0]), Math.toDegrees(latlon_rad[1]) + lon_0);
|
---|
[5073] | 76 | return datum.toWGS84(ll);
|
---|
[4285] | 77 | }
|
---|
| 78 |
|
---|
| 79 | @Override
|
---|
| 80 | public double getDefaultZoomInPPD() {
|
---|
| 81 | // this will set the map scaler to about 1000 m
|
---|
| 82 | return 10;
|
---|
| 83 | }
|
---|
[5073] | 84 |
|
---|
[4285] | 85 | /**
|
---|
| 86 | * @return The EPSG Code of this CRS, null if it doesn't have one.
|
---|
| 87 | */
|
---|
| 88 | public abstract Integer getEpsgCode();
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * Default implementation of toCode().
|
---|
| 92 | * Should be overridden, if there is no EPSG code for this CRS.
|
---|
| 93 | */
|
---|
| 94 | @Override
|
---|
| 95 | public String toCode() {
|
---|
| 96 | return "EPSG:" + getEpsgCode();
|
---|
| 97 | }
|
---|
[5073] | 98 |
|
---|
[5022] | 99 | protected static final double convertMinuteSecond(double minute, double second) {
|
---|
| 100 | return (minute/60.0) + (second/3600.0);
|
---|
| 101 | }
|
---|
[5073] | 102 |
|
---|
[5022] | 103 | protected static final double convertDegreeMinuteSecond(double degree, double minute, double second) {
|
---|
[5239] | 104 | return degree + (minute/60.0) + (second/3600.0);
|
---|
[5022] | 105 | }
|
---|
[4285] | 106 | }
|
---|