[12735] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.coor.conversion;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 5 |
|
---|
| 6 | import java.text.DecimalFormat;
|
---|
| 7 |
|
---|
| 8 | import org.openstreetmap.josm.data.coor.ILatLon;
|
---|
[12846] | 9 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
[12735] | 10 |
|
---|
| 11 | /**
|
---|
| 12 | * Coordinate format that converts a coordinate to degrees and minutes (nautical format).
|
---|
| 13 | * @since 12735
|
---|
| 14 | */
|
---|
| 15 | public class NauticalCoordinateFormat extends AbstractCoordinateFormat {
|
---|
| 16 | private static final DecimalFormat DM_MINUTE_FORMATTER = new DecimalFormat(
|
---|
[12846] | 17 | Config.getPref() == null ? "00.000" : Config.getPref().get("latlon.dm.decimal-format", "00.000"));
|
---|
[12735] | 18 | private static final String DM60 = DM_MINUTE_FORMATTER.format(60.0);
|
---|
| 19 | private static final String DM00 = DM_MINUTE_FORMATTER.format(0.0);
|
---|
| 20 |
|
---|
[12741] | 21 | /**
|
---|
| 22 | * The unique instance.
|
---|
| 23 | */
|
---|
[12739] | 24 | public static final NauticalCoordinateFormat INSTANCE = new NauticalCoordinateFormat();
|
---|
[12735] | 25 |
|
---|
[12738] | 26 | protected NauticalCoordinateFormat() {
|
---|
[12735] | 27 | super("NAUTICAL", tr("deg\u00B0 min'' (Nautical)"));
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | @Override
|
---|
| 31 | public String latToString(ILatLon ll) {
|
---|
| 32 | return degreesMinutes(ll.lat()) + ((ll.lat() < 0) ? SOUTH : NORTH);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | @Override
|
---|
| 36 | public String lonToString(ILatLon ll) {
|
---|
| 37 | return degreesMinutes(ll.lon()) + ((ll.lon() < 0) ? WEST : EAST);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * Replies the coordinate in degrees/minutes format
|
---|
| 42 | * @param pCoordinate The coordinate to convert
|
---|
| 43 | * @return The coordinate in degrees/minutes format
|
---|
| 44 | * @since 12537
|
---|
| 45 | */
|
---|
| 46 | public static String degreesMinutes(double pCoordinate) {
|
---|
| 47 |
|
---|
| 48 | double tAbsCoord = Math.abs(pCoordinate);
|
---|
| 49 | int tDegree = (int) tAbsCoord;
|
---|
| 50 | double tMinutes = (tAbsCoord - tDegree) * 60;
|
---|
| 51 |
|
---|
| 52 | String sDegrees = Integer.toString(tDegree);
|
---|
| 53 | String sMinutes = DM_MINUTE_FORMATTER.format(tMinutes);
|
---|
| 54 |
|
---|
| 55 | if (sMinutes.equals(DM60)) {
|
---|
| 56 | sMinutes = DM00;
|
---|
| 57 | sDegrees = Integer.toString(tDegree+1);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | return sDegrees + '\u00B0' + sMinutes + '\'';
|
---|
| 61 | }
|
---|
| 62 | }
|
---|