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.Main;
|
---|
9 | import org.openstreetmap.josm.data.coor.ILatLon;
|
---|
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(
|
---|
17 | Main.pref == null ? "00.000" : Main.pref.get("latlon.dm.decimal-format", "00.000"));
|
---|
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 |
|
---|
21 | public static NauticalCoordinateFormat INSTANCE = new NauticalCoordinateFormat();
|
---|
22 |
|
---|
23 | private NauticalCoordinateFormat() {
|
---|
24 | super("NAUTICAL", tr("deg\u00B0 min'' (Nautical)"));
|
---|
25 | }
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public String latToString(ILatLon ll) {
|
---|
29 | return degreesMinutes(ll.lat()) + ((ll.lat() < 0) ? SOUTH : NORTH);
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public String lonToString(ILatLon ll) {
|
---|
34 | return degreesMinutes(ll.lon()) + ((ll.lon() < 0) ? WEST : EAST);
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Replies the coordinate in degrees/minutes format
|
---|
39 | * @param pCoordinate The coordinate to convert
|
---|
40 | * @return The coordinate in degrees/minutes format
|
---|
41 | * @since 12537
|
---|
42 | */
|
---|
43 | public static String degreesMinutes(double pCoordinate) {
|
---|
44 |
|
---|
45 | double tAbsCoord = Math.abs(pCoordinate);
|
---|
46 | int tDegree = (int) tAbsCoord;
|
---|
47 | double tMinutes = (tAbsCoord - tDegree) * 60;
|
---|
48 |
|
---|
49 | String sDegrees = Integer.toString(tDegree);
|
---|
50 | String sMinutes = DM_MINUTE_FORMATTER.format(tMinutes);
|
---|
51 |
|
---|
52 | if (sMinutes.equals(DM60)) {
|
---|
53 | sMinutes = DM00;
|
---|
54 | sDegrees = Integer.toString(tDegree+1);
|
---|
55 | }
|
---|
56 |
|
---|
57 | return sDegrees + '\u00B0' + sMinutes + '\'';
|
---|
58 | }
|
---|
59 | }
|
---|