001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.data.projection.proj;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import org.openstreetmap.josm.data.Bounds;
007import org.openstreetmap.josm.data.projection.ProjectionConfigurationException;
008import org.openstreetmap.josm.tools.Utils;
009
010/**
011 * Equidistant cylindrical projection (EPSG code 9823).
012 * In the particular case where the {@code standard_parallel_1} is 0°, this projection is also called Plate Carree or Equirectangular.
013 * This is used in, for example, <cite>WGS84 / Plate Carree</cite> (EPSG:32662).
014 * <p>
015 * <b>References:</b>
016 * <ul>
017 *   <li>John P. Snyder (Map Projections - A Working Manual,<br>
018 *       U.S. Geological Survey Professional Paper 1395, 1987)</li>
019 *   <li>"Coordinate Conversions and Transformations including Formulas",<br>
020 *       EPSG Guidence Note Number 7 part 2, Version 24.</li>
021 * </ul>
022 *
023 * @author John Grange
024 * @author Martin Desruisseaux
025 *
026 * @see <A HREF="http://mathworld.wolfram.com/CylindricalEquidistantProjection.html">Cylindrical Equidistant projection on MathWorld</A>
027 * @see <A HREF="http://www.remotesensing.org/geotiff/proj_list/equirectangular.html">"Equirectangular" on RemoteSensing.org</A>
028 * @since 13598
029 */
030public class EquidistantCylindrical extends AbstractProj {
031
032    /**
033     * Cosinus of the {@code "standard_parallel_1"} parameter.
034     */
035    private double cosStandardParallel;
036
037    @Override
038    public String getName() {
039        return tr("Equidistant Cylindrical (Plate Caree)");
040    }
041
042    @Override
043    public String getProj4Id() {
044        return "eqc";
045    }
046
047    @Override
048    public void initialize(ProjParameters params) throws ProjectionConfigurationException {
049        super.initialize(params);
050        if (params.lat_ts != null) {
051            cosStandardParallel = Math.cos(Utils.toRadians(Math.abs(params.lat_ts)));
052        } else {
053            // standard parallel is the equator (Plate Carree or Equirectangular)
054            cosStandardParallel = 1.0;
055        }
056    }
057
058    @Override
059    public double[] project(double latRad, double lonRad) {
060        return new double[] {lonRad * cosStandardParallel, latRad};
061    }
062
063    @Override
064    public double[] invproject(double east, double north) {
065        return new double[] {north, east / cosStandardParallel};
066    }
067
068    @Override
069    public Bounds getAlgorithmBounds() {
070        return new Bounds(-89, -180, 89, 180, false);
071    }
072}