Changeset 13628 in josm for trunk/src/org


Ignore:
Timestamp:
2018-04-14T16:56:19+02:00 (7 years ago)
Author:
Don-vip
Message:

see #16129 - handle projection definitions with both +datum and +towgs84

File:
1 edited

Legend:

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

    r13598 r13628  
    454454     */
    455455    public Datum parseDatum(Map<String, String> parameters, Ellipsoid ellps) throws ProjectionConfigurationException {
     456        Datum result = null;
    456457        String datumId = parameters.get(Param.datum.key);
    457458        if (datumId != null) {
    458             return Optional.ofNullable(Projections.getDatum(datumId)).orElseThrow(
     459            result = Optional.ofNullable(Projections.getDatum(datumId)).orElseThrow(
    459460                    () -> new ProjectionConfigurationException(tr("Unknown datum identifier: ''{0}''", datumId)));
    460461        }
    461462        if (ellps == null) {
    462             if (parameters.containsKey(Param.no_defs.key))
     463            if (result == null && parameters.containsKey(Param.no_defs.key))
    463464                throw new ProjectionConfigurationException(tr("Ellipsoid required (+ellps=* or +a=*, +b=*)"));
    464465            // nothing specified, use WGS84 as default
    465             ellps = Ellipsoid.WGS84;
     466            ellps = result != null ? result.getEllipsoid() : Ellipsoid.WGS84;
    466467        }
    467468
     
    479480
    480481        String towgs84 = parameters.get(Param.towgs84.key);
    481         if (towgs84 != null)
    482             return parseToWGS84(towgs84, ellps);
    483 
    484         return new NullDatum(null, ellps);
     482        if (towgs84 != null) {
     483            Datum towgs84Datum = parseToWGS84(towgs84, ellps);
     484            if (result == null || towgs84Datum instanceof ThreeParameterDatum || towgs84Datum instanceof SevenParameterDatum) {
     485                // +datum has priority over +towgs84=0,0,0[,0,0,0,0]
     486                return towgs84Datum;
     487            }
     488        }
     489
     490        return result != null ? result : new NullDatum(null, ellps);
    485491    }
    486492
     
    513519        }
    514520        if (isCentric)
    515             return new CentricDatum(null, null, ellps);
     521            return Ellipsoid.WGS84.equals(ellps) ? WGS84Datum.INSTANCE : new CentricDatum(null, null, ellps);
    516522        boolean is3Param = true;
    517523        for (int i = 3; i < towgs84Param.size(); i++) {
Note: See TracChangeset for help on using the changeset viewer.