Changeset 5548 in josm


Ignore:
Timestamp:
2012-11-01T16:52:19+01:00 (11 years ago)
Author:
bastiK
Message:

remove Projection classes (replaced by data/epsg file)

concludes the projection rework from ealier this year

Location:
trunk/src/org/openstreetmap/josm
Files:
15 deleted
17 edited

Legend:

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

    r5279 r5548  
    2121import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum;
    2222import org.openstreetmap.josm.data.projection.datum.WGS84Datum;
     23import org.openstreetmap.josm.data.projection.proj.Mercator;
    2324import org.openstreetmap.josm.data.projection.proj.Proj;
    2425import org.openstreetmap.josm.data.projection.proj.ProjParameters;
     
    3839     */
    3940    protected String pref;
     41    protected String name;
     42    protected String code;
     43    protected String cacheDir;
    4044    protected Bounds bounds;
    4145
     
    8387
    8488    public CustomProjection() {
    85         this.pref = null;
    8689    }
    8790
    8891    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;
    89108        try {
    90             this.pref = pref;
    91109            update(pref);
    92110        } catch (ProjectionConfigurationException ex) {
     
    104122            ellps = Ellipsoid.WGS84;
    105123            datum = WGS84Datum.INSTANCE;
    106             proj = new org.openstreetmap.josm.data.projection.proj.Mercator();
     124            proj = new Mercator();
    107125            bounds = new Bounds(
    108126                    new LatLon(-85.05112877980659, -180.0),
     
    429447    @Override
    430448    public Integer getEpsgCode() {
     449        if (code != null && code.startsWith("EPSG:")) {
     450            try {
     451                return Integer.parseInt(code.substring(5));
     452            } catch (NumberFormatException e) {}
     453        }
    431454        return null;
    432455    }
     
    434457    @Override
    435458    public String toCode() {
    436         return "proj:" + (pref == null ? "ERROR" : pref);
     459        return code != null ? code : "proj:" + (pref == null ? "ERROR" : pref);
    437460    }
    438461
    439462    @Override
    440463    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);
    442465    }
    443466
     
    452475    @Override
    453476    public String toString() {
    454         return tr("Custom Projection");
     477        return name != null ? name : tr("Custom Projection");
    455478    }
    456479}
  • trunk/src/org/openstreetmap/josm/data/projection/Projection.java

    r5266 r5548  
    1 // License: GPL. Copyright 2007 by Immanuel Scholz and others
     1// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.data.projection;
    33
     
    77
    88/**
    9  * Classes implementing this are able to convert lat/lon values to
    10  * planar screen coordinates.
     9 * A projection, i.e. a class that supports conversion from lat/lon
     10 * to east/north and back.
    1111 *
    12  * @author imi
     12 * The conversion from east/north to the screen coordinates is simply a scale
     13 * factor and x/y offset.
    1314 */
    1415public interface Projection {
    1516    /**
    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})).
    1718     * FIXME: misnomer
     19     * @return the scale factor
    1820     */
    1921    double getDefaultZoomInPPD();
    2022
    2123    /**
    22      * Convert from lat/lon to northing/easting.
     24     * Convert from lat/lon to easting/northing.
    2325     *
    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
    2528     */
    26     EastNorth latlon2eastNorth(LatLon p);
     29    EastNorth latlon2eastNorth(LatLon ll);
    2730
    2831    /**
    29      * Convert from norting/easting to lat/lon.
     32     * Convert from easting/norting to lat/lon.
    3033     *
    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)
    3236     */
    33     LatLon eastNorth2latlon(EastNorth p);
     37    LatLon eastNorth2latlon(EastNorth en);
    3438
    3539    /**
    36      * Describe the projection converter in one or two words.
     40     * Describe the projection in one or two words.
     41     * @return the name / description
    3742     */
    3843    String toString();
    3944
    4045    /**
    41      * Return projection code. This should be a unique identifier.
     46     * Return projection code.
     47     *
     48     * This should be a unique identifier.
    4249     * If projection supports parameters, return a different code
    4350     * for each set of parameters.
    4451     *
    4552     * The EPSG code can be used (if defined for the projection).
     53     *
     54     * @return the projection identifier
    4655     */
    4756    String toCode();
    4857
    4958    /**
    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)
    5161     */
    5262    String getCacheDirectoryName();
    5363
    5464    /**
    55      * Get the bounds of the world
     65     * Get the bounds of the world.
     66     * @return the supported lat/lon rectangle for this projection
    5667     */
    5768    Bounds getWorldBoundsLatLon();
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r5237 r5548  
    2525import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
    2626import org.openstreetmap.josm.io.MirroredInputStream;
     27import org.openstreetmap.josm.tools.Pair;
    2728
    2829/**
     
    4748     * should be compatible to PROJ.4
    4849     */
    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>>();
    5455
    5556    static {
     
    109110
    110111    public static String getInit(String id) {
    111         return inits.get(id);
     112        return inits.get(id.toLowerCase()).b;
    112113    }
    113114
     
    116117     */
    117118    private static void loadInits() {
    118         Pattern epsgPattern = Pattern.compile("\\A<(\\d+)>(.*)<>\\Z");
     119        Pattern epsgPattern = Pattern.compile("<(\\d+)>(.*)<>");
    119120        try {
    120121            InputStream in = new MirroredInputStream("resource://data/epsg");
    121122            BufferedReader r = new BufferedReader(new InputStreamReader(in));
    122             String line;
     123            String line, lastline = "";
    123124            while ((line = r.readLine()) != null) {
    124125                line = line.trim();
    125126                if (!line.startsWith("#") && !line.isEmpty()) {
     127                    if (!lastline.startsWith("#")) throw new AssertionError();
     128                    String name = lastline.substring(1).trim();
    126129                    Matcher m = epsgPattern.matcher(line);
    127130                    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()));
    129132                    } else {
    130133                        System.err.println("Warning: failed to parse line from the epsg projection definition: "+line);
    131134                    }
    132135                }
     136                lastline = line;
    133137            }
    134138        } catch (IOException ex) {
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r5547 r5548  
    1212import java.io.PrintWriter;
    1313import java.util.ArrayList;
     14import java.util.Arrays;
    1415import java.util.Collection;
    1516import java.util.HashMap;
     
    2324import org.openstreetmap.josm.Main;
    2425import org.openstreetmap.josm.actions.ValidateAction;
    25 import org.openstreetmap.josm.data.projection.Epsg4326;
    26 import org.openstreetmap.josm.data.projection.Lambert;
    27 import org.openstreetmap.josm.data.projection.Mercator;
    2826import org.openstreetmap.josm.data.validation.tests.BuildingInBuilding;
    2927import org.openstreetmap.josm.data.validation.tests.Coastlines;
     
    5755import org.openstreetmap.josm.gui.layer.ValidatorLayer;
    5856import org.openstreetmap.josm.gui.preferences.ValidatorPreference;
     57import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
    5958
    6059/**
     
    253252     */
    254253    public void initializeGridDetail() {
    255         if (Main.getProjection().toString().equals(new Epsg4326().toString())) {
     254        String code = Main.getProjection().toCode();
     255        if (Arrays.asList(ProjectionPreference.wgs84.allCodes()).contains(code)) {
    256256            OsmValidator.griddetail = 10000;
    257         } else if (Main.getProjection().toString().equals(new Mercator().toString())) {
     257        } else if (Arrays.asList(ProjectionPreference.mercator.allCodes()).contains(code)) {
    258258            OsmValidator.griddetail = 0.01;
    259         } else if (Main.getProjection().toString().equals(new Lambert().toString())) {
     259        } else if (Arrays.asList(ProjectionPreference.lambert.allCodes()).contains(code)) {
    260260            OsmValidator.griddetail = 0.1;
    261261        } else {
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/AbstractProjectionChoice.java

    r5234 r5548  
    22package org.openstreetmap.josm.gui.preferences.projection;
    33
     4import org.openstreetmap.josm.data.projection.CustomProjection;
     5import org.openstreetmap.josm.data.projection.Projection;
     6import org.openstreetmap.josm.data.projection.Projections;
     7
    48abstract public class AbstractProjectionChoice implements ProjectionChoice {
    5     private String id;
    6     private String name;
     9   
     10    protected String name;
     11    protected String id;
     12    protected String cacheDir;
    713
    8     public AbstractProjectionChoice(String id, String name) {
     14    /**
     15     * Constructor.
     16     *
     17     * @param name short name of the projection choice as shown in the GUI
     18     * @param id unique identifier for the projection choice
     19     * @param cacheDir a cache directory name
     20     */
     21    public AbstractProjectionChoice(String name, String id, String cacheDir) {
     22        this.name = name;
    923        this.id = id;
    10         this.name = name;
     24        this.cacheDir = cacheDir;
    1125    }
     26
     27    /**
     28     * Constructor (without cacheDir argument).
     29     *
     30     * Only for core projection choices, where chacheDir is the same as
     31     * the second part of the id.
     32     */
     33    public AbstractProjectionChoice(String name, String id) {
     34        this(name, id, null);
     35        if (!id.startsWith("core:")) throw new IllegalArgumentException();
     36        this.cacheDir = id.substring(5);
     37    }
     38
    1239    @Override
    1340    public String getId() {
    1441        return id;
    1542    }
    16    
     43
     44    public String getCacheDir() {
     45        return cacheDir;
     46    }
     47
    1748    @Override
    1849    public String toString() {
     
    2051    }
    2152
     53    abstract public String getCurrentCode();
     54   
     55    abstract public String getProjectionName();
     56
     57    @Override
     58    public Projection getProjection() {
     59        String code = getCurrentCode();
     60        String pref = Projections.getInit(code);
     61        if (pref == null)
     62            throw new AssertionError("Error: Unkown projection code");
     63        return new CustomProjection(getProjectionName(), code, pref, getCacheDir());
     64    }
     65
    2266}
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/CustomProjectionChoice.java

    r5546 r5548  
    4343
    4444    public CustomProjectionChoice() {
    45         super("core:custom", tr("Custom Projection"));
     45        super(tr("Custom Projection"), "core:custom");
    4646    }
    4747
     
    207207
    208208    @Override
     209    public String getCurrentCode() {
     210        // not needed - getProjection() is overridden
     211        throw new UnsupportedOperationException();
     212    }
     213
     214    @Override
     215    public String getProjectionName() {
     216        // not needed - getProjection() is overridden
     217        throw new UnsupportedOperationException();
     218    }
     219
     220    @Override
    209221    public JPanel getPreferencePanel(ActionListener listener) {
    210222        return new PreferencePanel(pref, listener);
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/GaussKruegerProjectionChoice.java

    r5546 r5548  
    77import java.util.Collections;
    88
    9 import org.openstreetmap.josm.data.projection.GaussKrueger;
    10 import org.openstreetmap.josm.data.projection.Projection;
    11 
    129public class GaussKruegerProjectionChoice extends ListProjectionChoice {
    1310
     
    1512
    1613    public GaussKruegerProjectionChoice() {
    17         super("core:gauss-krueger", tr("Gau\u00DF-Kr\u00FCger"), zones, tr("GK Zone"));
     14        super(tr("Gau\u00DF-Kr\u00FCger"), "core:gauss-krueger", zones, tr("GK Zone"));
    1815    }
    1916
    2017    @Override
    21     public Projection getProjection() {
    22         return new GaussKrueger(index + 2);
     18    public String getCurrentCode() {
     19        return "EPSG:"+Integer.toString(31466 + index);
    2320    }
    2421
     
    5754    }
    5855   
     56    @Override
     57    public String getProjectionName() {
     58        return tr("Gau\u00DF-Kr\u00FCger Zone {0}", index + 2);
     59    }
     60
    5961}
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertCC9ZonesProjectionChoice.java

    r5546 r5548  
    1111import javax.swing.JPanel;
    1212
    13 import org.openstreetmap.josm.data.projection.LambertCC9Zones;
    14 import org.openstreetmap.josm.data.projection.Projection;
    1513import org.openstreetmap.josm.tools.GBC;
    1614import org.openstreetmap.josm.tools.ImageProvider;
     
    3129
    3230    public LambertCC9ZonesProjectionChoice() {
    33         super("core:lambertcc9", tr("Lambert CC9 Zone (France)"), lambert9zones, tr("Lambert CC Zone"));
     31        super(tr("Lambert CC9 Zone (France)"), "core:lambertcc9", lambert9zones, tr("Lambert CC Zone"));
    3432    }
    3533
     
    4846
    4947    @Override
    50     public Projection getProjection() {
    51         return new LambertCC9Zones(index);
     48    public String getCurrentCode() {
     49        return "EPSG:" + Integer.toString(3942+index); //CC42 is EPSG:3942 (up to EPSG:3950 for CC50)
     50    }
     51
     52    @Override
     53    public String getProjectionName() {
     54        return tr("Lambert CC9 Zone (France)");
    5255    }
    5356
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertProjectionChoice.java

    r5546 r5548  
    1111import javax.swing.JPanel;
    1212
    13 import org.openstreetmap.josm.data.projection.Lambert;
    14 import org.openstreetmap.josm.data.projection.Projection;
    1513import org.openstreetmap.josm.tools.GBC;
    1614import org.openstreetmap.josm.tools.ImageProvider;
     
    2624
    2725    public LambertProjectionChoice() {
    28         super("core:lambert", tr("Lambert 4 Zones (France)"), lambert4zones, tr("Lambert CC Zone"));
     26        super(tr("Lambert 4 Zones (France)"), "core:lambert", lambert4zones, tr("Lambert CC Zone"));
    2927    }
    3028
     
    4341
    4442    @Override
    45     public Projection getProjection() {
    46         return new Lambert(index);
     43    public String getCurrentCode() {
     44        return "EPSG:" + Integer.toString(27561+index);
     45    }
     46
     47    @Override
     48    public String getProjectionName() {
     49        return tr("Lambert 4 Zones (France)");
    4750    }
    4851
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ListProjectionChoice.java

    r5429 r5548  
    1818abstract public class ListProjectionChoice extends AbstractProjectionChoice {
    1919
    20     protected int index;
     20    protected int index;        // 0-based index
    2121    protected int defaultIndex;
    2222    protected Object[] entries;
    2323    protected String label;
    2424
    25     public ListProjectionChoice(String id, String name, Object[] entries, String label) {
    26         this(id, name, entries, label, 0);
    27     }
    28 
    2925    /**
    3026     * Constructor
    3127     *
     28     * @param name the display name
    3229     * @param id the unique id for this ProjectionChoice
    33      * @param name the display name
    3430     * @param entries the list of display entries for the combo-box
    3531     * @param label a label shown left to the combo-box
    3632     * @param defaultIndex the default index for the combo-box
    3733     */
    38     public ListProjectionChoice(String id, String name, Object[] entries, String label, int defaultIndex) {
    39         super(id, name);
     34    public ListProjectionChoice(String name, String id, Object[] entries, String label, int defaultIndex) {
     35        super(name, id);
    4036        this.entries = entries;
    4137        this.label = label;
    4238        this.defaultIndex = defaultIndex;
     39    }
     40
     41    public ListProjectionChoice(String name, String id, Object[] entries, String label) {
     42        this(name, id, entries, label, 0);
    4343    }
    4444
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionChoice.java

    r5234 r5548  
    1818    /**
    1919     * Get a unique id for the projection choice.
     20     *
     21     * Will be used to save the user selection to the preference file.
     22     *
     23     * @return the string identifier
    2024     */
    2125    String getId();
     
    2731     * listener from getPreferencePanel is invoked.
    2832     *
    29      * Argument may be null to reset everything.
     33     * @param args preferences as a list of strings; may be null
     34     * to reset everything.
    3035     */
    3136    void setPreferences(Collection<String> args);
     
    5661
    5762    /**
    58      * Return all projection codes supported by this projection class.
     63     * Return all projection codes supported by this projection choice.
    5964     */
    6065    String[] allCodes();
     
    6974    Collection<String> getPreferencesFromCode(String code);
    7075
     76    /**
     77     * Short name of the projection choice as shown in the GUI (combo box).
     78     *
     79     * @return the name
     80     */
     81    String toString();
     82
    7183}
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ProjectionPreference.java

    r5546 r5548  
    2727import org.openstreetmap.josm.data.preferences.CollectionProperty;
    2828import org.openstreetmap.josm.data.preferences.StringProperty;
    29 import org.openstreetmap.josm.data.projection.BelgianLambert1972;
    30 import org.openstreetmap.josm.data.projection.BelgianLambert2008;
    31 import org.openstreetmap.josm.data.projection.Epsg3008;
    32 import org.openstreetmap.josm.data.projection.Epsg4326;
    33 import org.openstreetmap.josm.data.projection.Lambert93;
    34 import org.openstreetmap.josm.data.projection.LambertEST;
    35 import org.openstreetmap.josm.data.projection.Mercator;
     29import org.openstreetmap.josm.data.projection.CustomProjection;
    3630import org.openstreetmap.josm.data.projection.Projection;
    37 import org.openstreetmap.josm.data.projection.TransverseMercatorLV;
    3831import org.openstreetmap.josm.gui.NavigatableComponent;
    3932import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
     
    4538import org.openstreetmap.josm.tools.GBC;
    4639
     40/**
     41 * Projection preferences.
     42 *
     43 * How to add new Projections:
     44 *  - Find EPSG code for the projection.
     45 *  - Look up the parameter string for Proj4, e.g. on http://spatialreference.org/
     46 *      and add it to the file 'data/epsg' in JOSM trunk
     47 *  - Search for official references and verify the parameter values. These
     48 *      documents are often available in the local language only.
     49 *  - Use {@link #registerProjectionChoice()}, to make the entry known to JOSM.
     50 *
     51 * In case there is no EPSG code:
     52 *  - override {@link AbstractProjectionChoice#getProjection()} and provide
     53 *    a manual implementation of the projection. Use {@link CustomProjection}
     54 *    if possible.
     55 */
    4756public class ProjectionPreference implements SubPreferenceSetting {
    4857
     
    5665    private static Map<String, ProjectionChoice> projectionChoicesById = new HashMap<String, ProjectionChoice>();
    5766
    58     public static ProjectionChoice mercator = new SingleProjectionChoice("core:mercator", new Mercator());
     67    public static final ProjectionChoice wgs84;
     68    public static final ProjectionChoice mercator;
     69    public static final ProjectionChoice lambert;
    5970    static {
    60         // global projections
    61         registerProjectionChoice("core:wgs84", new Epsg4326());
    62         registerProjectionChoice(mercator);
     71
     72        /************************
     73         * Global projections.
     74         */
     75
     76        /**
     77         * WGS84: Directly use latitude / longitude values as x/y.
     78         */
     79        wgs84 = registerProjectionChoice(tr("WGS84 Geographic"), "core:wgs84", 4326, "epsg4326");
     80
     81        /**
     82         * Mercator Projection.
     83         *
     84         * The center of the mercator projection is always the 0 grad
     85         * coordinate.
     86         *
     87         * See also USGS Bulletin 1532
     88         * (http://egsc.usgs.gov/isb/pubs/factsheets/fs08799.html)
     89         * initially EPSG used 3785 but that has been superseded by 3857,
     90         * see http://www.epsg-registry.org/
     91         */
     92        mercator = registerProjectionChoice(tr("Mercator"), "core:mercator",
     93                3857);
     94       
     95        /**
     96         * UTM.
     97         */
    6398        registerProjectionChoice(new UTMProjectionChoice());
    64         // regional - alphabetical order by country code
    65         registerProjectionChoice("core:belambert1972", new BelgianLambert1972());   // BE
    66         registerProjectionChoice("core:belambert2008", new BelgianLambert2008());   // BE
    67         registerProjectionChoice(new SwissGridProjectionChoice());                  // CH
    68         registerProjectionChoice(new GaussKruegerProjectionChoice());               // DE
    69         registerProjectionChoice("core:lambertest", new LambertEST());              // EE
    70         registerProjectionChoice(new LambertProjectionChoice());                    // FR
    71         registerProjectionChoice("core:lambert93", new Lambert93());                // FR
    72         registerProjectionChoice(new LambertCC9ZonesProjectionChoice());            // FR
    73         registerProjectionChoice(new UTM_France_DOM_ProjectionChoice());            // FR
    74         registerProjectionChoice("core:tmerclv", new TransverseMercatorLV());       // LV
    75         registerProjectionChoice(new PuwgProjectionChoice());                       // PL
    76         registerProjectionChoice("core:sweref99", new Epsg3008());                  // SE
     99
     100        /************************
     101         * Regional - alphabetical order by country code.
     102         */
     103
     104        /**
     105         * Belgian Lambert 72 projection.
     106         *
     107         * As specified by the Belgian IGN in this document:
     108         * http://www.ngi.be/Common/Lambert2008/Transformation_Geographic_Lambert_FR.pdf
     109         *
     110         * @author Don-vip
     111         */
     112        registerProjectionChoice(tr("Belgian Lambert 1972"), "core:belgianLambert1972", 31370);     // BE
     113        /**
     114         * Belgian Lambert 2008 projection.
     115         *
     116         * As specified by the Belgian IGN in this document:
     117         * http://www.ngi.be/Common/Lambert2008/Transformation_Geographic_Lambert_FR.pdf
     118         *
     119         * @author Don-vip
     120         */
     121        registerProjectionChoice(tr("Belgian Lambert 2008"), "core:belgianLambert2008", 3812);      // BE
     122
     123        /**
     124         * SwissGrid CH1903 / L03, see http://de.wikipedia.org/wiki/Swiss_Grid.
     125         *
     126         * Actually, what we have here, is CH1903+ (EPSG:2056), but without
     127         * the additional false easting of 2000km and false northing 1000 km.
     128         *
     129         * To get to CH1903, a shift file is required. So currently, there are errors
     130         * up to 1.6m (depending on the location).
     131         */
     132        registerProjectionChoice(new SwissGridProjectionChoice());                                  // CH
     133
     134        registerProjectionChoice(new GaussKruegerProjectionChoice());                               // DE
     135
     136        /**
     137         * Estonian Coordinate System of 1997.
     138         *
     139         * Thanks to Johan Montagnat and its geoconv java converter application
     140         * (http://www.i3s.unice.fr/~johan/gps/ , published under GPL license)
     141         * from which some code and constants have been reused here.
     142         */
     143        registerProjectionChoice(tr("Lambert Zone (Estonia)"), "core:lambertest", 3301);            // EE
     144
     145        /**
     146         * Lambert conic conform 4 zones using the French geodetic system NTF.
     147         *
     148         * This newer version uses the grid translation NTF<->RGF93 provided by IGN for a submillimetric accuracy.
     149         * (RGF93 is the French geodetic system similar to WGS84 but not mathematically equal)
     150         *
     151         * Source: http://professionnels.ign.fr/DISPLAY/000/526/700/5267002/transformation.pdf
     152         * @author Pieren
     153         */
     154        registerProjectionChoice(lambert = new LambertProjectionChoice());                          // FR
     155        /**
     156         * Lambert 93 projection.
     157         *
     158         * As specified by the IGN in this document
     159         * http://professionnels.ign.fr/DISPLAY/000/526/702/5267026/NTG_87.pdf
     160         * @author Don-vip
     161         */
     162        registerProjectionChoice(tr("Lambert 93 (France)"), "core:lambert93", 2154);                // FR
     163        /**
     164         * Lambert Conic Conform 9 Zones projection.
     165         *
     166         * As specified by the IGN in this document
     167         * http://professionnels.ign.fr/DISPLAY/000/526/700/5267002/transformation.pdf
     168         * @author Pieren
     169         */
     170        registerProjectionChoice(new LambertCC9ZonesProjectionChoice());                            // FR
     171        /**
     172         * French departements in the Caribbean Sea and Indian Ocean.
     173         *
     174         * Using the UTM transvers Mercator projection and specific geodesic settings.
     175         */
     176        registerProjectionChoice(new UTM_France_DOM_ProjectionChoice());                            // FR
     177
     178        /**
     179         * LKS-92/ Latvia TM projection.
     180         *
     181         * Based on data from spatialreference.org.
     182         * http://spatialreference.org/ref/epsg/3059/
     183         *
     184         * @author Viesturs Zarins
     185         */
     186        registerProjectionChoice(tr("LKS-92 (Latvia TM)"), "core:tmerclv", 3059);                   // LV
     187
     188        /**
     189         * PUWG 1992 and 2000 are the official cordinate systems in Poland.
     190         *
     191         * They use the same math as UTM only with different constants.
     192         *
     193         * @author steelman
     194         */
     195        registerProjectionChoice(new PuwgProjectionChoice());                                       // PL
     196
     197        /**
     198         * SWEREF99 13 30 projection. Based on data from spatialreference.org.
     199         * http://spatialreference.org/ref/epsg/3008/
     200         *
     201         * @author Hanno Hecker
     202         */
     203        registerProjectionChoice(tr("SWEREF99 13 30 / EPSG:3008 (Sweden)"), "core:sweref99", 3008); // SE
     204
     205        /************************
     206         * Custom projection.
     207         */
    77208        registerProjectionChoice(new CustomProjectionChoice());
    78209    }
     
    83214    }
    84215
    85     public static void registerProjectionChoice(String id, Projection projection) {
    86         registerProjectionChoice(new SingleProjectionChoice(id, projection));
     216    public static ProjectionChoice registerProjectionChoice(String name, String id, Integer epsg, String cacheDir) {
     217        ProjectionChoice pc = new SingleProjectionChoice(name, id, "EPSG:"+epsg, cacheDir);
     218        registerProjectionChoice(pc);
     219        return pc;
     220    }
     221
     222    private static ProjectionChoice registerProjectionChoice(String name, String id, Integer epsg) {
     223        ProjectionChoice pc = new SingleProjectionChoice(name, id, "EPSG:"+epsg);
     224        registerProjectionChoice(pc);
     225        return pc;
    87226    }
    88227
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/PuwgProjectionChoice.java

    r5546 r5548  
    77import java.util.Collections;
    88
    9 import org.openstreetmap.josm.data.projection.Projection;
    10 import org.openstreetmap.josm.data.projection.Puwg;
    11 
    129public class PuwgProjectionChoice extends ListProjectionChoice {
    1310
     11    public static final String[] CODES = {
     12        "EPSG:2180",
     13        "EPSG:2176",
     14        "EPSG:2177",
     15        "EPSG:2178",
     16        "EPSG:2179"
     17    };
     18    public static final String[] NAMES = {
     19        tr("PUWG 1992 (Poland)"),
     20        tr("PUWG 2000 Zone {0} (Poland)", 5),
     21        tr("PUWG 2000 Zone {0} (Poland)", 6),
     22        tr("PUWG 2000 Zone {0} (Poland)", 7),
     23        tr("PUWG 2000 Zone {0} (Poland)", 8)
     24    };
     25
    1426    public PuwgProjectionChoice() {
    15         super("core:puwg", tr("PUWG (Poland)"), Puwg.zones, tr("PUWG Zone"));
     27        super(tr("PUWG (Poland)"), "core:puwg", NAMES, tr("PUWG Zone"));
    1628    }
    1729
    1830    @Override
    19     public Projection getProjection() {
    20         return new Puwg(index);
     31    public String getCurrentCode() {
     32        return CODES[index];
    2133    }
    2234
    2335    @Override
     36    public String getProjectionName() {
     37        return NAMES[index];
     38    }
     39
     40
     41    @Override
    2442    public String[] allCodes() {
    25         String[] zones = new String[Puwg.zones.length];
    26         for (int index = 0; index < Puwg.zones.length; index++) {
    27             zones[index] = Puwg.zones[index].toCode();
     43        String[] zones = new String[CODES.length];
     44        for (int idx = 0; idx < CODES.length; idx++) {
     45            zones[idx] = CODES[idx];
    2846        }
    2947        return zones;
     
    3250    @Override
    3351    public Collection<String> getPreferencesFromCode(String code) {
    34         for (Puwg.PuwgData p : Puwg.zones) {
    35             if (code.equals(p.toCode()))
    36                 return Collections.singleton(code);
     52        for (String code2 : CODES) {
     53            if (code.equals(code2))
     54                return Collections.singleton(code2);
    3755        }
    3856        return null;
     
    4159    @Override
    4260    protected String indexToZone(int index) {
    43         return Puwg.zones[index].toCode();
     61        return CODES[index];
    4462    }
    4563
    4664    @Override
    4765    protected int zoneToIndex(String zone) {
    48         for (int i=0; i<Puwg.zones.length; i++) {
    49             if (zone.equals(Puwg.zones[i].toCode())) {
     66        for (int i=0; i<CODES.length; i++) {
     67            if (zone.equals(CODES[i])) {
    5068                return i;
    5169            }
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/SingleProjectionChoice.java

    r5546 r5548  
    88import javax.swing.JPanel;
    99
    10 import org.openstreetmap.josm.data.projection.Projection;
    11 
    1210/**
    1311 * ProjectionChoice, that offers just one projection as choice.
     
    1513 * The GUI is an empty panel.
    1614 */
    17 public class SingleProjectionChoice implements ProjectionChoice {
     15public class SingleProjectionChoice extends AbstractProjectionChoice {
    1816
    19     private String id;
    20     private String name;
    21     private Projection projection;
     17    protected String code;
    2218
    23     public SingleProjectionChoice(String id, String name, Projection projection) {
    24         this.id = id;
    25         this.name = name;
    26         this.projection = projection;
     19    /**
     20     * Constructor.
     21     *
     22     * @param name short name of the projection choice as shown in the GUI
     23     * @param id unique identifier for the projection choice, e.g. "core:thisproj"
     24     * @param code the unique identifier for the projection, e.g. "EPSG:1234"
     25     * @param cacheDir a cache directory name
     26     */
     27    public SingleProjectionChoice(String name, String id, String code, String cacheDir) {
     28        super(name, id, cacheDir);
     29        this.code = code;
    2730    }
    2831
    29     public SingleProjectionChoice(String id, Projection projection) {
    30         this(id, projection.toString(), projection);
     32    public SingleProjectionChoice(String name, String id, String code) {
     33        super(name, id);
     34        this.code = code;
    3135    }
    3236
     
    3741
    3842    @Override
    39     public String getId() {
    40         return id;
    41     }
    42 
    43     @Override
    4443    public String[] allCodes() {
    45         return new String[] { projection.toCode() };
     44        return new String[] { code };
    4645    }
    4746
     
    5655
    5756    @Override
    58     public Projection getProjection() {
    59         return projection;
    60     }
    61 
    62     @Override
    6357    public String toString() {
    6458        return name;
     
    6761    @Override
    6862    public Collection<String> getPreferencesFromCode(String code) {
    69         if (code.equals(projection.toCode()))
     63        if (code.equals(this.code))
    7064            return Collections.emptyList();
    7165        else
    7266            return null;
    7367    }
     68
     69    @Override
     70    public String getCurrentCode() {
     71        return code;
     72    }
     73
     74    @Override
     75    public String getProjectionName() {
     76        return name; // the same name as the projection choice
     77    }
     78
    7479}
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/SwissGridProjectionChoice.java

    r5234 r5548  
    1010import javax.swing.JPanel;
    1111
    12 import org.openstreetmap.josm.data.projection.SwissGrid;
    1312import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    1413import org.openstreetmap.josm.tools.GBC;
     
    1716
    1817    public SwissGridProjectionChoice() {
    19         super("core:swissgrid", tr("Swiss Grid (Switzerland)"), new SwissGrid());
     18        super(tr("Swiss Grid (Switzerland)"), "core:swissgrid", "EPSG:21781");
    2019    }
    2120
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTMProjectionChoice.java

    r5546 r5548  
    1616import javax.swing.JRadioButton;
    1717
    18 import org.openstreetmap.josm.data.projection.Projection;
    19 import org.openstreetmap.josm.data.projection.UTM;
    2018import org.openstreetmap.josm.tools.GBC;
    2119
    2220public class UTMProjectionChoice extends ListProjectionChoice {
    2321
    24     private static final UTM.Hemisphere DEFAULT_HEMISPHERE = UTM.Hemisphere.North;
     22    public enum Hemisphere { North, South }
    2523
    26     private UTM.Hemisphere hemisphere;
     24    private static final Hemisphere DEFAULT_HEMISPHERE = Hemisphere.North;
     25
     26    private Hemisphere hemisphere;
    2727   
    2828    private final static List<String> cbEntries = new ArrayList<String>();
    2929    static {
    3030        for (int i = 1; i <= 60; i++) {
    31                 cbEntries.add(Integer.toString(i));
     31            cbEntries.add(Integer.toString(i));
    3232        }
    3333    }
    3434
    3535    public UTMProjectionChoice() {
    36         super("core:utm", tr("UTM"), cbEntries.toArray(), tr("UTM Zone"));
     36        super(tr("UTM"), "core:utm", cbEntries.toArray(), tr("UTM Zone"));
    3737    }
    3838
     
    4646            //Hemisphere
    4747            north = new JRadioButton();
    48             north.setSelected(hemisphere == UTM.Hemisphere.North);
     48            north.setSelected(hemisphere == Hemisphere.North);
    4949            south = new JRadioButton();
    50             south.setSelected(hemisphere == UTM.Hemisphere.South);
     50            south.setSelected(hemisphere == Hemisphere.South);
    5151
    5252            ButtonGroup group = new ButtonGroup();
     
    8282
    8383    @Override
    84     public Projection getProjection() {
    85         return new UTM(index + 1, hemisphere);
     84    public String getCurrentCode() {
     85        int zone = index + 1;
     86        int code = 32600 + zone + (hemisphere == Hemisphere.South ? 100 : 0);
     87        return "EPSG:" + Integer.toString(code);
    8688    }
     89
     90    @Override
     91    public String getProjectionName() {
     92        return tr("UTM");
     93    }
     94
    8795
    8896    @Override
     
    9098        UTMPanel p = (UTMPanel) panel;
    9199        int index = p.prefcb.getSelectedIndex();
    92         UTM.Hemisphere hemisphere = p.south.isSelected()?UTM.Hemisphere.South:UTM.Hemisphere.North;
     100        Hemisphere hemisphere = p.south.isSelected()?Hemisphere.South:Hemisphere.North;
    93101        return Arrays.asList(indexToZone(index), hemisphere.toString());
    94102    }
     
    98106        ArrayList<String> projections = new ArrayList<String>(60*4);
    99107        for (int zone = 1;zone <= 60; zone++) {
    100             for (UTM.Hemisphere hemisphere : UTM.Hemisphere.values()) {
    101                 projections.add("EPSG:" + (32600 + zone + (hemisphere == UTM.Hemisphere.South?100:0)));
     108            for (Hemisphere hemisphere : Hemisphere.values()) {
     109                projections.add("EPSG:" + (32600 + zone + (hemisphere == Hemisphere.South?100:0)));
    102110            }
    103111        }
     
    110118        if (code.startsWith("EPSG:326") || code.startsWith("EPSG:327")) {
    111119            try {
    112                 UTM.Hemisphere hemisphere = code.charAt(7)=='6'?UTM.Hemisphere.North:UTM.Hemisphere.South;
     120                Hemisphere hemisphere = code.charAt(7)=='6'?Hemisphere.North:Hemisphere.South;
    113121                String zonestring = code.substring(8);
    114122                int zoneval = Integer.parseInt(zonestring);
     
    123131    public void setPreferences(Collection<String> args) {
    124132        super.setPreferences(args);
    125         UTM.Hemisphere hemisphere = DEFAULT_HEMISPHERE;
     133        Hemisphere hemisphere = DEFAULT_HEMISPHERE;
    126134
    127135        if(args != null) {
     
    129137
    130138            if (array.length > 1) {
    131                 hemisphere = UTM.Hemisphere.valueOf(array[1]);
     139                hemisphere = Hemisphere.valueOf(array[1]);
    132140            }
    133141        }
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTM_France_DOM_ProjectionChoice.java

    r5546 r5548  
    66import java.util.Collection;
    77import java.util.Collections;
    8 
    9 import org.openstreetmap.josm.data.projection.Projection;
    10 import org.openstreetmap.josm.data.projection.UTM_France_DOM;
    118
    129public class UTM_France_DOM_ProjectionChoice extends ListProjectionChoice {
     
    1916    private final static String[] utmGeodesicsNames = { FortMarigotName, SainteAnneName, MartiniqueName, Reunion92Name, Guyane92Name};
    2017
     18    private final static Integer FortMarigotEPSG = 2969;
     19    private final static Integer SainteAnneEPSG = 2970;
     20    private final static Integer MartiniqueEPSG = 2973;
     21    private final static Integer ReunionEPSG = 2975;
     22    private final static Integer GuyaneEPSG = 2972;
     23    private final static Integer[] utmEPSGs = { FortMarigotEPSG, SainteAnneEPSG, MartiniqueEPSG, ReunionEPSG, GuyaneEPSG };
     24
    2125    public UTM_France_DOM_ProjectionChoice() {
    22         super("core:utmfrancedom", tr("UTM France (DOM)"), utmGeodesicsNames, tr("UTM Geodesic system"));
     26        super(tr("UTM France (DOM)"), "core:utmfrancedom", utmGeodesicsNames, tr("UTM Geodesic system"));
    2327    }
    2428
     
    3741
    3842    @Override
    39     public Projection getProjection() {
    40         return new UTM_France_DOM(index);
     43    public String getProjectionName() {
     44        return utmGeodesicsNames[index];
     45    }
     46
     47    @Override
     48    public String getCurrentCode() {
     49        return "EPSG:" + utmEPSGs[index];
    4150    }
    4251
    4352    @Override
    4453    public String[] allCodes() {
    45         String[] res = new String[UTM_France_DOM.utmEPSGs.length];
    46         for (int i=0; i<UTM_France_DOM.utmEPSGs.length; ++i) {
    47             res[i] = "EPSG:"+UTM_France_DOM.utmEPSGs[i];
     54        String[] res = new String[utmEPSGs.length];
     55        for (int i=0; i<utmEPSGs.length; ++i) {
     56            res[i] = "EPSG:" + utmEPSGs[i];
    4857        }
    4958        return res;
     
    5261    @Override
    5362    public Collection<String> getPreferencesFromCode(String code) {
    54         for (int i=0; i < UTM_France_DOM.utmEPSGs.length; i++ )
    55             if (("EPSG:"+UTM_France_DOM.utmEPSGs[i]).equals(code))
     63        for (int i=0; i < utmEPSGs.length; i++ )
     64            if (("EPSG:" + utmEPSGs[i]).equals(code))
    5665                return Collections.singleton(Integer.toString(i+1));
    5766        return null;
Note: See TracChangeset for help on using the changeset viewer.