source: josm/trunk/src/org/openstreetmap/josm/data/projection/Lambert.java@ 5232

Last change on this file since 5232 was 5230, checked in by bastiK, 12 years ago

use standard parameter set for lambert projection

  • Property svn:eol-style set to native
File size: 7.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.projection;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.GridBagLayout;
7import java.awt.event.ActionListener;
8import java.util.Collection;
9import java.util.Collections;
10
11import javax.swing.JComboBox;
12import javax.swing.JLabel;
13import javax.swing.JPanel;
14
15import org.openstreetmap.josm.data.Bounds;
16import org.openstreetmap.josm.data.coor.LatLon;
17import org.openstreetmap.josm.data.projection.datum.NTV2Datum;
18import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper;
19import org.openstreetmap.josm.data.projection.proj.LambertConformalConic;
20import org.openstreetmap.josm.data.projection.proj.ProjParameters;
21import org.openstreetmap.josm.tools.GBC;
22import org.openstreetmap.josm.tools.ImageProvider;
23
24/**
25 * Lambert conic conform 4 zones using the French geodetic system NTF.
26 * This newer version uses the grid translation NTF<->RGF93 provided by IGN for a submillimetric accuracy.
27 * (RGF93 is the French geodetic system similar to WGS84 but not mathematically equal)
28 *
29 * Source: http://professionnels.ign.fr/DISPLAY/000/526/700/5267002/transformation.pdf
30 * @author Pieren
31 */
32public class Lambert extends AbstractProjection implements ProjectionSubPrefs {
33
34 /**
35 * Lambert I, II, III, and IV latitude origin
36 */
37 private static final double lat_0s[] = { 49.5, 46.8, 44.1, 42.165 };
38
39 /**
40 * Lambert I, II, III, and IV latitude of first standard parallel
41 */
42 private static final double lat_1s[] = {
43 convertDegreeMinuteSecond(48, 35, 54.682),
44 convertDegreeMinuteSecond(45, 53, 56.108),
45 convertDegreeMinuteSecond(43, 11, 57.449),
46 convertDegreeMinuteSecond(41, 33, 37.396)};
47
48 /**
49 * Lambert I, II, III, and IV latitude of second standard parallel
50 */
51 private static final double lat_2s[] = {
52 convertDegreeMinuteSecond(50, 23, 45.282),
53 convertDegreeMinuteSecond(47, 41, 45.652),
54 convertDegreeMinuteSecond(44, 59, 45.938),
55 convertDegreeMinuteSecond(42, 46, 3.588)};
56
57 /**
58 * Lambert I, II, III, and IV false east
59 */
60 private static final double x_0s[] = { 600000.0, 600000.0, 600000.0, 234.358 };
61
62 /**
63 * Lambert I, II, III, and IV false north
64 */
65 private static final double y_0s[] = { 200000.0, 200000.0, 200000.0, 185861.369 };
66
67 /**
68 * France is divided in 4 Lambert projection zones (1,2,3 + 4th for Corsica)
69 */
70 public static final double cMaxLatZone1Radian = Math.toRadians(57 * 0.9);
71 public static final double cMinLatZone1Radian = Math.toRadians(46.1 * 0.9);// lowest latitude of Zone 4 (South Corsica)
72
73 public static final double[][] zoneLimitsDegree = {
74 {Math.toDegrees(cMaxLatZone1Radian), (53.5 * 0.9)}, // Zone 1 (reference values in grad *0.9)
75 {(53.5 * 0.9), (50.5 * 0.9)}, // Zone 2
76 {(50.5 * 0.9), (47.0 * 0.9)}, // Zone 3
77 {(47.51963 * 0.9), Math.toDegrees(cMinLatZone1Radian)} // Zone 4
78 };
79
80 public static final double cMinLonZonesRadian = Math.toRadians(-4.9074074074074059 * 0.9);
81
82 public static final double cMaxLonZonesRadian = Math.toRadians(10.2 * 0.9);
83
84 /**
85 * Allow some extension beyond the theoretical limits
86 */
87 public static final double cMaxOverlappingZonesDegree = 1.5;
88
89 public static final int DEFAULT_ZONE = 0;
90
91 private int layoutZone;
92
93 public Lambert() {
94 updateParameters(DEFAULT_ZONE);
95 }
96
97 private void updateParameters(final int layoutZone) {
98 this.layoutZone = layoutZone;
99 ellps = Ellipsoid.clarkeIGN;
100 datum = new NTV2Datum("ntf_rgf93Grid", null, ellps, NTV2GridShiftFileWrapper.ntf_rgf93);
101 x_0 = x_0s[layoutZone];
102 y_0 = y_0s[layoutZone];
103 lon_0 = 2.0 + 20.0 / 60 + 14.025 / 3600; // 0 grade Paris
104 if (proj == null) {
105 proj = new LambertConformalConic();
106 }
107 proj = new LambertConformalConic();
108 try {
109 proj.initialize(new ProjParameters() {{
110 ellps = Lambert.this.ellps;
111 lat_0 = lat_0s[layoutZone];
112 lat_1 = lat_1s[layoutZone];
113 lat_2 = lat_2s[layoutZone];
114 }});
115 } catch (ProjectionConfigurationException e) {
116 throw new RuntimeException(e);
117 }
118 }
119
120 @Override
121 public String toString() {
122 return tr("Lambert 4 Zones (France)");
123 }
124
125 @Override
126 public Integer getEpsgCode() {
127 return 27561+layoutZone;
128 }
129
130 @Override
131 public int hashCode() {
132 return getClass().getName().hashCode()+layoutZone; // our only real variable
133 }
134
135 @Override
136 public String getCacheDirectoryName() {
137 return "lambert";
138 }
139
140 @Override
141 public Bounds getWorldBoundsLatLon()
142 {
143 Bounds b= new Bounds(
144 new LatLon(Math.max(zoneLimitsDegree[layoutZone][1] - cMaxOverlappingZonesDegree, Math.toDegrees(cMinLatZone1Radian)), Math.toDegrees(cMinLonZonesRadian)),
145 new LatLon(Math.min(zoneLimitsDegree[layoutZone][0] + cMaxOverlappingZonesDegree, Math.toDegrees(cMaxLatZone1Radian)), Math.toDegrees(cMaxLonZonesRadian)));
146 return b;
147 }
148
149 public int getLayoutZone() {
150 return layoutZone;
151 }
152
153 public static String[] lambert4zones = {
154 tr("{0} ({1} to {2} degrees)", 1,"51.30","48.15"),
155 tr("{0} ({1} to {2} degrees)", 2,"48.15","45.45"),
156 tr("{0} ({1} to {2} degrees)", 3,"45.45","42.76"),
157 tr("{0} (Corsica)", 4)
158 };
159
160 @Override
161 public void setupPreferencePanel(JPanel p, ActionListener listener) {
162 JComboBox prefcb = new JComboBox(lambert4zones);
163
164 prefcb.setSelectedIndex(layoutZone);
165 p.setLayout(new GridBagLayout());
166 p.add(new JLabel(tr("Lambert CC Zone")), GBC.std().insets(5,5,0,5));
167 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
168 /* Note: we use component position 2 below to find this again */
169 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
170 p.add(new JLabel(ImageProvider.get("data/projection", "Departements_Lambert4Zones.png")), GBC.eol().fill(GBC.HORIZONTAL));
171 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
172
173 if (listener != null) {
174 prefcb.addActionListener(listener);
175 }
176 }
177
178 @Override
179 public Collection<String> getPreferences(JPanel p) {
180 Object prefcb = p.getComponent(2);
181 if(!(prefcb instanceof JComboBox))
182 return null;
183 layoutZone = ((JComboBox)prefcb).getSelectedIndex();
184 return Collections.singleton(Integer.toString(layoutZone+1));
185 }
186
187 @Override
188 public void setPreferences(Collection<String> args) {
189 int layoutZone = DEFAULT_ZONE;
190 if (args != null) {
191 try {
192 for(String s : args)
193 {
194 layoutZone = Integer.parseInt(s)-1;
195 if(layoutZone < 0 || layoutZone > 3) {
196 layoutZone = DEFAULT_ZONE;
197 }
198 break;
199 }
200 } catch(NumberFormatException e) {}
201 }
202 updateParameters(layoutZone);
203 }
204
205 @Override
206 public String[] allCodes() {
207 String[] zones = new String[4];
208 for (int zone = 0; zone < 4; zone++) {
209 zones[zone] = "EPSG:"+(27561+zone);
210 }
211 return zones;
212 }
213
214 @Override
215 public Collection<String> getPreferencesFromCode(String code) {
216 if (code.startsWith("EPSG:2756") && code.length() == 10) {
217 try {
218 String zonestring = code.substring(9);
219 int zoneval = Integer.parseInt(zonestring);
220 if(zoneval >= 1 && zoneval <= 4)
221 return Collections.singleton(zonestring);
222 } catch(NumberFormatException e) {}
223 }
224 return null;
225 }
226
227}
Note: See TracBrowser for help on using the repository browser.