Changeset 9790 in josm for trunk/src/org/openstreetmap/josm/data
- Timestamp:
- 2016-02-12T14:31:47+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/projection
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java
r9558 r9790 28 28 protected Datum datum; 29 29 protected Proj proj; 30 protected double x0; /* false easting (in meters) */ 31 protected double y0; /* false northing (in meters) */ 32 protected double lon0; /* central meridian */ 33 protected double pm; /* prime meridian */ 34 protected double k0 = 1.0; /* general scale factor */ 30 protected double x0; /* false easting (in meters) */ 31 protected double y0; /* false northing (in meters) */ 32 protected double lon0; /* central meridian */ 33 protected double pm; /* prime meridian */ 34 protected double k0 = 1.0; /* general scale factor */ 35 protected double toMeter = 1.0; /* switch from meters to east/north coordinate units */ 35 36 36 37 private volatile ProjectionBounds projectionBoundsBox; … … 68 69 } 69 70 71 /** 72 * Get the factor that converts meters to intended units of east/north coordinates. 73 * 74 * For projected coordinate systems, the semi-major axis of the ellipsoid is 75 * always given in meters, which means the preliminary projection result will 76 * be in meters as well. This factor is used to convert to the intended units 77 * of east/north coordinates (e.g. feet in the US). 78 * 79 * For geographic coordinate systems, the preliminary "projection" result will 80 * be in degrees, so there is no reason to convert anything and this factor 81 * will by 1 by default. 82 * 83 * @return factor that converts meters to intended units of east/north coordinates 84 */ 85 public final double getToMeter() { 86 return toMeter; 87 } 88 70 89 @Override 71 90 public EastNorth latlon2eastNorth(LatLon ll) { 72 91 ll = datum.fromWGS84(ll); 73 92 double[] en = proj.project(Math.toRadians(ll.lat()), Math.toRadians(LatLon.normalizeLon(ll.lon() - lon0 - pm))); 74 return new EastNorth( ellps.a * k0 * en[0] + x0, ellps.a * k0 * en[1] + y0);93 return new EastNorth((ellps.a * k0 * en[0] + x0) / toMeter, (ellps.a * k0 * en[1] + y0) / toMeter); 75 94 } 76 95 77 96 @Override 78 97 public LatLon eastNorth2latlon(EastNorth en) { 79 double[] latlon_rad = proj.invproject((en.east() - x0) / ellps.a / k0, (en.north()- y0) / ellps.a / k0);98 double[] latlon_rad = proj.invproject((en.east() * toMeter - x0) / ellps.a / k0, (en.north() * toMeter - y0) / ellps.a / k0); 80 99 LatLon ll = new LatLon(Math.toDegrees(latlon_rad[0]), LatLon.normalizeLon(Math.toDegrees(latlon_rad[1]) + lon0 + pm)); 81 100 return datum.toWGS84(ll); -
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r9642 r9790 61 61 protected String cacheDir; 62 62 protected Bounds bounds; 63 private double metersPerUnit; 64 private double metersPerUnitNoDegrees; 63 private double metersPerUnitWMTS; 65 64 private String axis = "enu"; // default axis orientation is East, North, Up 66 65 … … 298 297 s = Utils.strip(s, "\""); 299 298 if (UNITS_TO_METERS.containsKey(s)) { 300 this. metersPerUnit= UNITS_TO_METERS.get(s);301 this.metersPerUnit NoDegrees = this.metersPerUnit;299 this.toMeter = UNITS_TO_METERS.get(s); 300 this.metersPerUnitWMTS = this.toMeter; 302 301 defaultUnits = false; 303 302 } else { 304 Main.warn("No metersPerUnit found for: " + s);303 throw new ProjectionConfigurationException(tr("No unit found for: {0}", s)); 305 304 } 306 305 } 307 306 s = parameters.get(Param.to_meter.key); 308 307 if (s != null) { 309 this. metersPerUnit= parseDouble(s, Param.to_meter.key);310 this.metersPerUnit NoDegrees = this.metersPerUnit;308 this.toMeter = parseDouble(s, Param.to_meter.key); 309 this.metersPerUnitWMTS = this.toMeter; 311 310 defaultUnits = false; 312 311 } 313 312 if (defaultUnits) { 314 this. metersPerUnit = proj.isGeographic() ? METER_PER_UNIT_DEGREE :1;315 this.metersPerUnit NoDegrees =1;313 this.toMeter = 1; 314 this.metersPerUnitWMTS = proj.isGeographic() ? METER_PER_UNIT_DEGREE : 1; 316 315 } 317 316 s = parameters.get(Param.axis.key); … … 712 711 } 713 712 713 /** 714 * Factor to convert units of east/north coordinates to meters. 715 * 716 * When east/north coordinates are in degrees (geographic CRS), the scale 717 * at the equator is taken, i.e. 360 degrees corresponds to the length of 718 * the equator in meters. 719 * 720 * @return factor to convert units to meter 721 */ 714 722 @Override 715 723 public double getMetersPerUnit() { 716 return metersPerUnit; 717 } 718 719 /** 720 * Like {@link #getMetersPerUnit()}, but has default value 1 for a 721 * geographic CRS. I.e. by default, degrees are not converted to meters, 722 * but left alone (similar to proj.4 behavior). 723 * @return meters per unit of projection 724 */ 725 public double getMetersPerUnitProj() { 726 return metersPerUnitNoDegrees; 724 return metersPerUnitWMTS; 727 725 } 728 726
Note:
See TracChangeset
for help on using the changeset viewer.