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