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

Last change on this file since 4382 was 4382, checked in by bastiK, 13 years ago

applied #6753 - enhance project Lambert CC 9 zones (patch by pieren)

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