Changeset 5072 in josm


Ignore:
Timestamp:
2012-03-11T19:29:20+01:00 (12 years ago)
Author:
bastiK
Message:

basic support for custom projections (see #7495)

Location:
trunk/src/org/openstreetmap/josm/data/projection
Files:
1 added
5 edited

Legend:

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

    r5066 r5072  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.data.projection;
    23
  • trunk/src/org/openstreetmap/josm/data/projection/BelgianLambert2008.java

    r5066 r5072  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.data.projection;
    23
  • trunk/src/org/openstreetmap/josm/data/projection/Ellipsoid.java

    r5067 r5072  
    99
    1010import org.openstreetmap.josm.data.coor.LatLon;
    11 import java.util.List;
    12 import java.util.ArrayList;
    1311
    1412/**
     
    127125    public static Ellipsoid create_a_rf(double a, double rf) {
    128126        return create_a_f(a, 1.0 / rf);
     127    }
     128
     129    @Override
     130    public String toString() {
     131        return "Ellipsoid{a="+a+", b="+b+"}";
    129132    }
    130133
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r5022 r5072  
    44import java.util.ArrayList;
    55import java.util.Arrays;
     6import java.util.HashMap;
     7import java.util.Map;
    68
    79import org.openstreetmap.josm.Main;
    810import org.openstreetmap.josm.data.coor.EastNorth;
    911import org.openstreetmap.josm.data.coor.LatLon;
     12import org.openstreetmap.josm.data.projection.datum.Datum;
     13import org.openstreetmap.josm.data.projection.datum.WGS84Datum;
     14import org.openstreetmap.josm.data.projection.proj.LambertConformalConic;
     15import org.openstreetmap.josm.data.projection.proj.Proj;
     16import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator;
     17import org.openstreetmap.josm.data.projection.proj.TransverseMercator;
     18import org.openstreetmap.josm.tools.CheckParameterUtil;
    1019
    1120/**
     
    2332                new Mercator(),
    2433                new UTM(),
    25                 // regional - alphabetical order by country name
    26                 new GaussKrueger(),
    27                 new BelgianLambert1972(),
    28                 new BelgianLambert2008(),
    29                 new LambertEST(),
    30                 new Lambert(),
    31                 new Lambert93(),
    32                 new LambertCC9Zones(),
    33                 new UTM_France_DOM(),
    34                 new TransverseMercatorLV(),
    35                 new Puwg(),
    36                 new Epsg3008(), // SWEREF99 13 30
    37                 new SwissGrid(),
     34                // regional - alphabetical order by country code
     35                new BelgianLambert1972(),   // BE
     36                new BelgianLambert2008(),   // BE
     37                new SwissGrid(),            // CH
     38                new GaussKrueger(),         // DE
     39                new LambertEST(),           // EE
     40                new Lambert(),              // FR
     41                new Lambert93(),            // FR
     42                new LambertCC9Zones(),      // FR
     43                new UTM_France_DOM(),       // FR
     44                new TransverseMercatorLV(), // LV
     45                new Puwg(),                 // PL
     46                new Epsg3008(),             // SE
    3847        }));
     48
     49    static {
     50        if (Main.pref.getBoolean("customprojection")) {
     51            addProjection(new CustomProjection());
     52        }
     53    }
    3954
    4055    public static ArrayList<Projection> getProjections() {
     
    4459    /**
    4560     * Adds a new projection to the list of known projections.
    46      * 
     61     *
    4762     * For Plugins authors: make sure your plugin is an early plugin, i.e. put
    4863     * Plugin-Early=true in your Manifest.
     
    5267    }
    5368
    54     static public EastNorth project(LatLon ll) {
     69    public static EastNorth project(LatLon ll) {
    5570        if (ll == null) return null;
    5671        return Main.getProjection().latlon2eastNorth(ll);
    5772    }
    5873
    59     static public LatLon inverseProject(EastNorth en) {
     74    public static LatLon inverseProject(EastNorth en) {
    6075        if (en == null) return null;
    6176        return Main.getProjection().eastNorth2latlon(en);
    6277    }
     78
     79    /*********************************
     80     * Registry for custom projection
     81     *
     82     * should be compatible to PROJ.4
     83     */
     84
     85    private static Map<String, Ellipsoid> ellipsoids = new HashMap<String, Ellipsoid>();
     86    private static Map<String, Class<? extends Proj>> projs = new HashMap<String, Class<? extends Proj>>();
     87    private static Map<String, Datum> datums = new HashMap<String, Datum>();
     88
     89    static {
     90        ellipsoids.put("intl", Ellipsoid.hayford);
     91        ellipsoids.put("GRS80", Ellipsoid.GRS80);
     92        ellipsoids.put("WGS84", Ellipsoid.WGS84);
     93        ellipsoids.put("bessel", Ellipsoid.Bessel1841);
     94
     95        projs.put("merc", org.openstreetmap.josm.data.projection.proj.Mercator.class);
     96        projs.put("lcc", LambertConformalConic.class);
     97        projs.put("somerc", SwissObliqueMercator.class);
     98        projs.put("tmerc", TransverseMercator.class);
     99
     100        datums.put("WGS84", WGS84Datum.INSTANCE);
     101    }
     102
     103    public static Ellipsoid getEllipsoid(String id) {
     104        return ellipsoids.get(id);
     105    }
     106
     107    public static Proj getProjection(String id) {
     108        Class<? extends Proj> projClass = projs.get(id);
     109        if (projClass == null) return null;
     110        Proj proj = null;
     111        try {
     112            proj = projClass.newInstance();
     113        } catch (InstantiationException e) {
     114            throw new RuntimeException(e);
     115        } catch (IllegalAccessException e) {
     116            throw new RuntimeException(e);
     117        }
     118        return proj;
     119    }
     120
     121    public static Datum getDatum(String id) {
     122        return datums.get(id);
     123    }
    63124}
  • trunk/src/org/openstreetmap/josm/data/projection/datum/CentricDatum.java

    r4285 r5072  
    1414        super(name, proj4Id, ellps);
    1515    }
    16    
     16
    1717    @Override
    1818    public LatLon toWGS84(LatLon ll) {
     
    2424        return this.ellps.cart2LatLon(Ellipsoid.WGS84.latLon2Cart(ll));
    2525    }
    26    
     26
     27    @Override
     28    public String toString() {
     29        return "CentricDatum{ellipsoid="+ellps+"}";
     30    }
    2731}
Note: See TracChangeset for help on using the changeset viewer.