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

Last change on this file since 5228 was 5226, checked in by bastiK, 12 years ago

improvements for custom projection

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