Changeset 12735 in josm for trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
- Timestamp:
- 2017-09-05T17:58:01+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r12725 r12735 25 25 import org.openstreetmap.josm.Main; 26 26 import org.openstreetmap.josm.data.Bounds; 27 import org.openstreetmap.josm.data.coor.conversion.DMSCoordinateFormat; 28 import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat; 29 import org.openstreetmap.josm.data.coor.conversion.NauticalCoordinateFormat; 27 30 import org.openstreetmap.josm.tools.Logging; 28 31 import org.openstreetmap.josm.tools.Utils; … … 69 72 public static final LatLon SOUTH_POLE = new LatLon(-90, 0); 70 73 71 private static DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00");72 private static DecimalFormat cDmsSecondFormatter = new DecimalFormat(73 Main.pref == null ? "00.0" : Main.pref.get("latlon.dms.decimal-format", "00.0"));74 private static DecimalFormat cDmMinuteFormatter = new DecimalFormat(75 Main.pref == null ? "00.000" : Main.pref.get("latlon.dm.decimal-format", "00.000"));76 74 /** 77 75 * The normal number format for server precision coordinates … … 90 88 cDdHighPecisionFormatter.applyPattern("###0.0##########"); 91 89 } 92 93 private static final String cDms60 = cDmsSecondFormatter.format(60.0);94 private static final String cDms00 = cDmsSecondFormatter.format(0.0);95 private static final String cDm60 = cDmMinuteFormatter.format(60.0);96 private static final String cDm00 = cDmMinuteFormatter.format(0.0);97 90 98 91 /** Character denoting South, as string */ … … 217 210 * @return The coordinate in degrees/minutes/seconds format 218 211 * @since 12561 219 */ 212 * @deprecated use {@link DMSCoordinateFormat#degreesMinutesSeconds(double)} 213 */ 214 @Deprecated 220 215 public static String degreesMinutesSeconds(double pCoordinate) { 221 222 double tAbsCoord = Math.abs(pCoordinate); 223 int tDegree = (int) tAbsCoord; 224 double tTmpMinutes = (tAbsCoord - tDegree) * 60; 225 int tMinutes = (int) tTmpMinutes; 226 double tSeconds = (tTmpMinutes - tMinutes) * 60; 227 228 String sDegrees = Integer.toString(tDegree); 229 String sMinutes = cDmsMinuteFormatter.format(tMinutes); 230 String sSeconds = cDmsSecondFormatter.format(tSeconds); 231 232 if (cDms60.equals(sSeconds)) { 233 sSeconds = cDms00; 234 sMinutes = cDmsMinuteFormatter.format(tMinutes+1L); 235 } 236 if ("60".equals(sMinutes)) { 237 sMinutes = "00"; 238 sDegrees = Integer.toString(tDegree+1); 239 } 240 241 return sDegrees + '\u00B0' + sMinutes + '\'' + sSeconds + '\"'; 216 return DMSCoordinateFormat.degreesMinutesSeconds(pCoordinate); 242 217 } 243 218 … … 247 222 * @return The coordinate in degrees/minutes format 248 223 * @since 12537 249 */ 224 * @deprecated use {@link NauticalCoordinateFormat#degreesMinutes(double)} 225 */ 226 @Deprecated 250 227 public static String degreesMinutes(double pCoordinate) { 251 252 double tAbsCoord = Math.abs(pCoordinate); 253 int tDegree = (int) tAbsCoord; 254 double tMinutes = (tAbsCoord - tDegree) * 60; 255 256 String sDegrees = Integer.toString(tDegree); 257 String sMinutes = cDmMinuteFormatter.format(tMinutes); 258 259 if (sMinutes.equals(cDm60)) { 260 sMinutes = cDm00; 261 sDegrees = Integer.toString(tDegree+1); 262 } 263 264 return sDegrees + '\u00B0' + sMinutes + '\''; 228 return NauticalCoordinateFormat.degreesMinutes(pCoordinate); 265 229 } 266 230 … … 302 266 * @param d the coordinate format to use 303 267 * @return the formatted latitude 304 */ 268 * @deprecated use {@link org.openstreetmap.josm.data.coor.format.ICoordinateFormat#latToString(ILatLon) 269 */ 270 @Deprecated 305 271 public String latToString(CoordinateFormat d) { 306 switch(d) { 307 case DECIMAL_DEGREES: return cDdFormatter.format(y); 308 case DEGREES_MINUTES_SECONDS: return degreesMinutesSeconds(y) + ((y < 0) ? SOUTH : NORTH); 309 case NAUTICAL: return degreesMinutes(y) + ((y < 0) ? SOUTH : NORTH); 310 case EAST_NORTH: return cDdFormatter.format(this.getEastNorth(Main.getProjection()).north()); 311 default: return "ERR"; 312 } 272 return d.getICoordinateFormat().latToString(this); 313 273 } 314 274 … … 322 282 * @param d the coordinate format to use 323 283 * @return the formatted longitude 324 */ 284 * @deprecated use {@link org.openstreetmap.josm.data.coor.format.ICoordinateFormat#lonToString(ILatLon) 285 */ 286 @Deprecated 325 287 public String lonToString(CoordinateFormat d) { 326 switch(d) { 327 case DECIMAL_DEGREES: return cDdFormatter.format(x); 328 case DEGREES_MINUTES_SECONDS: return degreesMinutesSeconds(x) + ((x < 0) ? WEST : EAST); 329 case NAUTICAL: return degreesMinutes(x) + ((x < 0) ? WEST : EAST); 330 case EAST_NORTH: return cDdFormatter.format(this.getEastNorth(Main.getProjection()).east()); 331 default: return "ERR"; 332 } 288 return d.getICoordinateFormat().lonToString(this); 333 289 } 334 290 … … 469 425 public String toStringCSV(String separator) { 470 426 return Utils.join(separator, Arrays.asList( 471 latToString(CoordinateFormat.DECIMAL_DEGREES),472 lonToString(CoordinateFormat.DECIMAL_DEGREES)427 DecimalDegreesCoordinateFormat.INSTANCE.latToString(this), 428 DecimalDegreesCoordinateFormat.INSTANCE.lonToString(this) 473 429 )); 474 430 }
Note:
See TracChangeset
for help on using the changeset viewer.