Changeset 5548 in josm for trunk/src/org/openstreetmap/josm/data/projection
- Timestamp:
- 2012-11-01T16:52:19+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/projection
- Files:
-
- 15 deleted
- 3 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 to convert lat/lon values 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) {
Note:
See TracChangeset
for help on using the changeset viewer.