Ignore:
Timestamp:
2016-02-12T14:31:47+01:00 (10 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.

File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.