Changeset 5236 in josm for trunk/src/org


Ignore:
Timestamp:
2012-05-12T23:27:39+02:00 (12 years ago)
Author:
bastiK
Message:
  • removed offset option from UTM which is probably rarely used. (custom projection can be used for this now, e.g. +proj=tmerc +lon_0=-3 +k_0=0.9996 +x_0=3500000 or +init=epsg:32630 +x_0=3500000)
  • fixed tests
Location:
trunk/src/org/openstreetmap/josm
Files:
12 edited

Legend:

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

    r5235 r5236  
    9696
    9797    public Lambert(final int layoutZone) {
     98        if (layoutZone < 0 || layoutZone >= 4)
     99            throw new IllegalArgumentException();
    98100        this.layoutZone = layoutZone;
    99101        ellps = Ellipsoid.clarkeIGN;
  • trunk/src/org/openstreetmap/josm/data/projection/ProjectionInfo.java

    r5234 r5236  
    44import java.util.Collection;
    55import java.util.HashMap;
     6import java.util.Map;
    67
    78import org.openstreetmap.josm.gui.preferences.projection.ProjectionChoice;
     
    910
    1011public class ProjectionInfo {
    11     private static HashMap<String, ProjectionChoice> allCodesPC;
    12     private static HashMap<String, Projection> allCodes;
     12    private static Map<String, ProjectionChoice> allCodesPC = new HashMap<String, ProjectionChoice>();
     13    private static Map<String, Projection> allCodes = new HashMap<String, Projection>();
    1314
    1415    static {
    15         allCodes = new HashMap<String, Projection>();
    1616        for (ProjectionChoice pc : ProjectionPreference.getProjectionChoices()) {
    1717            for (String code : pc.allCodes()) {
  • trunk/src/org/openstreetmap/josm/data/projection/Puwg.java

    r5235 r5236  
    2222    private final int zone;
    2323
    24     static public PuwgData[] Zones = new PuwgData[] {
     24    static public PuwgData[] zones = new PuwgData[] {
    2525        new Epsg2180(),
    2626        new Epsg2176(),
     
    3535
    3636    public Puwg(int zone) {
     37        if (zone < 0 || zone >= zones.length)
     38            throw new IllegalArgumentException();
    3739        ellps = Ellipsoid.GRS80;
    3840        proj = new org.openstreetmap.josm.data.projection.proj.TransverseMercator();
     
    4446        datum = GRS80Datum.INSTANCE;
    4547        this.zone = zone;
    46         PuwgData z = Zones[zone];
     48        PuwgData z = zones[zone];
    4749        x_0 = z.getPuwgFalseEasting();
    4850        y_0 = z.getPuwgFalseNorthing();
     
    5860    @Override
    5961    public Integer getEpsgCode() {
    60         return Zones[zone].getEpsgCode();
     62        return zones[zone].getEpsgCode();
    6163    }
    6264
     
    6870    @Override
    6971    public String getCacheDirectoryName() {
    70         return Zones[zone].getCacheDirectoryName();
     72        return zones[zone].getCacheDirectoryName();
    7173    }
    7274
    7375    @Override
    7476    public Bounds getWorldBoundsLatLon() {
    75         return Zones[zone].getWorldBoundsLatLon();
     77        return zones[zone].getWorldBoundsLatLon();
    7678    }
    7779
  • trunk/src/org/openstreetmap/josm/data/projection/UTM.java

    r5235 r5236  
    2424    private Hemisphere hemisphere;
    2525
    26     /**
    27      * Applies an additional false easting of 3000000 m if true.
    28      */
    29     private boolean offset;
    30 
    3126    public UTM() {
    32         this(DEFAULT_ZONE, DEFAULT_HEMISPHERE, false);
     27        this(DEFAULT_ZONE, DEFAULT_HEMISPHERE);
    3328    }
    3429
    35     public UTM(int zone, Hemisphere hemisphere, boolean offset) {
     30    public UTM(int zone, Hemisphere hemisphere) {
     31        if (zone < 1 || zone > 60)
     32            throw new IllegalArgumentException();
    3633        ellps = Ellipsoid.WGS84;
    3734        proj = new org.openstreetmap.josm.data.projection.proj.TransverseMercator();
     
    4441        this.zone = zone;
    4542        this.hemisphere = hemisphere;
    46         this.offset = offset;
    47         x_0 = 500000 + (offset ? 3000000 : 0);
     43        x_0 = 500000;
    4844        y_0 = hemisphere == Hemisphere.North ? 0 : 10000000;
    4945        lon_0 = getUtmCentralMeridianDeg(zone);
     
    8177    @Override
    8278    public Integer getEpsgCode() {
    83         return ((offset?325800:32600) + getzone() + (hemisphere == Hemisphere.South?100:0));
     79        return (32600 + getzone() + (hemisphere == Hemisphere.South?100:0));
    8480    }
    8581
  • trunk/src/org/openstreetmap/josm/data/projection/UTM_France_DOM.java

    r5235 r5236  
    6161
    6262    public UTM_France_DOM(int currentGeodesic) {
     63        if (currentGeodesic < 0 || currentGeodesic >= 5)
     64            throw new IllegalArgumentException();
    6365        this.currentGeodesic = currentGeodesic;
    6466        datum = utmDatums[currentGeodesic];
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/GaussKruegerProjectionChoice.java

    r5234 r5236  
    2020    @Override
    2121    public Projection getProjection() {
    22         return new GaussKrueger(indexToZone(index));
     22        return new GaussKrueger(index + 2);
    2323    }
    2424
    2525    @Override
    26     protected int indexToZone(int index) {
    27         return index + 2;
     26    protected String indexToZone(int index) {
     27        return Integer.toString(index + 2);
    2828    }
    2929
    3030    @Override
    31     protected int zoneToIndex(int zone) {
    32         return zone - 2;
     31    protected int zoneToIndex(String zone) {
     32        try {
     33            return Integer.parseInt(zone) - 2;
     34        } catch(NumberFormatException e) {}
     35        return defaultIndex;
    3336    }
    3437
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertCC9ZonesProjectionChoice.java

    r5234 r5236  
    7676   
    7777    @Override
    78     protected int indexToZone(int index) {
    79         return index + 1;
     78    protected String indexToZone(int index) {
     79        return Integer.toString(index + 1);
    8080    }
    8181
    8282    @Override
    83     protected int zoneToIndex(int zone) {
    84         return zone - 1;
     83    protected int zoneToIndex(String zone) {
     84        try {
     85            return Integer.parseInt(zone) - 1;
     86        } catch(NumberFormatException e) {}
     87        return defaultIndex;
    8588    }
    8689
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/LambertProjectionChoice.java

    r5234 r5236  
    7070
    7171    @Override
    72     protected int indexToZone(int index) {
    73         return index + 1;
     72    protected String indexToZone(int index) {
     73        return Integer.toString(index + 1);
    7474    }
    7575
    7676    @Override
    77     protected int zoneToIndex(int zone) {
    78         return zone - 1;
     77    protected int zoneToIndex(String zone) {
     78        try {
     79            return Integer.parseInt(zone) - 1;
     80        } catch(NumberFormatException e) {}
     81        return defaultIndex;
    7982    }
    8083
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/ListProjectionChoice.java

    r5234 r5236  
    4646     * Convert 0-based index to preference value.
    4747     */
    48     abstract protected int indexToZone(int index);
     48    abstract protected String indexToZone(int index);
    4949
    5050    /**
    5151     * Convert preference value to 0-based index.
    5252     */
    53     abstract protected int zoneToIndex(int zone);
     53    abstract protected int zoneToIndex(String zone);
    5454
    5555    @Override
    5656    public void setPreferences(Collection<String> args) {
    57         Integer zone = null;
     57        String zone = null;
    5858        if (args != null && args.size() >= 1) {
    59             try {
    60                 zone = Integer.parseInt(args.iterator().next());
    61             } catch(NumberFormatException e) {}
     59            zone = args.iterator().next();
    6260        }
    6361        int index;
     
    10199        CBPanel p = (CBPanel) panel;
    102100        int index = p.prefcb.getSelectedIndex();
    103         return Collections.singleton(Integer.toString(indexToZone(index)));
     101        return Collections.singleton(indexToZone(index));
    104102    }
    105103
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/PuwgProjectionChoice.java

    r5234 r5236  
    1313
    1414    public PuwgProjectionChoice() {
    15         super("core:puwg", tr("PUWG (Poland)"), Puwg.Zones, tr("PUWG Zone"));
     15        super("core:puwg", tr("PUWG (Poland)"), Puwg.zones, tr("PUWG Zone"));
    1616    }
    1717
     
    2323    @Override
    2424    public String[] allCodes() {
    25         String[] zones = new String[Puwg.Zones.length];
    26         for (int zone = 0; zone < Puwg.Zones.length; zone++) {
    27             zones[zone] = Puwg.Zones[zone].toCode();
     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();
    2828        }
    2929        return zones;
     
    3232    @Override
    3333    public Collection<String> getPreferencesFromCode(String code) {
    34         for (Puwg.PuwgData p : Puwg.Zones) {
     34        for (Puwg.PuwgData p : Puwg.zones) {
    3535            if (code.equals(p.toCode()))
    3636                return Collections.singleton(code);
     
    4545
    4646    @Override
    47     protected int indexToZone(int index) {
    48         return index;
     47    protected String indexToZone(int index) {
     48        return Puwg.zones[index].toCode();
    4949    }
    5050
    5151    @Override
    52     protected int zoneToIndex(int zone) {
    53         return zone;
     52    protected int zoneToIndex(String zone) {
     53        for (int i=0; i<Puwg.zones.length; i++) {
     54            if (zone.equals(Puwg.zones[i].toCode())) {
     55                return i;
     56            }
     57        }
     58        return defaultIndex;
    5459    }
    5560
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTMProjectionChoice.java

    r5234 r5236  
    1212
    1313import javax.swing.ButtonGroup;
    14 import javax.swing.JCheckBox;
    1514import javax.swing.JLabel;
    1615import javax.swing.JPanel;
     
    2726    private UTM.Hemisphere hemisphere;
    2827   
    29     /**
    30      * Applies an additional false easting of 3000000 m if true.
    31      */
    32     private boolean offset;
    33 
    3428    private final static List<String> cbEntries = new ArrayList<String>();
    3529    static {
     
    4640
    4741        public JRadioButton north, south;
    48         public JCheckBox offsetBox;
    4942
    5043        public UTMPanel(Object[] entries, int initialIndex, String label, ActionListener listener) {
     
    7669            this.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
    7770
    78             //Offset
    79             offsetBox = new JCheckBox();
    80             offsetBox.setSelected(offset);
    81 
    82             this.add(new JLabel(tr("Offset 3.000.000m east")), GBC.std().insets(5,5,0,5));
    83             this.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL));
    84             this.add(offsetBox, GBC.eop().fill(GBC.HORIZONTAL));
    85             this.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH));
    86 
    8771            if (listener != null) {
    8872                north.addActionListener(listener);
    8973                south.addActionListener(listener);
    90                 offsetBox.addActionListener(listener);
    9174            }
    9275        }
     
    10083    @Override
    10184    public Projection getProjection() {
    102         return new UTM(indexToZone(index), hemisphere, offset);
     85        return new UTM(index + 1, hemisphere);
    10386    }
    10487
     
    10891        int index = p.prefcb.getSelectedIndex();
    10992        UTM.Hemisphere hemisphere = p.south.isSelected()?UTM.Hemisphere.South:UTM.Hemisphere.North;
    110         boolean offset = p.offsetBox.isSelected();
    111         return Arrays.asList(Integer.toString(indexToZone(index)), hemisphere.toString(), (offset?"offset":"standard"));
     93        return Arrays.asList(indexToZone(index), hemisphere.toString());
    11294    }
    11395
     
    11698        ArrayList<String> projections = new ArrayList<String>(60*4);
    11799        for (int zone = 1;zone <= 60; zone++) {
    118             for (boolean offset : new boolean[] { false, true }) {
    119                 for (UTM.Hemisphere hemisphere : UTM.Hemisphere.values()) {
    120                     projections.add("EPSG:" + ((offset?325800:32600) + zone + (hemisphere == UTM.Hemisphere.South?100:0)));
    121                 }
     100            for (UTM.Hemisphere hemisphere : UTM.Hemisphere.values()) {
     101                projections.add("EPSG:" + (32600 + zone + (hemisphere == UTM.Hemisphere.South?100:0)));
    122102            }
    123103        }
     
    127107    @Override
    128108    public Collection<String> getPreferencesFromCode(String code) {
    129         boolean offset = code.startsWith("EPSG:3258") || code.startsWith("EPSG:3259");
    130109
    131         if (code.startsWith("EPSG:326") || code.startsWith("EPSG:327") || offset) {
     110        if (code.startsWith("EPSG:326") || code.startsWith("EPSG:327")) {
    132111            try {
    133                 UTM.Hemisphere hemisphere;
    134                 String zonestring;
    135                 if (offset) {
    136                     hemisphere = code.charAt(8)=='8'?UTM.Hemisphere.North:UTM.Hemisphere.South;
    137                     zonestring = code.substring(9);
    138                 } else {
    139                     hemisphere = code.charAt(7)=='6'?UTM.Hemisphere.North:UTM.Hemisphere.South;
    140                     zonestring = code.substring(8);
    141                 }
    142 
     112                UTM.Hemisphere hemisphere = code.charAt(7)=='6'?UTM.Hemisphere.North:UTM.Hemisphere.South;
     113                String zonestring = code.substring(8);
    143114                int zoneval = Integer.parseInt(zonestring);
    144115                if(zoneval > 0 && zoneval <= 60)
    145                     return Arrays.asList(zonestring, hemisphere.toString(), (offset?"offset":"standard"));
     116                    return Arrays.asList(zonestring, hemisphere.toString());
    146117            } catch(NumberFormatException e) {}
    147118        }
     
    153124        super.setPreferences(args);
    154125        UTM.Hemisphere hemisphere = DEFAULT_HEMISPHERE;
    155         boolean offset = false;
    156126
    157127        if(args != null) {
     
    161131                hemisphere = UTM.Hemisphere.valueOf(array[1]);
    162132            }
    163 
    164             if (array.length > 2) {
    165                 offset = array[2].equals("offset");
    166             }
    167133        }
    168134        this.hemisphere = hemisphere;
    169         this.offset = offset;
    170135    }
    171136
    172137    @Override
    173     protected int indexToZone(int index) {
    174         return index + 1;
     138    protected String indexToZone(int index) {
     139        return Integer.toString(index + 1);
    175140    }
    176141
    177142    @Override
    178     protected int zoneToIndex(int zone) {
    179         return zone - 1;
     143    protected int zoneToIndex(String zone) {
     144        try {
     145            return Integer.parseInt(zone) - 1;
     146        } catch(NumberFormatException e) {}
     147        return defaultIndex;
    180148    }
    181149
  • trunk/src/org/openstreetmap/josm/gui/preferences/projection/UTM_France_DOM_ProjectionChoice.java

    r5234 r5236  
    2424
    2525    @Override
    26     protected int indexToZone(int index) {
    27         return index + 1;
     26    protected String indexToZone(int index) {
     27        return Integer.toString(index + 1);
    2828    }
    2929
    3030    @Override
    31     protected int zoneToIndex(int zone) {
    32         return zone - 1;
     31    protected int zoneToIndex(String zone) {
     32        try {
     33            return Integer.parseInt(zone) - 1;
     34        } catch(NumberFormatException e) {}
     35        return defaultIndex;
    3336    }
    3437
Note: See TracChangeset for help on using the changeset viewer.