001    // License: GPL. For details, see LICENSE file.
002    package org.openstreetmap.josm.data.projection;
003    
004    import static org.openstreetmap.josm.tools.I18n.tr;
005    
006    import org.openstreetmap.josm.data.Bounds;
007    import org.openstreetmap.josm.data.coor.LatLon;
008    import org.openstreetmap.josm.data.projection.datum.Datum;
009    import org.openstreetmap.josm.data.projection.datum.GRS80Datum;
010    import org.openstreetmap.josm.data.projection.datum.SevenParameterDatum;
011    import org.openstreetmap.josm.data.projection.datum.ThreeParameterDatum;
012    import org.openstreetmap.josm.data.projection.proj.ProjParameters;
013    
014    /**
015     * This class implements all projections for French departements in the Caribbean Sea and
016     * Indian Ocean using the UTM transvers Mercator projection and specific geodesic settings.
017     *
018     */
019    public class UTM_France_DOM extends AbstractProjection {
020    
021        private final static Bounds FortMarigotBounds = new Bounds( new LatLon(17.6,-63.25), new LatLon(18.5,-62.5), false);
022        private final static Bounds SainteAnneBounds = new Bounds( new LatLon(15.8,-61.9), new LatLon(16.6,-60.9), false);
023        private final static Bounds MartiniqueBounds = new Bounds( new LatLon(14.25,-61.25), new LatLon(15.025,-60.725), false);
024        private final static Bounds ReunionBounds = new Bounds( new LatLon(-25.92,37.58), new LatLon(-10.6, 58.27), false);
025        private final static Bounds GuyaneBounds = new Bounds( new LatLon(2.16 , -54.0), new LatLon(9.06 , -49.62), false);
026        private final static Bounds[] utmBounds = { FortMarigotBounds, SainteAnneBounds, MartiniqueBounds, ReunionBounds, GuyaneBounds };
027    
028        private final static Integer FortMarigotEPSG = 2969;
029        private final static Integer SainteAnneEPSG = 2970;
030        private final static Integer MartiniqueEPSG = 2973;
031        private final static Integer ReunionEPSG = 2975;
032        private final static Integer GuyaneEPSG = 2972;
033        public final static Integer[] utmEPSGs = { FortMarigotEPSG, SainteAnneEPSG, MartiniqueEPSG, ReunionEPSG, GuyaneEPSG };
034    
035        private final static Datum FortMarigotDatum = new ThreeParameterDatum("FortMarigot Datum", null, Ellipsoid.hayford, 136.596, 248.148, -429.789);
036        private final static Datum SainteAnneDatum = new SevenParameterDatum("SainteAnne Datum", null, Ellipsoid.hayford, -472.29, -5.63, -304.12, 0.4362, -0.8374, 0.2563, 1.8984);
037        private final static Datum MartiniqueDatum = new SevenParameterDatum("Martinique Datum", null, Ellipsoid.hayford, 126.926, 547.939, 130.409, -2.78670, 5.16124, -0.85844, 13.82265);
038        private final static Datum ReunionDatum = GRS80Datum.INSTANCE;
039        private final static Datum GuyaneDatum = GRS80Datum.INSTANCE;
040        private final static Datum[] utmDatums = { FortMarigotDatum, SainteAnneDatum, MartiniqueDatum, ReunionDatum, GuyaneDatum };
041    
042        private final static int[] utmZones = { 20, 20, 20, 40, 22 };
043    
044        /**
045         * UTM zone (from 1 to 60)
046         */
047        private static int zone;
048        /**
049         * whether north or south hemisphere
050         */
051        private boolean isNorth;
052    
053        public static final int DEFAULT_GEODESIC = 0;
054    
055        public int currentGeodesic;
056    
057    
058        public UTM_France_DOM() {
059            this(DEFAULT_GEODESIC);
060        }
061    
062        public UTM_France_DOM(int currentGeodesic) {
063            if (currentGeodesic < 0 || currentGeodesic >= 5)
064                throw new IllegalArgumentException();
065            this.currentGeodesic = currentGeodesic;
066            datum = utmDatums[currentGeodesic];
067            ellps = datum.getEllipsoid();
068            proj = new org.openstreetmap.josm.data.projection.proj.TransverseMercator();
069            try {
070                proj.initialize(new ProjParameters() {{ ellps = UTM_France_DOM.this.ellps; }});
071            } catch (ProjectionConfigurationException e) {
072                throw new RuntimeException(e);
073            }
074            isNorth = currentGeodesic != 3;
075            zone = utmZones[currentGeodesic];
076            x_0 = 500000;
077            y_0 = isNorth ? 0.0 : 10000000.0;
078            lon_0 = 6 * zone - 183;
079            k_0 = 0.9996;
080        }
081    
082        public int getCurrentGeodesic() {
083            return currentGeodesic;
084        }
085    
086        @Override
087        public String toString() {
088            return tr("UTM France (DOM)");
089        }
090    
091        @Override
092        public String getCacheDirectoryName() {
093            return this.toString();
094        }
095    
096        @Override
097        public Bounds getWorldBoundsLatLon() {
098            return utmBounds[currentGeodesic];
099        }
100    
101        @Override
102        public Integer getEpsgCode() {
103            return utmEPSGs[currentGeodesic];
104        }
105    
106        @Override
107        public int hashCode() {
108            return getClass().getName().hashCode()+currentGeodesic; // our only real variable
109        }
110    
111    }