Changeset 5227 in josm


Ignore:
Timestamp:
May 10, 2012 4:12:42 PM (13 months ago)
Author:
bastiK
Message:

finish custom projection

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

Legend:

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

    r5226 r5227  
    55 
    66import java.util.ArrayList; 
     7import java.util.Arrays; 
    78import java.util.HashMap; 
     9import java.util.HashSet; 
    810import java.util.List; 
    911import java.util.Map; 
     12import java.util.Set; 
    1013import java.util.regex.Matcher; 
    1114import java.util.regex.Pattern; 
     
    1316import org.openstreetmap.josm.data.Bounds; 
    1417import org.openstreetmap.josm.data.coor.LatLon; 
     18import org.openstreetmap.josm.data.projection.CustomProjection.Param; 
    1519import org.openstreetmap.josm.data.projection.datum.CentricDatum; 
    1620import org.openstreetmap.josm.data.projection.datum.Datum; 
     
    3842    protected String pref = null; 
    3943 
     44    protected static class Param { 
     45        public String key; 
     46        public boolean hasValue; 
     47 
     48        public final static Param x_0 = new Param("x_0", true); 
     49        public final static Param y_0 = new Param("y_0", true); 
     50        public final static Param lon_0 = new Param("lon_0", true); 
     51        public final static Param k_0 = new Param("k_0", true); 
     52        public final static Param ellps = new Param("ellps", true); 
     53        public final static Param a = new Param("a", true); 
     54        public final static Param es = new Param("es", true); 
     55        public final static Param rf = new Param("rf", true); 
     56        public final static Param f = new Param("f", true); 
     57        public final static Param b = new Param("b", true); 
     58        public final static Param datum = new Param("datum", true); 
     59        public final static Param towgs84 = new Param("towgs84", true); 
     60        public final static Param nadgrids = new Param("nadgrids", true); 
     61        public final static Param proj = new Param("proj", true); 
     62        public final static Param lat_0 = new Param("lat_0", true); 
     63        public final static Param lat_1 = new Param("lat_1", true); 
     64        public final static Param lat_2 = new Param("lat_2", true); 
     65 
     66        public final static Set<Param> params = new HashSet<Param>(Arrays.asList( 
     67                x_0, y_0, lon_0, k_0, ellps, a, es, rf, f, b, datum, towgs84, 
     68                nadgrids, proj, lat_0, lat_1, lat_2 
     69        )); 
     70 
     71        public final static Map<String, Param> paramsByKey = new HashMap<String, Param>(); 
     72        static { 
     73            for (Param p : params) { 
     74                paramsByKey.put(p.key, p); 
     75            } 
     76        } 
     77 
     78        public Param(String key, boolean hasValue) { 
     79            this.key = key; 
     80            this.hasValue = hasValue; 
     81        } 
     82    } 
     83 
    4084    public void update(String pref) throws ProjectionConfigurationException { 
    4185        if (pref == null) { 
     
    4791            Map<String, String> parameters = new HashMap<String, String>(); 
    4892            String[] parts = pref.trim().split("\\s+"); 
     93            if (pref.trim().isEmpty()) { 
     94                parts = new String[0]; 
     95            } 
    4996            for (int i = 0; i < parts.length; i++) { 
    5097                String part = parts[i]; 
     
    58105                        value = m.group(3); 
    59106                    } 
     107                    if (!Param.paramsByKey.containsKey(key)) 
     108                        throw new ProjectionConfigurationException(tr("Unkown parameter: ''{0}''.", key)); 
     109                    if (Param.paramsByKey.get(key).hasValue && value == null) 
     110                        throw new ProjectionConfigurationException(tr("Value expected for parameter ''{0}''.", key)); 
     111                    if (!Param.paramsByKey.get(key).hasValue && value != null) 
     112                        throw new ProjectionConfigurationException(tr("No value expected for parameter ''{0}''.", key)); 
    60113                    parameters.put(key, value); 
    61114                } else 
     
    65118            datum = parseDatum(parameters, ellps); 
    66119            proj = parseProjection(parameters, ellps); 
    67             String s = parameters.get("x_0"); 
     120            String s = parameters.get(Param.x_0.key); 
    68121            if (s != null) { 
    69                 this.x_0 = parseDouble(s, "x_0"); 
    70             } 
    71             s = parameters.get("y_0"); 
     122                this.x_0 = parseDouble(s, Param.x_0.key); 
     123            } 
     124            s = parameters.get(Param.y_0.key); 
    72125            if (s != null) { 
    73                 this.y_0 = parseDouble(s, "y_0"); 
    74             } 
    75             s = parameters.get("lon_0"); 
     126                this.y_0 = parseDouble(s, Param.x_0.key); 
     127            } 
     128            s = parameters.get(Param.lon_0.key); 
    76129            if (s != null) { 
    77                 this.lon_0 = parseAngle(s, "lon_0"); 
    78             } 
    79             s = parameters.get("k_0"); 
     130                this.lon_0 = parseAngle(s, Param.x_0.key); 
     131            } 
     132            s = parameters.get(Param.k_0.key); 
    80133            if (s != null) { 
    81                 this.k_0 = parseDouble(s, "k_0"); 
     134                this.k_0 = parseDouble(s, Param.x_0.key); 
    82135            } 
    83136            this.pref = pref; 
     
    86139 
    87140    public Ellipsoid parseEllipsoid(Map<String, String> parameters) throws ProjectionConfigurationException { 
    88         String code = parameters.get("ellps"); 
     141        String code = parameters.get(Param.ellps.key); 
    89142        if (code != null) { 
    90143            Ellipsoid ellipsoid = Projections.getEllipsoid(code); 
     
    95148            } 
    96149        } 
    97         String s = parameters.get("a"); 
     150        String s = parameters.get(Param.a.key); 
    98151        if (s != null) { 
    99             double a = parseDouble(s, "a"); 
    100             if (parameters.get("es") != null) { 
    101                 double es = parseDouble(parameters, "es"); 
     152            double a = parseDouble(s, Param.a.key); 
     153            if (parameters.get(Param.es.key) != null) { 
     154                double es = parseDouble(parameters, Param.es.key); 
    102155                return Ellipsoid.create_a_es(a, es); 
    103156            } 
    104             if (parameters.get("rf") != null) { 
    105                 double rf = parseDouble(parameters, "rf"); 
     157            if (parameters.get(Param.rf.key) != null) { 
     158                double rf = parseDouble(parameters, Param.rf.key); 
    106159                return Ellipsoid.create_a_rf(a, rf); 
    107160            } 
    108             if (parameters.get("f") != null) { 
    109                 double f = parseDouble(parameters, "f"); 
     161            if (parameters.get(Param.f.key) != null) { 
     162                double f = parseDouble(parameters, Param.f.key); 
    110163                return Ellipsoid.create_a_f(a, f); 
    111164            } 
    112             if (parameters.get("b") != null) { 
    113                 double b = parseDouble(parameters, "b"); 
     165            if (parameters.get(Param.b.key) != null) { 
     166                double b = parseDouble(parameters, Param.b.key); 
    114167                return Ellipsoid.create_a_b(a, b); 
    115168            } 
    116169        } 
    117         if (parameters.containsKey("a") || 
    118                 parameters.containsKey("es") || 
    119                 parameters.containsKey("rf") || 
    120                 parameters.containsKey("f") || 
    121                 parameters.containsKey("b")) 
     170        if (parameters.containsKey(Param.a.key) || 
     171                parameters.containsKey(Param.es.key) || 
     172                parameters.containsKey(Param.rf.key) || 
     173                parameters.containsKey(Param.f.key) || 
     174                parameters.containsKey(Param.b.key)) 
    122175            throw new ProjectionConfigurationException(tr("Combination of ellipsoid parameters is not supported.")); 
    123176        // nothing specified, use WGS84 as default 
     
    126179 
    127180    public Datum parseDatum(Map<String, String> parameters, Ellipsoid ellps) throws ProjectionConfigurationException { 
    128         String nadgridsId = parameters.get("nadgrids"); 
     181        String nadgridsId = parameters.get(Param.nadgrids.key); 
    129182        if (nadgridsId != null) { 
    130183            NTV2GridShiftFileWrapper nadgrids = Projections.getNadgrids(nadgridsId); 
     
    134187        } 
    135188 
    136         String towgs84 = parameters.get("towgs84"); 
     189        String towgs84 = parameters.get(Param.towgs84.key); 
    137190        if (towgs84 != null) 
    138191            return parseToWGS84(towgs84, ellps); 
    139192 
    140         String datumId = parameters.get("datum"); 
     193        String datumId = parameters.get(Param.datum.key); 
    141194        if (datumId != null) { 
    142195            Datum datum = Projections.getDatum(datumId); 
     
    189242 
    190243    public Proj parseProjection(Map<String, String> parameters, Ellipsoid ellps) throws ProjectionConfigurationException { 
    191         String id = (String) parameters.get("proj"); 
     244        String id = (String) parameters.get(Param.proj.key); 
    192245        if (id == null) throw new ProjectionConfigurationException(tr("Projection required (+proj=*)")); 
    193246 
    194         Proj proj =  Projections.getProjection(id); 
     247        Proj proj =  Projections.getBaseProjection(id); 
    195248        if (proj == null) throw new ProjectionConfigurationException(tr("Unkown projection identifier: ''{0}''", id)); 
    196249 
     
    200253 
    201254        String s; 
    202         s = parameters.get("lat_0"); 
     255        s = parameters.get(Param.lat_0.key); 
    203256        if (s != null) { 
    204             projParams.lat_0 = parseAngle(s, "lat_0"); 
    205         } 
    206         s = parameters.get("lat_1"); 
     257            projParams.lat_0 = parseAngle(s, Param.lat_0.key); 
     258        } 
     259        s = parameters.get(Param.lat_1.key); 
    207260        if (s != null) { 
    208             projParams.lat_1 = parseAngle(s, "lat_1"); 
    209         } 
    210         s = parameters.get("lat_2"); 
     261            projParams.lat_1 = parseAngle(s, Param.lat_1.key); 
     262        } 
     263        s = parameters.get(Param.lat_2.key); 
    211264        if (s != null) { 
    212             projParams.lat_2 = parseAngle(s, "lat_2"); 
     265            projParams.lat_2 = parseAngle(s, Param.lat_2.key); 
    213266        } 
    214267        proj.initialize(projParams); 
     
    328381    @Override 
    329382    public String toString() { 
    330         return tr("Custom Projection (from PROJ.4 string)"); 
     383        return tr("Custom Projection"); 
    331384    } 
    332385} 
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjectionPrefGui.java

    r5226 r5227  
    99import java.awt.event.ActionEvent; 
    1010import java.awt.event.ActionListener; 
     11import java.util.ArrayList; 
    1112import java.util.Collection; 
    1213import java.util.Collections; 
    13 import java.util.logging.Level; 
    14 import java.util.logging.Logger; 
     14import java.util.List; 
     15import java.util.Map; 
    1516 
    1617import javax.swing.JButton; 
     18import javax.swing.JComponent; 
    1719import javax.swing.JLabel; 
    1820import javax.swing.JPanel; 
    1921import javax.swing.JTextField; 
    2022 
     23import org.openstreetmap.josm.gui.ExtendedDialog; 
    2124import org.openstreetmap.josm.gui.preferences.projection.SubPrefsOptions; 
    2225import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; 
     
    2427import org.openstreetmap.josm.tools.GBC; 
    2528import org.openstreetmap.josm.tools.ImageProvider; 
     29import org.openstreetmap.josm.tools.Utils; 
    2630 
    2731public class CustomProjectionPrefGui extends CustomProjection implements ProjectionSubPrefs, SubPrefsOptions { 
     
    2933    @Override 
    3034    public void setupPreferencePanel(JPanel p, ActionListener listener) { 
    31         final JTextField input = new JTextField(pref == null ? "" : pref, 30); 
    32         final HtmlPanel errorsPanel = new HtmlPanel(); 
    33         errorsPanel.setVisible(false); 
    34         final JLabel valStatus = new JLabel(); 
    35         valStatus.setVisible(false); 
    36  
    37         final AbstractTextComponentValidator val = new AbstractTextComponentValidator(input, false, false, false) { 
    38  
    39             private String error; 
    40  
    41             @Override 
    42             public void validate() { 
    43                 if (!isValid()) { 
    44                     feedbackInvalid(tr("Invalid projection configuration: {0}",error)); 
    45                 } else { 
    46                     feedbackValid(tr("Projection configuration is valid.")); 
    47                 } 
    48             } 
    49  
    50             @Override 
    51             public boolean isValid() { 
    52                 try { 
    53                     CustomProjection test = new CustomProjection(); 
    54                     test.update(input.getText()); 
    55                 } catch (ProjectionConfigurationException ex) { 
    56                     error = ex.getMessage(); 
    57                     valStatus.setIcon(ImageProvider.get("data", "error.png")); 
     35        JPanel inner = new PreferencePanel(); 
     36        p.setLayout(new GridBagLayout()); 
     37        p.add(inner, GBC.std().fill(GBC.HORIZONTAL)); 
     38    } 
     39 
     40    private class PreferencePanel extends JPanel { 
     41 
     42        public final JTextField input; 
     43 
     44        public PreferencePanel() { 
     45            input = new JTextField(pref == null ? "" : pref, 30); 
     46            build(); 
     47        } 
     48 
     49        private void build() { 
     50            final HtmlPanel errorsPanel = new HtmlPanel(); 
     51            errorsPanel.setVisible(false); 
     52            final JLabel valStatus = new JLabel(); 
     53            valStatus.setVisible(false); 
     54 
     55            final AbstractTextComponentValidator val = new AbstractTextComponentValidator(input, false, false, false) { 
     56 
     57                private String error; 
     58 
     59                @Override 
     60                public void validate() { 
     61                    if (!isValid()) { 
     62                        feedbackInvalid(tr("Invalid projection configuration: {0}",error)); 
     63                    } else { 
     64                        feedbackValid(tr("Projection configuration is valid.")); 
     65                    } 
     66                } 
     67 
     68                @Override 
     69                public boolean isValid() { 
     70                    try { 
     71                        CustomProjection test = new CustomProjection(); 
     72                        test.update(input.getText()); 
     73                    } catch (ProjectionConfigurationException ex) { 
     74                        error = ex.getMessage(); 
     75                        valStatus.setIcon(ImageProvider.get("data", "error.png")); 
     76                        valStatus.setVisible(true); 
     77                        errorsPanel.setText(error); 
     78                        errorsPanel.setVisible(true); 
     79                        return false; 
     80                    } 
     81                    errorsPanel.setVisible(false); 
     82                    valStatus.setIcon(ImageProvider.get("misc", "green_check.png")); 
    5883                    valStatus.setVisible(true); 
    59                     errorsPanel.setText(error); 
    60                     errorsPanel.setVisible(true); 
    61                     return false; 
    62                 } 
    63                 errorsPanel.setVisible(false); 
    64                 valStatus.setIcon(ImageProvider.get("misc", "green_check.png")); 
    65                 valStatus.setVisible(true); 
    66                 return true; 
    67             } 
    68  
    69         }; 
    70  
    71         JButton btnCheck = new JButton(tr("Validate")); 
    72         btnCheck.addActionListener(new ActionListener() { 
    73             @Override 
    74             public void actionPerformed(ActionEvent e) { 
    75                 val.validate(); 
    76             } 
    77         }); 
    78         btnCheck.setLayout(new BorderLayout()); 
    79         btnCheck.setMargin(new Insets(-1,0,-1,0)); 
    80  
    81         p.setLayout(new GridBagLayout()); 
    82         p.add(input, GBC.std().fill(GBC.HORIZONTAL).insets(0, 0, 5, 5)); 
    83         p.add(btnCheck, GBC.eol()); 
    84         JPanel p2 = new JPanel(new GridBagLayout()); 
    85         p2.add(valStatus, GBC.std().anchor(GBC.WEST).weight(0.0001, 0)); 
    86         p2.add(errorsPanel, GBC.eol().fill(GBC.HORIZONTAL)); 
    87         p.add(p2, GBC.eol().fill(GBC.HORIZONTAL)); 
     84                    return true; 
     85                } 
     86 
     87            }; 
     88 
     89            JButton btnCheck = new JButton(tr("Validate")); 
     90            btnCheck.addActionListener(new ActionListener() { 
     91                @Override 
     92                public void actionPerformed(ActionEvent e) { 
     93                    val.validate(); 
     94                } 
     95            }); 
     96            btnCheck.setLayout(new BorderLayout()); 
     97            btnCheck.setMargin(new Insets(-1,0,-1,0)); 
     98 
     99            JButton btnInfo = new JButton(tr("Parameter information...")); 
     100            btnInfo.addActionListener(new ActionListener() { 
     101                @Override 
     102                public void actionPerformed(ActionEvent e) { 
     103                    ParameterInfoDialog dlg = new ParameterInfoDialog(); 
     104                    dlg.showDialog(); 
     105                    dlg.toFront(); 
     106                } 
     107            }); 
     108 
     109            this.setLayout(new GridBagLayout()); 
     110            JPanel p2 = new JPanel(new GridBagLayout()); 
     111            p2.add(input, GBC.std().fill(GBC.HORIZONTAL).insets(0, 20, 5, 5)); 
     112            p2.add(btnCheck, GBC.eol().insets(0, 20, 0, 5)); 
     113            this.add(p2, GBC.eol().fill(GBC.HORIZONTAL)); 
     114            p2 = new JPanel(new GridBagLayout()); 
     115            p2.add(valStatus, GBC.std().anchor(GBC.WEST).weight(0.0001, 0)); 
     116            p2.add(errorsPanel, GBC.eol().fill(GBC.HORIZONTAL)); 
     117            this.add(p2, GBC.eol().fill(GBC.HORIZONTAL)); 
     118            p2 = new JPanel(new GridBagLayout()); 
     119            p2.add(btnInfo, GBC.std().insets(0, 20, 0, 0)); 
     120            p2.add(GBC.glue(1, 0), GBC.eol().fill(GBC.HORIZONTAL)); 
     121            this.add(p2, GBC.eol().fill(GBC.HORIZONTAL)); 
     122        } 
     123    } 
     124 
     125    public class ParameterInfoDialog extends ExtendedDialog { 
     126 
     127        public ParameterInfoDialog() { 
     128            super(null, tr("Parameter information"), new String[] { tr("Close") }, false); 
     129            setContent(build()); 
     130        } 
     131 
     132        private JComponent build() { 
     133            StringBuilder s = new StringBuilder(); 
     134            s.append("<b>+proj=...</b> - <i>"+tr("Projection name")+"</i><br>"); 
     135            s.append("&nbsp;&nbsp;&nbsp;&nbsp;"+tr("Supported values:")+" "); 
     136            s.append(listKeys(Projections.projs)+"<br>"); 
     137            s.append("<b>+lat_0=..., +lat_1=..., +lat_2=...</b> - <i>"+tr("Projection parameters")+"</i><br>"); 
     138            s.append("<b>+x_0=..., +y_0=...</b> - <i>"+tr("False easting and false northing")+"</i><br>"); 
     139            s.append("<b>+lon_0=...</b> - <i>"+tr("Central meridian")+"</i><br>"); 
     140            s.append("<b>+k_0=...</b> - <i>"+tr("Scaling factor")+"</i><br>"); 
     141            s.append("<b>+ellps=...</b> - <i>"+tr("Ellipsoid name")+"</i><br>"); 
     142            s.append("&nbsp;&nbsp;&nbsp;&nbsp;"+tr("Supported values:")+" "); 
     143            s.append(listKeys(Projections.ellipsoids)+"<br>"); 
     144            s.append("<b>+a=..., +b=..., +rf=..., +f=..., +es=...</b> - <i>"+tr("Ellipsoid parameters")+"</i><br>"); 
     145            s.append("<b>+datum=...</b> - <i>"+tr("Datum name")+"</i><br>"); 
     146            s.append("&nbsp;&nbsp;&nbsp;&nbsp;"+tr("Supported values:")+" "); 
     147            s.append(listKeys(Projections.datums)+"<br>"); 
     148            s.append("<b>+towgs84=...</b> - <i>"+tr("3 or 7 term datum transform parameters")+"</i><br>"); 
     149            s.append("<b>+nadgrids=...</b> - <i>"+tr("NTv2 grid file")+"</i><br>"); 
     150            s.append("&nbsp;&nbsp;&nbsp;&nbsp;"+tr("Build-in:")+" "); 
     151            s.append(listKeys(Projections.nadgrids)+"<br>"); 
     152 
     153            HtmlPanel info = new HtmlPanel(s.toString()); 
     154            return info; 
     155        } 
     156 
     157        private String listKeys(Map<String, ?> map) { 
     158            List<String> keys = new ArrayList<String>(map.keySet()); 
     159            Collections.sort(keys); 
     160            return Utils.join(", ", keys); 
     161        } 
    88162    } 
    89163 
    90164    @Override 
    91165    public Collection<String> getPreferences(JPanel p) { 
    92         Object prefTf = p.getComponent(0); 
    93         if (!(prefTf instanceof JTextField)) 
    94             return null; 
    95         String pref = ((JTextField) prefTf).getText(); 
     166        PreferencePanel prefPanel = (PreferencePanel) p.getComponent(0); 
     167        String pref = prefPanel.input.getText(); 
    96168        return Collections.singleton(pref); 
    97169    } 
     
    100172    public void setPreferences(Collection<String> args) { 
    101173        try { 
     174            if (args == null || args.isEmpty()) throw new ProjectionConfigurationException(); 
    102175            update(args.iterator().next()); 
    103176        } catch (ProjectionConfigurationException ex) { 
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r5226 r5227  
    1313import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper; 
    1414import org.openstreetmap.josm.data.projection.datum.WGS84Datum; 
     15import org.openstreetmap.josm.data.projection.proj.ClassProjFactory; 
    1516import org.openstreetmap.josm.data.projection.proj.LambertConformalConic; 
     17import org.openstreetmap.josm.data.projection.proj.LonLat; 
    1618import org.openstreetmap.josm.data.projection.proj.Proj; 
     19import org.openstreetmap.josm.data.projection.proj.ProjFactory; 
    1720import org.openstreetmap.josm.data.projection.proj.SwissObliqueMercator; 
    1821import org.openstreetmap.josm.data.projection.proj.TransverseMercator; 
     
    4548                new Puwg(),                 // PL 
    4649                new Epsg3008(),             // SE 
     50                new CustomProjectionPrefGui() 
    4751        })); 
    48  
    49     static { 
    50         if (Main.pref.getBoolean("customprojection")) { 
    51             addProjection(new CustomProjectionPrefGui()); 
    52         } 
    53     } 
    5452 
    5553    public static ArrayList<Projection> getProjections() { 
     
    8280     * should be compatible to PROJ.4 
    8381     */ 
    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     private static Map<String, NTV2GridShiftFileWrapper> nadgrids = new HashMap<String, NTV2GridShiftFileWrapper>(); 
     82    public static Map<String, Ellipsoid> ellipsoids = new HashMap<String, Ellipsoid>(); 
     83    public static Map<String, ProjFactory> projs = new HashMap<String, ProjFactory>(); 
     84    public static Map<String, Datum> datums = new HashMap<String, Datum>(); 
     85    public static Map<String, NTV2GridShiftFileWrapper> nadgrids = new HashMap<String, NTV2GridShiftFileWrapper>(); 
    8986 
    9087    static { 
     88        registerBaseProjection("lonlat", LonLat.class, "core"); 
     89        registerBaseProjection("merc", org.openstreetmap.josm.data.projection.proj.Mercator.class, "core"); 
     90        registerBaseProjection("lcc", LambertConformalConic.class, "core"); 
     91        registerBaseProjection("somerc", SwissObliqueMercator.class, "core"); 
     92        registerBaseProjection("tmerc", TransverseMercator.class, "core"); 
     93 
    9194        ellipsoids.put("intl", Ellipsoid.hayford); 
    9295        ellipsoids.put("GRS80", Ellipsoid.GRS80); 
    9396        ellipsoids.put("WGS84", Ellipsoid.WGS84); 
    9497        ellipsoids.put("bessel", Ellipsoid.Bessel1841); 
    95  
    96         projs.put("merc", org.openstreetmap.josm.data.projection.proj.Mercator.class); 
    97         projs.put("lcc", LambertConformalConic.class); 
    98         projs.put("somerc", SwissObliqueMercator.class); 
    99         projs.put("tmerc", TransverseMercator.class); 
    10098 
    10199        datums.put("WGS84", WGS84Datum.INSTANCE); 
     
    105103    } 
    106104 
     105    /** 
     106     * Plugins can register additional base projections. 
     107     * 
     108     * @param id The "official" PROJ.4 id. In case the projection is not supported 
     109     * by PROJ.4, use some prefix, e.g. josm:myproj or gdal:otherproj. 
     110     * @param fac The base projection factory. 
     111     * @param origin Multiple plugins may implement the same base projection. 
     112     * Provide plugin name or similar string, so it be differentiated. 
     113     */ 
     114    public static void registerBaseProjection(String id, ProjFactory fac, String origin) { 
     115        projs.put(id, fac); 
     116    } 
     117 
     118    public static void registerBaseProjection(String id, Class<? extends Proj> projClass, String origin) { 
     119        registerBaseProjection(id, new ClassProjFactory(projClass), origin); 
     120    } 
     121 
     122    public static Proj getBaseProjection(String id) { 
     123        ProjFactory fac = projs.get(id); 
     124        if (fac == null) return null; 
     125        return fac.createInstance(); 
     126    } 
     127 
    107128    public static Ellipsoid getEllipsoid(String id) { 
    108129        return ellipsoids.get(id); 
    109     } 
    110  
    111     public static Proj getProjection(String id) { 
    112         Class<? extends Proj> projClass = projs.get(id); 
    113         if (projClass == null) return null; 
    114         Proj proj = null; 
    115         try { 
    116             proj = projClass.newInstance(); 
    117         } catch (InstantiationException e) { 
    118             throw new RuntimeException(e); 
    119         } catch (IllegalAccessException e) { 
    120             throw new RuntimeException(e); 
    121         } 
    122         return proj; 
    123130    } 
    124131 
Note: See TracChangeset for help on using the changeset viewer.