Changeset 5548 in josm
- Timestamp:
- 2012-11-01T16:52:19+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 15 deleted
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r5279 r5548 21 21 import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum; 22 22 import org.openstreetmap.josm.data.projection.datum.WGS84Datum; 23 import org.openstreetmap.josm.data.projection.proj.Mercator; 23 24 import org.openstreetmap.josm.data.projection.proj.Proj; 24 25 import org.openstreetmap.josm.data.projection.proj.ProjParameters; … … 38 39 */ 39 40 protected String pref; 41 protected String name; 42 protected String code; 43 protected String cacheDir; 40 44 protected Bounds bounds; 41 45 … … 83 87 84 88 public CustomProjection() { 85 this.pref = null;86 89 } 87 90 88 91 public CustomProjection(String pref) { 92 this(null, null, pref, null); 93 } 94 95 /** 96 * Constructor. 97 * 98 * @param name describe projection in one or two words 99 * @param code unique code for this projection - may be null 100 * @param pref the string that defines the custom projection 101 * @param cacheDir cache directory name 102 */ 103 public CustomProjection(String name, String code, String pref, String cacheDir) { 104 this.name = name; 105 this.code = code; 106 this.pref = pref; 107 this.cacheDir = cacheDir; 89 108 try { 90 this.pref = pref;91 109 update(pref); 92 110 } catch (ProjectionConfigurationException ex) { … … 104 122 ellps = Ellipsoid.WGS84; 105 123 datum = WGS84Datum.INSTANCE; 106 proj = new org.openstreetmap.josm.data.projection.proj.Mercator();124 proj = new Mercator(); 107 125 bounds = new Bounds( 108 126 new LatLon(-85.05112877980659, -180.0), … … 429 447 @Override 430 448 public Integer getEpsgCode() { 449 if (code != null && code.startsWith("EPSG:")) { 450 try { 451 return Integer.parseInt(code.substring(5)); 452 } catch (NumberFormatException e) {} 453 } 431 454 return null; 432 455 } … … 434 457 @Override 435 458 public String toCode() { 436 return "proj:" + (pref == null ? "ERROR" : pref); 459 return code != null ? code : "proj:" + (pref == null ? "ERROR" : pref); 437 460 } 438 461 439 462 @Override 440 463 public String getCacheDirectoryName() { 441 return "proj-"+Utils.md5Hex(pref == null ? "" : pref).substring(0, 4); 464 return cacheDir != null ? cacheDir : "proj-"+Utils.md5Hex(pref == null ? "" : pref).substring(0, 4); 442 465 } 443 466 … … 452 475 @Override 453 476 public String toString() { 454 return tr("Custom Projection"); 477 return name != null ? name : tr("Custom Projection"); 455 478 } 456 479 } -
trunk/src/org/openstreetmap/josm/data/projection/Projection.java
r5266 r5548 1 // License: GPL. Copyright 2007 by Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.data.projection; 3 3 … … 7 7 8 8 /** 9 * Classes implementing this are able toconvertlat/lonvalues to10 * planar screen coordinates.9 * A projection, i.e. a class that supports conversion from lat/lon 10 * to east/north and back. 11 11 * 12 * @author imi 12 * The conversion from east/north to the screen coordinates is simply a scale 13 * factor and x/y offset. 13 14 */ 14 15 public interface Projection { 15 16 /** 16 * The default scale factor in east/north units per pixel ({@link #NavigatableComponent#scale})) 17 * The default scale factor in east/north units per pixel ({@link #NavigatableComponent#scale})). 17 18 * FIXME: misnomer 19 * @return the scale factor 18 20 */ 19 21 double getDefaultZoomInPPD(); 20 22 21 23 /** 22 * Convert from lat/lon to northing/easting.24 * Convert from lat/lon to easting/northing. 23 25 * 24 * @param p The geo point to convert. x/y members of the point are filled. 26 * @param ll the geographical point to convert (in WGS84 lat/lon) 27 * @return the corresponding east/north coordinates 25 28 */ 26 EastNorth latlon2eastNorth(LatLon p);29 EastNorth latlon2eastNorth(LatLon ll); 27 30 28 31 /** 29 * Convert from norting/easting to lat/lon.32 * Convert from easting/norting to lat/lon. 30 33 * 31 * @param p The geo point to convert. lat/lon members of the point are filled. 34 * @param en the geographical point to convert (in projected coordinates) 35 * @return the corresponding lat/lon (WGS84) 32 36 */ 33 LatLon eastNorth2latlon(EastNorth p);37 LatLon eastNorth2latlon(EastNorth en); 34 38 35 39 /** 36 * Describe the projection converter in one or two words. 40 * Describe the projection in one or two words. 41 * @return the name / description 37 42 */ 38 43 String toString(); 39 44 40 45 /** 41 * Return projection code. This should be a unique identifier. 46 * Return projection code. 47 * 48 * This should be a unique identifier. 42 49 * If projection supports parameters, return a different code 43 50 * for each set of parameters. 44 51 * 45 52 * The EPSG code can be used (if defined for the projection). 53 * 54 * @return the projection identifier 46 55 */ 47 56 String toCode(); 48 57 49 58 /** 50 * Get a filename compatible string (for the cache directory) 59 * Get a filename compatible string (for the cache directory). 60 * @return the cache directory name (base name) 51 61 */ 52 62 String getCacheDirectoryName(); 53 63 54 64 /** 55 * Get the bounds of the world 65 * Get the bounds of the world. 66 * @return the supported lat/lon rectangle for this projection 56 67 */ 57 68 Bounds getWorldBoundsLatLon(); -
trunk/src/org/openstreetmap/josm/data/projection/Projections.java
r5237 r5548 25 25 import org.openstreetmap.josm.data.projection.proj.TransverseMercator; 26 26 import org.openstreetmap.josm.io.MirroredInputStream; 27 import org.openstreetmap.josm.tools.Pair; 27 28 28 29 /** … … 47 48 * should be compatible to PROJ.4 48 49 */ 49 public static Map<String, ProjFactory> projs = new HashMap<String, ProjFactory>(); 50 public static Map<String, Ellipsoid> ellipsoids = new HashMap<String, Ellipsoid>(); 51 public static Map<String, Datum> datums = new HashMap<String, Datum>(); 52 public static Map<String, NTV2GridShiftFileWrapper> nadgrids = new HashMap<String, NTV2GridShiftFileWrapper>(); 53 public static Map<String, String> inits = new HashMap<String,String>();50 final public static Map<String, ProjFactory> projs = new HashMap<String, ProjFactory>(); 51 final public static Map<String, Ellipsoid> ellipsoids = new HashMap<String, Ellipsoid>(); 52 final public static Map<String, Datum> datums = new HashMap<String, Datum>(); 53 final public static Map<String, NTV2GridShiftFileWrapper> nadgrids = new HashMap<String, NTV2GridShiftFileWrapper>(); 54 final public static Map<String, Pair<String, String>> inits = new HashMap<String, Pair<String, String>>(); 54 55 55 56 static { … … 109 110 110 111 public static String getInit(String id) { 111 return inits.get(id );112 return inits.get(id.toLowerCase()).b; 112 113 } 113 114 … … 116 117 */ 117 118 private static void loadInits() { 118 Pattern epsgPattern = Pattern.compile(" \\A<(\\d+)>(.*)<>\\Z");119 Pattern epsgPattern = Pattern.compile("<(\\d+)>(.*)<>"); 119 120 try { 120 121 InputStream in = new MirroredInputStream("resource://data/epsg"); 121 122 BufferedReader r = new BufferedReader(new InputStreamReader(in)); 122 String line; 123 String line, lastline = ""; 123 124 while ((line = r.readLine()) != null) { 124 125 line = line.trim(); 125 126 if (!line.startsWith("#") && !line.isEmpty()) { 127 if (!lastline.startsWith("#")) throw new AssertionError(); 128 String name = lastline.substring(1).trim(); 126 129 Matcher m = epsgPattern.matcher(line); 127 130 if (m.matches()) { 128 inits.put("epsg:" + m.group(1), m.group(2).trim()); 131 inits.put("epsg:" + m.group(1), Pair.create(name, m.group(2).trim())); 129 132 } else { 130 133 System.err.println("Warning: failed to parse line from the epsg projection definition: "+line); 131 134 } 132 135 } 136 lastline = line; 133 137 } 134 138 } catch (IOException ex) { -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r5547 r5548 12 12 import java.io.PrintWriter; 13 13 import java.util.ArrayList; 14 import java.util.Arrays; 14 15 import java.util.Collection; 15 16 import java.util.HashMap; … … 23 24 import org.openstreetmap.josm.Main; 24 25 import org.openstreetmap.josm.actions.ValidateAction; 25 import org.openstreetmap.josm.data.projection.Epsg4326;26 import org.openstreetmap.josm.data.projection.Lambert;27 import org.openstreetmap.josm.data.projection.Mercator;28 26 import org.openstreetmap.josm.data.validation.tests.BuildingInBuilding; 29 27 import org.openstreetmap.josm.data.validation.tests.Coastlines; … … 57 55 import org.openstreetmap.josm.gui.layer.ValidatorLayer; 58 56 import org.openstreetmap.josm.gui.preferences.ValidatorPreference; 57 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 59 58 60 59 /** … … 253 252 */ 254 253 public void initializeGridDetail() { 255 if (Main.getProjection().toString().equals(new Epsg4326().toString())) { 254 String code = Main.getProjection().toCode(); 255 if (Arrays.asList(ProjectionPreference.wgs84.allCodes()).contains(code)) { 256 256 OsmValidator.griddetail = 10000; 257 } else if ( Main.getProjection().toString().equals(new Mercator().toString())) {257 } else if (Arrays.asList(ProjectionPreference.mercator.allCodes()).contains(code)) { 258 258 OsmValidator.griddetail = 0.01; 259 } else if ( Main.getProjection().toString().equals(new Lambert().toString())) {259 } else if (Arrays.asList(ProjectionPreference.lambert.allCodes()).contains(code)) { 260 260 OsmValidator.griddetail = 0.1; 261 261 } else { -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/AbstractProjectionChoice.java
r5234 r5548 2 2 package org.openstreetmap.josm.gui.preferences.projection; 3 3 4 import org.openstreetmap.josm.data.projection.CustomProjection; 5 import org.openstreetmap.josm.data.projection.Projection; 6 import org.openstreetmap.josm.data.projection.Projections; 7 4 8 abstract public class AbstractProjectionChoice implements ProjectionChoice { 5 private String id; 6 private String name; 9 10 protected String name; 11 protected String id; 12 protected String cacheDir; 7 13 8 public AbstractProjectionChoice(String id, String name) { 14 /** 15 * Constructor. 16 * 17 * @param name short name of the projection choice as shown in the GUI 18 * @param id unique identifier for the projection choice 19 * @param cacheDir a cache directory name 20 */ 21 public AbstractProjectionChoice(String name, String id, String cacheDir) { 22 this.name = name; 9 23 this.id = id; 10 this. name = name;24 this.cacheDir = cacheDir; 11 25 } 26 27 /** 28 * Constructor (without cacheDir argument). 29 * 30 * Only for core projection choices, where chacheDir is the same as 31 * the second part of the id. 32 */ 33 public AbstractProjectionChoice(String name, String id) { 34 this(name, id, null); 35 if (!id.startsWith("core:")) throw new IllegalArgumentException(); 36 this.cacheDir = id.substring(5); 37 } 38 12 39 @Override 13 40 public String getId() { 14 41 return id; 15 42 } 16 43 44 public String getCacheDir() { 45 return cacheDir; 46 } 47 17 48 @Override 18 49 public String toString() { … … 20 51 } 21 52 53 abstract public String getCurrentCode(); 54 55 abstract public String getProjectionName(); 56 57 @Override 58 public Projection getProjection() { 59 String code = getCurrentCode(); 60 String pref = Projections.getInit(code); 61 if (pref == null) 62 throw new AssertionError("Error: Unkown projection code"); 63 return new CustomProjection(getProjectionName(), code, pref, getCacheDir()); 64 } 65 22 66 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/CustomProjectionChoice.java
r5546 r5548 43 43 44 44 public CustomProjectionChoice() { 45 super( "core:custom",tr("Custom Projection"));45 super(tr("Custom Projection"), "core:custom"); 46 46 } 47 47 … … 207 207 208 208 @Override 209 public String getCurrentCode() { 210 // not needed - getProjection() is overridden 211 throw new UnsupportedOperationException(); 212 } 213 214 @Override 215 public String getProjectionName() { 216 // not needed - getProjection() is overridden 217 throw new UnsupportedOperationException(); 218 } 219 220 @Override 209 221 public JPanel getPreferencePanel(ActionListener listener) { 210 222 return new PreferencePanel(pref, listener); -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/GaussKruegerProjectionChoice.java
r5546 r5548 7 7 import java.util.Collections; 8 8 9 import org.openstreetmap.josm.data.projection.GaussKrueger;10 import org.openstreetmap.josm.data.projection.Projection;11 12 9 public class GaussKruegerProjectionChoice extends ListProjectionChoice { 13 10 … … 15 12 16 13 public GaussKruegerProjectionChoice() { 17 super( "core:gauss-krueger",tr("Gau\u00DF-Kr\u00FCger"), zones, tr("GK Zone"));14 super(tr("Gau\u00DF-Kr\u00FCger"), "core:gauss-krueger", zones, tr("GK Zone")); 18 15 } 19 16 20 17 @Override 21 public Projection getProjection() {22 return new GaussKrueger(index + 2);18 public String getCurrentCode() { 19 return "EPSG:"+Integer.toString(31466 + index); 23 20 } 24 21 … … 57 54 } 58 55 56 @Override 57 public String getProjectionName() { 58 return tr("Gau\u00DF-Kr\u00FCger Zone {0}", index + 2); 59 } 60 59 61 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertCC9ZonesProjectionChoice.java
r5546 r5548 11 11 import javax.swing.JPanel; 12 12 13 import org.openstreetmap.josm.data.projection.LambertCC9Zones;14 import org.openstreetmap.josm.data.projection.Projection;15 13 import org.openstreetmap.josm.tools.GBC; 16 14 import org.openstreetmap.josm.tools.ImageProvider; … … 31 29 32 30 public LambertCC9ZonesProjectionChoice() { 33 super( "core:lambertcc9",tr("Lambert CC9 Zone (France)"), lambert9zones, tr("Lambert CC Zone"));31 super(tr("Lambert CC9 Zone (France)"), "core:lambertcc9", lambert9zones, tr("Lambert CC Zone")); 34 32 } 35 33 … … 48 46 49 47 @Override 50 public Projection getProjection() { 51 return new LambertCC9Zones(index); 48 public String getCurrentCode() { 49 return "EPSG:" + Integer.toString(3942+index); //CC42 is EPSG:3942 (up to EPSG:3950 for CC50) 50 } 51 52 @Override 53 public String getProjectionName() { 54 return tr("Lambert CC9 Zone (France)"); 52 55 } 53 56 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertProjectionChoice.java
r5546 r5548 11 11 import javax.swing.JPanel; 12 12 13 import org.openstreetmap.josm.data.projection.Lambert;14 import org.openstreetmap.josm.data.projection.Projection;15 13 import org.openstreetmap.josm.tools.GBC; 16 14 import org.openstreetmap.josm.tools.ImageProvider; … … 26 24 27 25 public LambertProjectionChoice() { 28 super( "core:lambert",tr("Lambert 4 Zones (France)"), lambert4zones, tr("Lambert CC Zone"));26 super(tr("Lambert 4 Zones (France)"), "core:lambert", lambert4zones, tr("Lambert CC Zone")); 29 27 } 30 28 … … 43 41 44 42 @Override 45 public Projection getProjection() { 46 return new Lambert(index); 43 public String getCurrentCode() { 44 return "EPSG:" + Integer.toString(27561+index); 45 } 46 47 @Override 48 public String getProjectionName() { 49 return tr("Lambert 4 Zones (France)"); 47 50 } 48 51 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ListProjectionChoice.java
r5429 r5548 18 18 abstract public class ListProjectionChoice extends AbstractProjectionChoice { 19 19 20 protected int index; 20 protected int index; // 0-based index 21 21 protected int defaultIndex; 22 22 protected Object[] entries; 23 23 protected String label; 24 24 25 public ListProjectionChoice(String id, String name, Object[] entries, String label) {26 this(id, name, entries, label, 0);27 }28 29 25 /** 30 26 * Constructor 31 27 * 28 * @param name the display name 32 29 * @param id the unique id for this ProjectionChoice 33 * @param name the display name34 30 * @param entries the list of display entries for the combo-box 35 31 * @param label a label shown left to the combo-box 36 32 * @param defaultIndex the default index for the combo-box 37 33 */ 38 public ListProjectionChoice(String id, Stringname, Object[] entries, String label, int defaultIndex) {39 super( id, name);34 public ListProjectionChoice(String name, String id, Object[] entries, String label, int defaultIndex) { 35 super(name, id); 40 36 this.entries = entries; 41 37 this.label = label; 42 38 this.defaultIndex = defaultIndex; 39 } 40 41 public ListProjectionChoice(String name, String id, Object[] entries, String label) { 42 this(name, id, entries, label, 0); 43 43 } 44 44 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionChoice.java
r5234 r5548 18 18 /** 19 19 * Get a unique id for the projection choice. 20 * 21 * Will be used to save the user selection to the preference file. 22 * 23 * @return the string identifier 20 24 */ 21 25 String getId(); … … 27 31 * listener from getPreferencePanel is invoked. 28 32 * 29 * Argument may be null to reset everything. 33 * @param args preferences as a list of strings; may be null 34 * to reset everything. 30 35 */ 31 36 void setPreferences(Collection<String> args); … … 56 61 57 62 /** 58 * Return all projection codes supported by this projection c lass.63 * Return all projection codes supported by this projection choice. 59 64 */ 60 65 String[] allCodes(); … … 69 74 Collection<String> getPreferencesFromCode(String code); 70 75 76 /** 77 * Short name of the projection choice as shown in the GUI (combo box). 78 * 79 * @return the name 80 */ 81 String toString(); 82 71 83 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java
r5546 r5548 27 27 import org.openstreetmap.josm.data.preferences.CollectionProperty; 28 28 import org.openstreetmap.josm.data.preferences.StringProperty; 29 import org.openstreetmap.josm.data.projection.BelgianLambert1972; 30 import org.openstreetmap.josm.data.projection.BelgianLambert2008; 31 import org.openstreetmap.josm.data.projection.Epsg3008; 32 import org.openstreetmap.josm.data.projection.Epsg4326; 33 import org.openstreetmap.josm.data.projection.Lambert93; 34 import org.openstreetmap.josm.data.projection.LambertEST; 35 import org.openstreetmap.josm.data.projection.Mercator; 29 import org.openstreetmap.josm.data.projection.CustomProjection; 36 30 import org.openstreetmap.josm.data.projection.Projection; 37 import org.openstreetmap.josm.data.projection.TransverseMercatorLV;38 31 import org.openstreetmap.josm.gui.NavigatableComponent; 39 32 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; … … 45 38 import org.openstreetmap.josm.tools.GBC; 46 39 40 /** 41 * Projection preferences. 42 * 43 * How to add new Projections: 44 * - Find EPSG code for the projection. 45 * - Look up the parameter string for Proj4, e.g. on http://spatialreference.org/ 46 * and add it to the file 'data/epsg' in JOSM trunk 47 * - Search for official references and verify the parameter values. These 48 * documents are often available in the local language only. 49 * - Use {@link #registerProjectionChoice()}, to make the entry known to JOSM. 50 * 51 * In case there is no EPSG code: 52 * - override {@link AbstractProjectionChoice#getProjection()} and provide 53 * a manual implementation of the projection. Use {@link CustomProjection} 54 * if possible. 55 */ 47 56 public class ProjectionPreference implements SubPreferenceSetting { 48 57 … … 56 65 private static Map<String, ProjectionChoice> projectionChoicesById = new HashMap<String, ProjectionChoice>(); 57 66 58 public static ProjectionChoice mercator = new SingleProjectionChoice("core:mercator", new Mercator()); 67 public static final ProjectionChoice wgs84; 68 public static final ProjectionChoice mercator; 69 public static final ProjectionChoice lambert; 59 70 static { 60 // global projections 61 registerProjectionChoice("core:wgs84", new Epsg4326()); 62 registerProjectionChoice(mercator); 71 72 /************************ 73 * Global projections. 74 */ 75 76 /** 77 * WGS84: Directly use latitude / longitude values as x/y. 78 */ 79 wgs84 = registerProjectionChoice(tr("WGS84 Geographic"), "core:wgs84", 4326, "epsg4326"); 80 81 /** 82 * Mercator Projection. 83 * 84 * The center of the mercator projection is always the 0 grad 85 * coordinate. 86 * 87 * See also USGS Bulletin 1532 88 * (http://egsc.usgs.gov/isb/pubs/factsheets/fs08799.html) 89 * initially EPSG used 3785 but that has been superseded by 3857, 90 * see http://www.epsg-registry.org/ 91 */ 92 mercator = registerProjectionChoice(tr("Mercator"), "core:mercator", 93 3857); 94 95 /** 96 * UTM. 97 */ 63 98 registerProjectionChoice(new UTMProjectionChoice()); 64 // regional - alphabetical order by country code 65 registerProjectionChoice("core:belambert1972", new BelgianLambert1972()); // BE 66 registerProjectionChoice("core:belambert2008", new BelgianLambert2008()); // BE 67 registerProjectionChoice(new SwissGridProjectionChoice()); // CH 68 registerProjectionChoice(new GaussKruegerProjectionChoice()); // DE 69 registerProjectionChoice("core:lambertest", new LambertEST()); // EE 70 registerProjectionChoice(new LambertProjectionChoice()); // FR 71 registerProjectionChoice("core:lambert93", new Lambert93()); // FR 72 registerProjectionChoice(new LambertCC9ZonesProjectionChoice()); // FR 73 registerProjectionChoice(new UTM_France_DOM_ProjectionChoice()); // FR 74 registerProjectionChoice("core:tmerclv", new TransverseMercatorLV()); // LV 75 registerProjectionChoice(new PuwgProjectionChoice()); // PL 76 registerProjectionChoice("core:sweref99", new Epsg3008()); // SE 99 100 /************************ 101 * Regional - alphabetical order by country code. 102 */ 103 104 /** 105 * Belgian Lambert 72 projection. 106 * 107 * As specified by the Belgian IGN in this document: 108 * http://www.ngi.be/Common/Lambert2008/Transformation_Geographic_Lambert_FR.pdf 109 * 110 * @author Don-vip 111 */ 112 registerProjectionChoice(tr("Belgian Lambert 1972"), "core:belgianLambert1972", 31370); // BE 113 /** 114 * Belgian Lambert 2008 projection. 115 * 116 * As specified by the Belgian IGN in this document: 117 * http://www.ngi.be/Common/Lambert2008/Transformation_Geographic_Lambert_FR.pdf 118 * 119 * @author Don-vip 120 */ 121 registerProjectionChoice(tr("Belgian Lambert 2008"), "core:belgianLambert2008", 3812); // BE 122 123 /** 124 * SwissGrid CH1903 / L03, see http://de.wikipedia.org/wiki/Swiss_Grid. 125 * 126 * Actually, what we have here, is CH1903+ (EPSG:2056), but without 127 * the additional false easting of 2000km and false northing 1000 km. 128 * 129 * To get to CH1903, a shift file is required. So currently, there are errors 130 * up to 1.6m (depending on the location). 131 */ 132 registerProjectionChoice(new SwissGridProjectionChoice()); // CH 133 134 registerProjectionChoice(new GaussKruegerProjectionChoice()); // DE 135 136 /** 137 * Estonian Coordinate System of 1997. 138 * 139 * Thanks to Johan Montagnat and its geoconv java converter application 140 * (http://www.i3s.unice.fr/~johan/gps/ , published under GPL license) 141 * from which some code and constants have been reused here. 142 */ 143 registerProjectionChoice(tr("Lambert Zone (Estonia)"), "core:lambertest", 3301); // EE 144 145 /** 146 * Lambert conic conform 4 zones using the French geodetic system NTF. 147 * 148 * This newer version uses the grid translation NTF<->RGF93 provided by IGN for a submillimetric accuracy. 149 * (RGF93 is the French geodetic system similar to WGS84 but not mathematically equal) 150 * 151 * Source: http://professionnels.ign.fr/DISPLAY/000/526/700/5267002/transformation.pdf 152 * @author Pieren 153 */ 154 registerProjectionChoice(lambert = new LambertProjectionChoice()); // FR 155 /** 156 * Lambert 93 projection. 157 * 158 * As specified by the IGN in this document 159 * http://professionnels.ign.fr/DISPLAY/000/526/702/5267026/NTG_87.pdf 160 * @author Don-vip 161 */ 162 registerProjectionChoice(tr("Lambert 93 (France)"), "core:lambert93", 2154); // FR 163 /** 164 * Lambert Conic Conform 9 Zones projection. 165 * 166 * As specified by the IGN in this document 167 * http://professionnels.ign.fr/DISPLAY/000/526/700/5267002/transformation.pdf 168 * @author Pieren 169 */ 170 registerProjectionChoice(new LambertCC9ZonesProjectionChoice()); // FR 171 /** 172 * French departements in the Caribbean Sea and Indian Ocean. 173 * 174 * Using the UTM transvers Mercator projection and specific geodesic settings. 175 */ 176 registerProjectionChoice(new UTM_France_DOM_ProjectionChoice()); // FR 177 178 /** 179 * LKS-92/ Latvia TM projection. 180 * 181 * Based on data from spatialreference.org. 182 * http://spatialreference.org/ref/epsg/3059/ 183 * 184 * @author Viesturs Zarins 185 */ 186 registerProjectionChoice(tr("LKS-92 (Latvia TM)"), "core:tmerclv", 3059); // LV 187 188 /** 189 * PUWG 1992 and 2000 are the official cordinate systems in Poland. 190 * 191 * They use the same math as UTM only with different constants. 192 * 193 * @author steelman 194 */ 195 registerProjectionChoice(new PuwgProjectionChoice()); // PL 196 197 /** 198 * SWEREF99 13 30 projection. Based on data from spatialreference.org. 199 * http://spatialreference.org/ref/epsg/3008/ 200 * 201 * @author Hanno Hecker 202 */ 203 registerProjectionChoice(tr("SWEREF99 13 30 / EPSG:3008 (Sweden)"), "core:sweref99", 3008); // SE 204 205 /************************ 206 * Custom projection. 207 */ 77 208 registerProjectionChoice(new CustomProjectionChoice()); 78 209 } … … 83 214 } 84 215 85 public static void registerProjectionChoice(String id, Projection projection) { 86 registerProjectionChoice(new SingleProjectionChoice(id, projection)); 216 public static ProjectionChoice registerProjectionChoice(String name, String id, Integer epsg, String cacheDir) { 217 ProjectionChoice pc = new SingleProjectionChoice(name, id, "EPSG:"+epsg, cacheDir); 218 registerProjectionChoice(pc); 219 return pc; 220 } 221 222 private static ProjectionChoice registerProjectionChoice(String name, String id, Integer epsg) { 223 ProjectionChoice pc = new SingleProjectionChoice(name, id, "EPSG:"+epsg); 224 registerProjectionChoice(pc); 225 return pc; 87 226 } 88 227 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/PuwgProjectionChoice.java
r5546 r5548 7 7 import java.util.Collections; 8 8 9 import org.openstreetmap.josm.data.projection.Projection;10 import org.openstreetmap.josm.data.projection.Puwg;11 12 9 public class PuwgProjectionChoice extends ListProjectionChoice { 13 10 11 public static final String[] CODES = { 12 "EPSG:2180", 13 "EPSG:2176", 14 "EPSG:2177", 15 "EPSG:2178", 16 "EPSG:2179" 17 }; 18 public static final String[] NAMES = { 19 tr("PUWG 1992 (Poland)"), 20 tr("PUWG 2000 Zone {0} (Poland)", 5), 21 tr("PUWG 2000 Zone {0} (Poland)", 6), 22 tr("PUWG 2000 Zone {0} (Poland)", 7), 23 tr("PUWG 2000 Zone {0} (Poland)", 8) 24 }; 25 14 26 public PuwgProjectionChoice() { 15 super( "core:puwg",tr("PUWG (Poland)"),Puwg.zones, tr("PUWG Zone"));27 super(tr("PUWG (Poland)"), "core:puwg", NAMES, tr("PUWG Zone")); 16 28 } 17 29 18 30 @Override 19 public Projection getProjection() {20 return new Puwg(index);31 public String getCurrentCode() { 32 return CODES[index]; 21 33 } 22 34 23 35 @Override 36 public String getProjectionName() { 37 return NAMES[index]; 38 } 39 40 41 @Override 24 42 public String[] allCodes() { 25 String[] zones = new String[ Puwg.zones.length];26 for (int i ndex = 0; index < Puwg.zones.length; index++) {27 zones[i ndex] = Puwg.zones[index].toCode();43 String[] zones = new String[CODES.length]; 44 for (int idx = 0; idx < CODES.length; idx++) { 45 zones[idx] = CODES[idx]; 28 46 } 29 47 return zones; … … 32 50 @Override 33 51 public Collection<String> getPreferencesFromCode(String code) { 34 for ( Puwg.PuwgData p : Puwg.zones) {35 if (code.equals( p.toCode()))36 return Collections.singleton(code); 52 for (String code2 : CODES) { 53 if (code.equals(code2)) 54 return Collections.singleton(code2); 37 55 } 38 56 return null; … … 41 59 @Override 42 60 protected String indexToZone(int index) { 43 return Puwg.zones[index].toCode();61 return CODES[index]; 44 62 } 45 63 46 64 @Override 47 65 protected int zoneToIndex(String zone) { 48 for (int i=0; i< Puwg.zones.length; i++) {49 if (zone.equals( Puwg.zones[i].toCode())) {66 for (int i=0; i<CODES.length; i++) { 67 if (zone.equals(CODES[i])) { 50 68 return i; 51 69 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/SingleProjectionChoice.java
r5546 r5548 8 8 import javax.swing.JPanel; 9 9 10 import org.openstreetmap.josm.data.projection.Projection;11 12 10 /** 13 11 * ProjectionChoice, that offers just one projection as choice. … … 15 13 * The GUI is an empty panel. 16 14 */ 17 public class SingleProjectionChoice implementsProjectionChoice {15 public class SingleProjectionChoice extends AbstractProjectionChoice { 18 16 19 private String id; 20 private String name; 21 private Projection projection; 17 protected String code; 22 18 23 public SingleProjectionChoice(String id, String name, Projection projection) { 24 this.id = id; 25 this.name = name; 26 this.projection = projection; 19 /** 20 * Constructor. 21 * 22 * @param name short name of the projection choice as shown in the GUI 23 * @param id unique identifier for the projection choice, e.g. "core:thisproj" 24 * @param code the unique identifier for the projection, e.g. "EPSG:1234" 25 * @param cacheDir a cache directory name 26 */ 27 public SingleProjectionChoice(String name, String id, String code, String cacheDir) { 28 super(name, id, cacheDir); 29 this.code = code; 27 30 } 28 31 29 public SingleProjectionChoice(String id, Projection projection) { 30 this(id, projection.toString(), projection); 32 public SingleProjectionChoice(String name, String id, String code) { 33 super(name, id); 34 this.code = code; 31 35 } 32 36 … … 37 41 38 42 @Override 39 public String getId() {40 return id;41 }42 43 @Override44 43 public String[] allCodes() { 45 return new String[] { projection.toCode()};44 return new String[] { code }; 46 45 } 47 46 … … 56 55 57 56 @Override 58 public Projection getProjection() {59 return projection;60 }61 62 @Override63 57 public String toString() { 64 58 return name; … … 67 61 @Override 68 62 public Collection<String> getPreferencesFromCode(String code) { 69 if (code.equals( projection.toCode()))63 if (code.equals(this.code)) 70 64 return Collections.emptyList(); 71 65 else 72 66 return null; 73 67 } 68 69 @Override 70 public String getCurrentCode() { 71 return code; 72 } 73 74 @Override 75 public String getProjectionName() { 76 return name; // the same name as the projection choice 77 } 78 74 79 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/SwissGridProjectionChoice.java
r5234 r5548 10 10 import javax.swing.JPanel; 11 11 12 import org.openstreetmap.josm.data.projection.SwissGrid;13 12 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 14 13 import org.openstreetmap.josm.tools.GBC; … … 17 16 18 17 public SwissGridProjectionChoice() { 19 super( "core:swissgrid",tr("Swiss Grid (Switzerland)"),new SwissGrid());18 super(tr("Swiss Grid (Switzerland)"), "core:swissgrid", "EPSG:21781"); 20 19 } 21 20 -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTMProjectionChoice.java
r5546 r5548 16 16 import javax.swing.JRadioButton; 17 17 18 import org.openstreetmap.josm.data.projection.Projection;19 import org.openstreetmap.josm.data.projection.UTM;20 18 import org.openstreetmap.josm.tools.GBC; 21 19 22 20 public class UTMProjectionChoice extends ListProjectionChoice { 23 21 24 p rivate static final UTM.HemisphereDEFAULT_HEMISPHERE = UTM.Hemisphere.North;22 public enum Hemisphere { North, South } 25 23 26 private UTM.Hemisphere hemisphere; 24 private static final Hemisphere DEFAULT_HEMISPHERE = Hemisphere.North; 25 26 private Hemisphere hemisphere; 27 27 28 28 private final static List<String> cbEntries = new ArrayList<String>(); 29 29 static { 30 30 for (int i = 1; i <= 60; i++) { 31 31 cbEntries.add(Integer.toString(i)); 32 32 } 33 33 } 34 34 35 35 public UTMProjectionChoice() { 36 super("core:utm" , tr("UTM"), cbEntries.toArray(), tr("UTM Zone"));36 super(tr("UTM"), "core:utm", cbEntries.toArray(), tr("UTM Zone")); 37 37 } 38 38 … … 46 46 //Hemisphere 47 47 north = new JRadioButton(); 48 north.setSelected(hemisphere == UTM.Hemisphere.North);48 north.setSelected(hemisphere == Hemisphere.North); 49 49 south = new JRadioButton(); 50 south.setSelected(hemisphere == UTM.Hemisphere.South);50 south.setSelected(hemisphere == Hemisphere.South); 51 51 52 52 ButtonGroup group = new ButtonGroup(); … … 82 82 83 83 @Override 84 public Projection getProjection() { 85 return new UTM(index + 1, hemisphere); 84 public String getCurrentCode() { 85 int zone = index + 1; 86 int code = 32600 + zone + (hemisphere == Hemisphere.South ? 100 : 0); 87 return "EPSG:" + Integer.toString(code); 86 88 } 89 90 @Override 91 public String getProjectionName() { 92 return tr("UTM"); 93 } 94 87 95 88 96 @Override … … 90 98 UTMPanel p = (UTMPanel) panel; 91 99 int index = p.prefcb.getSelectedIndex(); 92 UTM.Hemisphere hemisphere = p.south.isSelected()?UTM.Hemisphere.South:UTM.Hemisphere.North;100 Hemisphere hemisphere = p.south.isSelected()?Hemisphere.South:Hemisphere.North; 93 101 return Arrays.asList(indexToZone(index), hemisphere.toString()); 94 102 } … … 98 106 ArrayList<String> projections = new ArrayList<String>(60*4); 99 107 for (int zone = 1;zone <= 60; zone++) { 100 for ( UTM.Hemisphere hemisphere :UTM.Hemisphere.values()) {101 projections.add("EPSG:" + (32600 + zone + (hemisphere == UTM.Hemisphere.South?100:0)));108 for (Hemisphere hemisphere : Hemisphere.values()) { 109 projections.add("EPSG:" + (32600 + zone + (hemisphere == Hemisphere.South?100:0))); 102 110 } 103 111 } … … 110 118 if (code.startsWith("EPSG:326") || code.startsWith("EPSG:327")) { 111 119 try { 112 UTM.Hemisphere hemisphere = code.charAt(7)=='6'?UTM.Hemisphere.North:UTM.Hemisphere.South;120 Hemisphere hemisphere = code.charAt(7)=='6'?Hemisphere.North:Hemisphere.South; 113 121 String zonestring = code.substring(8); 114 122 int zoneval = Integer.parseInt(zonestring); … … 123 131 public void setPreferences(Collection<String> args) { 124 132 super.setPreferences(args); 125 UTM.Hemisphere hemisphere = DEFAULT_HEMISPHERE;133 Hemisphere hemisphere = DEFAULT_HEMISPHERE; 126 134 127 135 if(args != null) { … … 129 137 130 138 if (array.length > 1) { 131 hemisphere = UTM.Hemisphere.valueOf(array[1]);139 hemisphere = Hemisphere.valueOf(array[1]); 132 140 } 133 141 } -
trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTM_France_DOM_ProjectionChoice.java
r5546 r5548 6 6 import java.util.Collection; 7 7 import java.util.Collections; 8 9 import org.openstreetmap.josm.data.projection.Projection;10 import org.openstreetmap.josm.data.projection.UTM_France_DOM;11 8 12 9 public class UTM_France_DOM_ProjectionChoice extends ListProjectionChoice { … … 19 16 private final static String[] utmGeodesicsNames = { FortMarigotName, SainteAnneName, MartiniqueName, Reunion92Name, Guyane92Name}; 20 17 18 private final static Integer FortMarigotEPSG = 2969; 19 private final static Integer SainteAnneEPSG = 2970; 20 private final static Integer MartiniqueEPSG = 2973; 21 private final static Integer ReunionEPSG = 2975; 22 private final static Integer GuyaneEPSG = 2972; 23 private final static Integer[] utmEPSGs = { FortMarigotEPSG, SainteAnneEPSG, MartiniqueEPSG, ReunionEPSG, GuyaneEPSG }; 24 21 25 public UTM_France_DOM_ProjectionChoice() { 22 super( "core:utmfrancedom",tr("UTM France (DOM)"), utmGeodesicsNames, tr("UTM Geodesic system"));26 super(tr("UTM France (DOM)"), "core:utmfrancedom", utmGeodesicsNames, tr("UTM Geodesic system")); 23 27 } 24 28 … … 37 41 38 42 @Override 39 public Projection getProjection() { 40 return new UTM_France_DOM(index); 43 public String getProjectionName() { 44 return utmGeodesicsNames[index]; 45 } 46 47 @Override 48 public String getCurrentCode() { 49 return "EPSG:" + utmEPSGs[index]; 41 50 } 42 51 43 52 @Override 44 53 public String[] allCodes() { 45 String[] res = new String[ UTM_France_DOM.utmEPSGs.length];46 for (int i=0; i< UTM_France_DOM.utmEPSGs.length; ++i) {47 res[i] = "EPSG:" +UTM_France_DOM.utmEPSGs[i];54 String[] res = new String[utmEPSGs.length]; 55 for (int i=0; i<utmEPSGs.length; ++i) { 56 res[i] = "EPSG:" + utmEPSGs[i]; 48 57 } 49 58 return res; … … 52 61 @Override 53 62 public Collection<String> getPreferencesFromCode(String code) { 54 for (int i=0; i < UTM_France_DOM.utmEPSGs.length; i++ )55 if (("EPSG:" +UTM_France_DOM.utmEPSGs[i]).equals(code))63 for (int i=0; i < utmEPSGs.length; i++ ) 64 if (("EPSG:" + utmEPSGs[i]).equals(code)) 56 65 return Collections.singleton(Integer.toString(i+1)); 57 66 return null;
Note:
See TracChangeset
for help on using the changeset viewer.