1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.projection;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GridBagLayout;
|
---|
7 | import java.awt.event.ActionListener;
|
---|
8 | import java.util.Collection;
|
---|
9 | import java.util.Collections;
|
---|
10 |
|
---|
11 | import javax.swing.JComboBox;
|
---|
12 | import javax.swing.JLabel;
|
---|
13 | import javax.swing.JPanel;
|
---|
14 |
|
---|
15 | import org.openstreetmap.josm.data.Bounds;
|
---|
16 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
17 | import org.openstreetmap.josm.data.projection.datum.Datum;
|
---|
18 | import org.openstreetmap.josm.data.projection.datum.GRS80Datum;
|
---|
19 | import org.openstreetmap.josm.data.projection.datum.SevenParameterDatum;
|
---|
20 | import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum;
|
---|
21 | import org.openstreetmap.josm.data.projection.proj.ProjParameters;
|
---|
22 | import org.openstreetmap.josm.tools.GBC;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * This class implements all projections for French departements in the Caribbean Sea and
|
---|
26 | * Indian Ocean using the UTM transvers Mercator projection and specific geodesic settings.
|
---|
27 | *
|
---|
28 | */
|
---|
29 | public class UTM_France_DOM extends AbstractProjection implements ProjectionSubPrefs {
|
---|
30 |
|
---|
31 | private final static String FortMarigotName = tr("Guadeloupe Fort-Marigot 1949");
|
---|
32 | private final static String SainteAnneName = tr("Guadeloupe Ste-Anne 1948");
|
---|
33 | private final static String MartiniqueName = tr("Martinique Fort Desaix 1952");
|
---|
34 | private final static String Reunion92Name = tr("Reunion RGR92");
|
---|
35 | private final static String Guyane92Name = tr("Guyane RGFG95");
|
---|
36 | private final static String[] utmGeodesicsNames = { FortMarigotName, SainteAnneName, MartiniqueName, Reunion92Name, Guyane92Name};
|
---|
37 |
|
---|
38 | private final static Bounds FortMarigotBounds = new Bounds( new LatLon(17.6,-63.25), new LatLon(18.5,-62.5));
|
---|
39 | private final static Bounds SainteAnneBounds = new Bounds( new LatLon(15.8,-61.9), new LatLon(16.6,-60.9));
|
---|
40 | private final static Bounds MartiniqueBounds = new Bounds( new LatLon(14.25,-61.25), new LatLon(15.025,-60.725));
|
---|
41 | private final static Bounds ReunionBounds = new Bounds( new LatLon(-25.92,37.58), new LatLon(-10.6, 58.27));
|
---|
42 | private final static Bounds GuyaneBounds = new Bounds( new LatLon(2.16 , -54.0), new LatLon(9.06 , -49.62));
|
---|
43 | private final static Bounds[] utmBounds = { FortMarigotBounds, SainteAnneBounds, MartiniqueBounds, ReunionBounds, GuyaneBounds };
|
---|
44 |
|
---|
45 | private final static Integer FortMarigotEPSG = 2969;
|
---|
46 | private final static Integer SainteAnneEPSG = 2970;
|
---|
47 | private final static Integer MartiniqueEPSG = 2973;
|
---|
48 | private final static Integer ReunionEPSG = 2975;
|
---|
49 | private final static Integer GuyaneEPSG = 2972;
|
---|
50 | private final static Integer[] utmEPSGs = { FortMarigotEPSG, SainteAnneEPSG, MartiniqueEPSG, ReunionEPSG, GuyaneEPSG };
|
---|
51 |
|
---|
52 | private final static Datum FortMarigotDatum = new ThreeParameterDatum("FortMarigot Datum", null, Ellipsoid.hayford, 136.596, 248.148, -429.789);
|
---|
53 | private final static Datum SainteAnneDatum = new SevenParameterDatum("SainteAnne Datum", null, Ellipsoid.hayford, -472.29, -5.63, -304.12, 0.4362, -0.8374, 0.2563, 1.8984);
|
---|
54 | private final static Datum MartiniqueDatum = new SevenParameterDatum("Martinique Datum", null, Ellipsoid.hayford, 126.926, 547.939, 130.409, -2.78670, 5.16124, -0.85844, 13.82265);
|
---|
55 | private final static Datum ReunionDatum = GRS80Datum.INSTANCE;
|
---|
56 | private final static Datum GuyaneDatum = GRS80Datum.INSTANCE;
|
---|
57 | private final static Datum[] utmDatums = { FortMarigotDatum, SainteAnneDatum, MartiniqueDatum, ReunionDatum, GuyaneDatum };
|
---|
58 |
|
---|
59 | private final static int[] utmZones = { 20, 20, 20, 40, 22 };
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * UTM zone (from 1 to 60)
|
---|
63 | */
|
---|
64 | private static int zone;
|
---|
65 | /**
|
---|
66 | * whether north or south hemisphere
|
---|
67 | */
|
---|
68 | private boolean isNorth;
|
---|
69 |
|
---|
70 | public static final int DEFAULT_GEODESIC = 0;
|
---|
71 |
|
---|
72 | public int currentGeodesic;
|
---|
73 |
|
---|
74 |
|
---|
75 | public UTM_France_DOM() {
|
---|
76 | updateParameters(DEFAULT_GEODESIC);
|
---|
77 | }
|
---|
78 |
|
---|
79 | public void updateParameters(int currentGeodesic) {
|
---|
80 | this.currentGeodesic = currentGeodesic;
|
---|
81 | datum = utmDatums[currentGeodesic];
|
---|
82 | ellps = datum.getEllipsoid();
|
---|
83 | proj = new org.openstreetmap.josm.data.projection.proj.TransverseMercator();
|
---|
84 | try {
|
---|
85 | proj.initialize(new ProjParameters() {{ ellps = UTM_France_DOM.this.ellps; }});
|
---|
86 | } catch (ProjectionConfigurationException e) {
|
---|
87 | throw new RuntimeException(e);
|
---|
88 | }
|
---|
89 | isNorth = currentGeodesic != 3;
|
---|
90 | zone = utmZones[currentGeodesic];
|
---|
91 | x_0 = 500000;
|
---|
92 | y_0 = isNorth ? 0.0 : 10000000.0;
|
---|
93 | lon_0 = 6 * zone - 183;
|
---|
94 | k_0 = 0.9996;
|
---|
95 | }
|
---|
96 |
|
---|
97 | public int getCurrentGeodesic() {
|
---|
98 | return currentGeodesic;
|
---|
99 | }
|
---|
100 |
|
---|
101 | @Override
|
---|
102 | public String toString() {
|
---|
103 | return tr("UTM France (DOM)");
|
---|
104 | }
|
---|
105 |
|
---|
106 | @Override
|
---|
107 | public String getCacheDirectoryName() {
|
---|
108 | return this.toString();
|
---|
109 | }
|
---|
110 |
|
---|
111 | @Override
|
---|
112 | public Bounds getWorldBoundsLatLon() {
|
---|
113 | return utmBounds[currentGeodesic];
|
---|
114 | }
|
---|
115 |
|
---|
116 | @Override
|
---|
117 | public Integer getEpsgCode() {
|
---|
118 | return utmEPSGs[currentGeodesic];
|
---|
119 | }
|
---|
120 |
|
---|
121 | @Override
|
---|
122 | public int hashCode() {
|
---|
123 | return getClass().getName().hashCode()+currentGeodesic; // our only real variable
|
---|
124 | }
|
---|
125 |
|
---|
126 | @Override
|
---|
127 | public void setupPreferencePanel(JPanel p, ActionListener listener) {
|
---|
128 | JComboBox prefcb = new JComboBox(utmGeodesicsNames);
|
---|
129 |
|
---|
130 | prefcb.setSelectedIndex(currentGeodesic);
|
---|
131 | p.setLayout(new GridBagLayout());
|
---|
132 | p.add(new JLabel(tr("UTM Geodesic system")), GBC.std().insets(5,5,0,5));
|
---|
133 | p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
|
---|
134 | p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
|
---|
135 | p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
|
---|
136 | if (listener != null) {
|
---|
137 | prefcb.addActionListener(listener);
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | @Override
|
---|
142 | public Collection<String> getPreferences(JPanel p) {
|
---|
143 | Object prefcb = p.getComponent(2);
|
---|
144 | if(!(prefcb instanceof JComboBox))
|
---|
145 | return null;
|
---|
146 | currentGeodesic = ((JComboBox)prefcb).getSelectedIndex();
|
---|
147 | return Collections.singleton(Integer.toString(currentGeodesic+1));
|
---|
148 | }
|
---|
149 |
|
---|
150 | @Override
|
---|
151 | public String[] allCodes() {
|
---|
152 | String[] res = new String[utmEPSGs.length];
|
---|
153 | for (int i=0; i<utmEPSGs.length; ++i) {
|
---|
154 | res[i] = "EPSG:"+utmEPSGs[i];
|
---|
155 | }
|
---|
156 | return res;
|
---|
157 | }
|
---|
158 |
|
---|
159 | @Override
|
---|
160 | public Collection<String> getPreferencesFromCode(String code) {
|
---|
161 | for (int i=0; i < utmEPSGs.length; i++ )
|
---|
162 | if (("EPSG:"+utmEPSGs[i]).equals(code))
|
---|
163 | return Collections.singleton(Integer.toString(i+1));
|
---|
164 | return null;
|
---|
165 | }
|
---|
166 |
|
---|
167 | @Override
|
---|
168 | public void setPreferences(Collection<String> args) {
|
---|
169 | int currentGeodesic = DEFAULT_GEODESIC;
|
---|
170 | if (args != null) {
|
---|
171 | try {
|
---|
172 | for(String s : args)
|
---|
173 | {
|
---|
174 | currentGeodesic = Integer.parseInt(s)-1;
|
---|
175 | if(currentGeodesic < 0 || currentGeodesic >= utmEPSGs.length) {
|
---|
176 | currentGeodesic = DEFAULT_GEODESIC;
|
---|
177 | }
|
---|
178 | break;
|
---|
179 | }
|
---|
180 | } catch(NumberFormatException e) {}
|
---|
181 | }
|
---|
182 | updateParameters(currentGeodesic);
|
---|
183 | }
|
---|
184 | }
|
---|