Changeset 8609 in josm for trunk/src


Ignore:
Timestamp:
2015-07-21T22:39:57+02:00 (9 years ago)
Author:
bastiK
Message:

add proj.4 syntax "+proj=utm +zone=... [+south]" for CustomProjection (see #11701)

This is just a shortcut for a set of already supported parameters.

File:
1 edited

Legend:

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

    r8608 r8609  
    103103        /** definition of axis for projection */
    104104        axis("axis", true),
     105        /** UTM zone */
     106        zone("zone", true),
     107        /** indicate southern hemisphere for UTM */
     108        south("south", false),
    105109        // JOSM extensions, not present in PROJ.4
    106110        wmssrs("wmssrs", true),
     
    185189            datum = parseDatum(parameters, ellps);
    186190            proj = parseProjection(parameters, ellps);
     191            // "utm" is a shortcut for a set of parameters
     192            if ("utm".equals(parameters.get(Param.proj.key))) {
     193                String zoneStr = parameters.get(Param.zone.key);
     194                Integer zone;
     195                if (zoneStr == null)
     196                    throw new ProjectionConfigurationException(tr("UTM projection (''+proj=utm'') requires ''+zone=...'' parameter."));
     197                try {
     198                    zone = Integer.parseInt(zoneStr);
     199                } catch (NumberFormatException e) {
     200                    zone = null;
     201                }
     202                if (zone == null || zone < 1 || zone > 60)
     203                    throw new ProjectionConfigurationException(tr("Expected integer value in range 1-60 for ''+zone=...'' paramter."));
     204                this.lon0 = 6 * zone - 183;
     205                this.k0 = 0.9996;
     206                this.x0 = 500000;
     207                this.y0 = parameters.containsKey(Param.south.key) ? 10000000 : 0;
     208            }
    187209            String s = parameters.get(Param.x_0.key);
    188210            if (s != null) {
     
    400422        if (id == null) throw new ProjectionConfigurationException(tr("Projection required (+proj=*)"));
    401423
     424        // "utm" is not a real projection, but a shortcut for a set of parameters
     425        if ("utm".equals(id)) {
     426            id = "tmerc";
     427        }
    402428        Proj proj =  Projections.getBaseProjection(id);
    403429        if (proj == null) throw new ProjectionConfigurationException(tr("Unknown projection identifier: ''{0}''", id));
     
    436462    public static double parseDouble(Map<String, String> parameters, String parameterName) throws ProjectionConfigurationException {
    437463        if (!parameters.containsKey(parameterName))
    438             throw new IllegalArgumentException(tr("Unknown parameter ''{0}''", parameterName));
     464            throw new ProjectionConfigurationException(tr("Unknown parameter ''{0}''", parameterName));
    439465        String doubleStr = parameters.get(parameterName);
    440466        if (doubleStr == null)
Note: See TracChangeset for help on using the changeset viewer.