1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.projection;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.Bounds;
|
---|
7 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
8 | import org.openstreetmap.josm.data.projection.datum.WGS84Datum;
|
---|
9 | import org.openstreetmap.josm.data.projection.proj.ProjParameters;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | *
|
---|
13 | * @author Dirk Stöcker
|
---|
14 | * code based on JavaScript from Chuck Taylor
|
---|
15 | *
|
---|
16 | */
|
---|
17 | public class UTM extends AbstractProjection {
|
---|
18 |
|
---|
19 | private static final int DEFAULT_ZONE = 30;
|
---|
20 | private int zone;
|
---|
21 |
|
---|
22 | public enum Hemisphere { North, South }
|
---|
23 | private static final Hemisphere DEFAULT_HEMISPHERE = Hemisphere.North;
|
---|
24 | private Hemisphere hemisphere;
|
---|
25 |
|
---|
26 | public UTM() {
|
---|
27 | this(DEFAULT_ZONE, DEFAULT_HEMISPHERE);
|
---|
28 | }
|
---|
29 |
|
---|
30 | public UTM(int zone, Hemisphere hemisphere) {
|
---|
31 | if (zone < 1 || zone > 60)
|
---|
32 | throw new IllegalArgumentException();
|
---|
33 | ellps = Ellipsoid.WGS84;
|
---|
34 | proj = new org.openstreetmap.josm.data.projection.proj.TransverseMercator();
|
---|
35 | try {
|
---|
36 | proj.initialize(new ProjParameters() {{ ellps = UTM.this.ellps; }});
|
---|
37 | } catch (ProjectionConfigurationException e) {
|
---|
38 | throw new RuntimeException(e);
|
---|
39 | }
|
---|
40 | datum = WGS84Datum.INSTANCE;
|
---|
41 | this.zone = zone;
|
---|
42 | this.hemisphere = hemisphere;
|
---|
43 | x_0 = 500000;
|
---|
44 | y_0 = hemisphere == Hemisphere.North ? 0 : 10000000;
|
---|
45 | lon_0 = getUtmCentralMeridianDeg(zone);
|
---|
46 | k_0 = 0.9996;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * UTMCentralMeridian
|
---|
51 | *
|
---|
52 | * Determines the central meridian for the given UTM zone.
|
---|
53 | *
|
---|
54 | * Inputs:
|
---|
55 | * zone - An integer value designating the UTM zone, range [1,60].
|
---|
56 | *
|
---|
57 | * Returns:
|
---|
58 | * The central meridian for the given UTM zone, in radians, or zero
|
---|
59 | * if the UTM zone parameter is outside the range [1,60].
|
---|
60 | * Range of the central meridian is the radian equivalent of [-177,+177].
|
---|
61 | *
|
---|
62 | */
|
---|
63 | private double getUtmCentralMeridianDeg(int zone)
|
---|
64 | {
|
---|
65 | return -183.0 + (zone * 6.0);
|
---|
66 | }
|
---|
67 |
|
---|
68 | public int getzone() {
|
---|
69 | return zone;
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Override
|
---|
73 | public String toString() {
|
---|
74 | return tr("UTM");
|
---|
75 | }
|
---|
76 |
|
---|
77 | @Override
|
---|
78 | public Integer getEpsgCode() {
|
---|
79 | return (32600 + getzone() + (hemisphere == Hemisphere.South?100:0));
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Override
|
---|
83 | public int hashCode() {
|
---|
84 | return toCode().hashCode();
|
---|
85 | }
|
---|
86 |
|
---|
87 | @Override
|
---|
88 | public String getCacheDirectoryName() {
|
---|
89 | return "epsg"+ getEpsgCode();
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Override
|
---|
93 | public Bounds getWorldBoundsLatLon()
|
---|
94 | {
|
---|
95 | if (hemisphere == Hemisphere.North)
|
---|
96 | return new Bounds(
|
---|
97 | new LatLon(-5.0, getUtmCentralMeridianDeg(getzone())-5.0),
|
---|
98 | new LatLon(85.0, getUtmCentralMeridianDeg(getzone())+5.0), false);
|
---|
99 | else
|
---|
100 | return new Bounds(
|
---|
101 | new LatLon(-85.0, getUtmCentralMeridianDeg(getzone())-5.0),
|
---|
102 | new LatLon(5.0, getUtmCentralMeridianDeg(getzone())+5.0), false);
|
---|
103 | }
|
---|
104 |
|
---|
105 | }
|
---|