Changeset 9790 in josm for trunk/src/org


Ignore:
Timestamp:
2016-02-12T14:31:47+01:00 (8 years ago)
Author:
bastiK
Message:

use intended units for east/north coordinates (see #12186)

When east/north coordinates are not in meter, but
feet, ... convert them to correct units.
Currently they are always stored in meters or degrees.
This makes no difference to JOSM internally, but affects
services like WMS/WMTS.
Only relevant for projections with +units=... or +to_meter=...
parameter set to non-default value.

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/projection/AbstractProjection.java

    r9558 r9790  
    2828    protected Datum datum;
    2929    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 */
    3536
    3637    private volatile ProjectionBounds projectionBoundsBox;
     
    6869    }
    6970
     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
    7089    @Override
    7190    public EastNorth latlon2eastNorth(LatLon ll) {
    7291        ll = datum.fromWGS84(ll);
    7392        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);
    7594    }
    7695
    7796    @Override
    7897    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);
    8099        LatLon ll = new LatLon(Math.toDegrees(latlon_rad[0]), LatLon.normalizeLon(Math.toDegrees(latlon_rad[1]) + lon0 + pm));
    81100        return datum.toWGS84(ll);
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r9642 r9790  
    6161    protected String cacheDir;
    6262    protected Bounds bounds;
    63     private double metersPerUnit;
    64     private double metersPerUnitNoDegrees;
     63    private double metersPerUnitWMTS;
    6564    private String axis = "enu"; // default axis orientation is East, North, Up
    6665
     
    298297                s = Utils.strip(s, "\"");
    299298                if (UNITS_TO_METERS.containsKey(s)) {
    300                     this.metersPerUnit = UNITS_TO_METERS.get(s);
    301                     this.metersPerUnitNoDegrees = this.metersPerUnit;
     299                    this.toMeter = UNITS_TO_METERS.get(s);
     300                    this.metersPerUnitWMTS = this.toMeter;
    302301                    defaultUnits = false;
    303302                } else {
    304                     Main.warn("No metersPerUnit found for: " + s);
     303                    throw new ProjectionConfigurationException(tr("No unit found for: {0}", s));
    305304                }
    306305            }
    307306            s = parameters.get(Param.to_meter.key);
    308307            if (s != null) {
    309                 this.metersPerUnit = parseDouble(s, Param.to_meter.key);
    310                 this.metersPerUnitNoDegrees = this.metersPerUnit;
     308                this.toMeter = parseDouble(s, Param.to_meter.key);
     309                this.metersPerUnitWMTS = this.toMeter;
    311310                defaultUnits = false;
    312311            }
    313312            if (defaultUnits) {
    314                 this.metersPerUnit = proj.isGeographic() ? METER_PER_UNIT_DEGREE : 1;
    315                 this.metersPerUnitNoDegrees = 1;
     313                this.toMeter = 1;
     314                this.metersPerUnitWMTS = proj.isGeographic() ? METER_PER_UNIT_DEGREE : 1;
    316315            }
    317316            s = parameters.get(Param.axis.key);
     
    712711    }
    713712
     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     */
    714722    @Override
    715723    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;
    727725    }
    728726
  • trunk/src/org/openstreetmap/josm/tools/MultiMap.java

    r9755 r9790  
    255255
    256256    @Override
    257 
    258257    public String toString() {
    259258        List<String> entries = new ArrayList<>(map.size());
Note: See TracChangeset for help on using the changeset viewer.