source: josm/trunk/src/org/openstreetmap/josm/data/projection/LambertCC9Zones.java@ 5226

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

Proj parameter refactoring (see #7495)

  • Property svn:eol-style set to native
File size: 6.2 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.GRS80Datum;
18import org.openstreetmap.josm.data.projection.proj.LambertConformalConic;
19import org.openstreetmap.josm.data.projection.proj.ProjParameters;
20import org.openstreetmap.josm.tools.GBC;
21import org.openstreetmap.josm.tools.ImageProvider;
22
23/**
24 * Lambert Conic Conform 9 Zones projection as specified by the IGN
25 * in this document http://professionnels.ign.fr/DISPLAY/000/526/700/5267002/transformation.pdf
26 * @author Pieren
27 *
28 */
29public class LambertCC9Zones extends AbstractProjection implements ProjectionSubPrefs {
30
31 /**
32 * France is divided in 9 Lambert projection zones, CC42 to CC50.
33 */
34 public static final double cMaxLatZonesRadian = Math.toRadians(51.1);
35
36 public static final double cMinLatZonesDegree = 41.0;
37
38 public static final double cMaxOverlappingZones = 1.5;
39
40 public static final int DEFAULT_ZONE = 0;
41
42 private int layoutZone = DEFAULT_ZONE;
43
44 public LambertCC9Zones() {
45 this(DEFAULT_ZONE);
46 }
47
48 public LambertCC9Zones(int layoutZone) {
49 updateParameters(layoutZone);
50 }
51
52 public void updateParameters(final int layoutZone) {
53 ellps = Ellipsoid.GRS80;
54 datum = GRS80Datum.INSTANCE;
55 this.layoutZone = layoutZone;
56 x_0 = 1700000;
57 y_0 = (layoutZone+1) * 1000000 + 200000;
58 lon_0 = 3;
59 if (proj == null) {
60 proj = new LambertConformalConic();
61 }
62 try {
63 proj.initialize(new ProjParameters() {{
64 ellps = LambertCC9Zones.this.ellps;
65 lat_0 = 42.0 + layoutZone;
66 lat_1 = 41.25 + layoutZone;
67 lat_2 = 42.75 + layoutZone;
68 }});
69 } catch (ProjectionConfigurationException e) {
70 throw new RuntimeException(e);
71 }
72 }
73
74 @Override
75 public String toString() {
76 return tr("Lambert CC9 Zone (France)");
77 }
78
79 public static int north2ZoneNumber(double north) {
80 int nz = (int)(north /1000000) - 1;
81 if (nz < 0) return 0;
82 else if (nz > 8) return 8;
83 else return nz;
84 }
85
86 @Override
87 public Integer getEpsgCode() {
88 return 3942+layoutZone; //CC42 is EPSG:3942 (up to EPSG:3950 for CC50)
89 }
90
91 @Override
92 public int hashCode() {
93 return getClass().getName().hashCode()+layoutZone; // our only real variable
94 }
95
96 @Override
97 public String getCacheDirectoryName() {
98 return "lambert";
99 }
100
101 @Override
102 public Bounds getWorldBoundsLatLon()
103 {
104 double medLatZone = cMinLatZonesDegree + (layoutZone+1);
105 return new Bounds(
106 new LatLon(Math.max(medLatZone - 1.0 - cMaxOverlappingZones, cMinLatZonesDegree), -5.5),
107 new LatLon(Math.min(medLatZone + 1.0 + cMaxOverlappingZones, Math.toDegrees(cMaxLatZonesRadian)), 10.2));
108 }
109
110 public int getLayoutZone() {
111 return layoutZone;
112 }
113
114 private static String[] lambert9zones = {
115 tr("{0} ({1} to {2} degrees)", 1,41,43),
116 tr("{0} ({1} to {2} degrees)", 2,42,44),
117 tr("{0} ({1} to {2} degrees)", 3,43,45),
118 tr("{0} ({1} to {2} degrees)", 4,44,46),
119 tr("{0} ({1} to {2} degrees)", 5,45,47),
120 tr("{0} ({1} to {2} degrees)", 6,46,48),
121 tr("{0} ({1} to {2} degrees)", 7,47,49),
122 tr("{0} ({1} to {2} degrees)", 8,48,50),
123 tr("{0} ({1} to {2} degrees)", 9,49,51)
124 };
125
126 @Override
127 public void setupPreferencePanel(JPanel p, ActionListener listener) {
128 JComboBox prefcb = new JComboBox(lambert9zones);
129
130 prefcb.setSelectedIndex(layoutZone);
131 p.setLayout(new GridBagLayout());
132 p.add(new JLabel(tr("Lambert CC Zone")), GBC.std().insets(5,5,0,5));
133 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
134 /* Note: we use component position 2 below to find this again */
135 p.add(prefcb, GBC.eop().fill(GBC.HORIZONTAL));
136 p.add(new JLabel(ImageProvider.get("data/projection", "LambertCC9Zones.png")), GBC.eol().fill(GBC.HORIZONTAL));
137 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
138
139 if (listener != null) {
140 prefcb.addActionListener(listener);
141 }
142 }
143
144 @Override
145 public Collection<String> getPreferences(JPanel p) {
146 Object prefcb = p.getComponent(2);
147 if(!(prefcb instanceof JComboBox))
148 return null;
149 int layoutZone = ((JComboBox)prefcb).getSelectedIndex();
150 return Collections.singleton(Integer.toString(layoutZone+1));
151 }
152
153 @Override
154 public void setPreferences(Collection<String> args) {
155 int layoutZone = DEFAULT_ZONE;
156 if (args != null) {
157 try {
158 for(String s : args)
159 {
160 layoutZone = Integer.parseInt(s)-1;
161 if(layoutZone < 0 || layoutZone > 8) {
162 layoutZone = DEFAULT_ZONE;
163 }
164 break;
165 }
166 } catch(NumberFormatException e) {}
167 }
168 updateParameters(layoutZone);
169 }
170
171 @Override
172 public String[] allCodes() {
173 String[] zones = new String[9];
174 for (int zone = 0; zone < 9; zone++) {
175 zones[zone] = "EPSG:" + (3942 + zone);
176 }
177 return zones;
178 }
179
180 @Override
181 public Collection<String> getPreferencesFromCode(String code)
182 {
183 //zone 1=CC42=EPSG:3942 up to zone 9=CC50=EPSG:3950
184 if (code.startsWith("EPSG:39") && code.length() == 9) {
185 try {
186 String zonestring = code.substring(5,9);
187 int zoneval = Integer.parseInt(zonestring)-3942;
188 if(zoneval >= 0 && zoneval <= 8)
189 return Collections.singleton(String.valueOf(zoneval+1));
190 } catch(NumberFormatException ex) {}
191 }
192 return null;
193 }
194}
Note: See TracBrowser for help on using the repository browser.