Changeset 3477 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2010-08-29T14:07:46+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/projection/UTM.java
r3083 r3477 5 5 6 6 import java.awt.GridBagLayout; 7 import java.util.Arrays; 7 8 import java.util.Collection; 8 import java.util.Collections; 9 9 10 import javax.swing.ButtonGroup; 11 import javax.swing.JCheckBox; 10 12 import javax.swing.JComboBox; 11 13 import javax.swing.JLabel; 12 14 import javax.swing.JPanel; 15 import javax.swing.JRadioButton; 13 16 14 17 import org.openstreetmap.josm.data.Bounds; … … 25 28 public class UTM implements Projection, ProjectionSubPrefs { 26 29 27 p ublicstatic final int DEFAULT_ZONE = 30;30 private static final int DEFAULT_ZONE = 30; 28 31 private int zone = DEFAULT_ZONE; 29 32 30 final private static double UTMScaleFactor = 0.9996; 33 public enum Hemisphere {North, South} 34 private static final Hemisphere DEFAULT_HEMISPHERE = Hemisphere.North; 35 private Hemisphere hemisphere = DEFAULT_HEMISPHERE; 36 37 private boolean offset = false; 38 39 private final static double UTMScaleFactor = 0.9996; 31 40 32 41 /* Ellipsoid model constants (WGS84) - TODO Use Elliposid class here too */ … … 339 348 public EastNorth latlon2eastNorth(LatLon p) { 340 349 EastNorth a = mapLatLonToXY(Math.toRadians(p.lat()), Math.toRadians(p.lon()), UTMCentralMeridian(getzone())); 341 return new EastNorth(a.east() * UTMScaleFactor + 3500000.0, a.north() * UTMScaleFactor);350 return new EastNorth(a.east() * UTMScaleFactor + getEastOffset(), a.north() * UTMScaleFactor + getNorthOffset()); 342 351 } 343 352 344 353 public LatLon eastNorth2latlon(EastNorth p) { 345 return mapXYToLatLon((p.east()- 3500000.0)/UTMScaleFactor, p.north()/UTMScaleFactor, UTMCentralMeridian(getzone()));354 return mapXYToLatLon((p.east()-getEastOffset())/UTMScaleFactor, (p.north()-getNorthOffset())/UTMScaleFactor, UTMCentralMeridian(getzone())); 346 355 } 347 356 … … 355 364 } 356 365 366 private double getEastOffset() { 367 return 500000 + (offset?3000000:0); 368 } 369 370 private double getNorthOffset() { 371 if (hemisphere == Hemisphere.North) 372 return 0; 373 else 374 return 10000000; 375 } 376 377 private int epsgCode() { 378 return ((offset?325800:32600) + getzone() + (hemisphere == Hemisphere.South?100:0)); 379 } 380 357 381 public String toCode() { 358 return "EPSG:"+ (325800 + getzone());382 return "EPSG:"+ epsgCode(); 359 383 } 360 384 361 385 @Override 362 386 public int hashCode() { 363 return getClass().getName().hashCode()+zone; // our only real variable387 return toCode().hashCode(); 364 388 } 365 389 366 390 public String getCacheDirectoryName() { 367 return "epsg"+ (325800 + getzone());391 return "epsg"+ epsgCode(); 368 392 } 369 393 370 394 public Bounds getWorldBoundsLatLon() 371 395 { 372 return new Bounds( 373 new LatLon(-85.0, UTMCentralMeridianDeg(getzone())-5.0), 374 new LatLon(85.0, UTMCentralMeridianDeg(getzone())+5.0)); 396 if (hemisphere == Hemisphere.North) 397 return new Bounds( 398 new LatLon(-5.0, UTMCentralMeridianDeg(getzone())-5.0), 399 new LatLon(85.0, UTMCentralMeridianDeg(getzone())+5.0)); 400 else 401 return new Bounds( 402 new LatLon(-85.0, UTMCentralMeridianDeg(getzone())-5.0), 403 new LatLon(5.0, UTMCentralMeridianDeg(getzone())+5.0)); 375 404 } 376 405 … … 381 410 382 411 public void setupPreferencePanel(JPanel p) { 383 JComboBox prefcb = new JComboBox(); 412 //Zone 413 JComboBox zonecb = new JComboBox(); 384 414 for(int i = 1; i <= 60; i++) { 385 prefcb.addItem(i);415 zonecb.addItem(i); 386 416 } 387 417 388 prefcb.setSelectedIndex(zone - 1);418 zonecb.setSelectedIndex(zone - 1); 389 419 p.setLayout(new GridBagLayout()); 390 420 p.add(new JLabel(tr("UTM Zone")), GBC.std().insets(5,5,0,5)); 391 421 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 392 422 /* Note: we use component position 2 below to find this again */ 393 p.add( prefcb, GBC.eop().fill(GBC.HORIZONTAL));423 p.add(zonecb, GBC.eop().fill(GBC.HORIZONTAL)); 394 424 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 425 426 //Hemisphere 427 JRadioButton north = new JRadioButton(); 428 north.setSelected(hemisphere == Hemisphere.North); 429 JRadioButton south = new JRadioButton(); 430 south.setSelected(hemisphere == Hemisphere.South); 431 432 ButtonGroup group = new ButtonGroup(); 433 group.add(north); 434 group.add(south); 435 436 JPanel bPanel = new JPanel(); 437 bPanel.setLayout(new GridBagLayout()); 438 439 bPanel.add(new JLabel(tr("North")), GBC.std().insets(5, 5, 0, 5)); 440 bPanel.add(north, GBC.std().fill(GBC.HORIZONTAL)); 441 bPanel.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 442 bPanel.add(new JLabel(tr("South")), GBC.std().insets(5, 5, 0, 5)); 443 bPanel.add(south, GBC.std().fill(GBC.HORIZONTAL)); 444 bPanel.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 445 446 p.add(new JLabel(tr("Hemisphere")), GBC.std().insets(5,5,0,5)); 447 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 448 p.add(bPanel, GBC.eop().fill(GBC.HORIZONTAL)); 449 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 450 451 //Offset 452 JCheckBox offsetBox = new JCheckBox(); 453 offsetBox.setSelected(offset); 454 455 p.add(new JLabel(tr("Offset 3.000.000m east")), GBC.std().insets(5,5,0,5)); 456 p.add(GBC.glue(1, 0), GBC.std().fill(GBC.HORIZONTAL)); 457 /* Note: we use component position 2 below to find this again */ 458 p.add(offsetBox, GBC.eop().fill(GBC.HORIZONTAL)); 459 p.add(GBC.glue(1, 1), GBC.eol().fill(GBC.BOTH)); 395 460 } 396 461 397 462 public Collection<String> getPreferences(JPanel p) { 398 Object prefcb = p.getComponent(2); 399 if(!(prefcb instanceof JComboBox)) 400 return null; 401 int zone = ((JComboBox)prefcb).getSelectedIndex() + 1; 402 return Collections.singleton(Integer.toString(zone)); 463 int zone = DEFAULT_ZONE; 464 Hemisphere hemisphere = DEFAULT_HEMISPHERE; 465 boolean offset = false; 466 467 Object zonecb = p.getComponent(2); 468 if (zonecb instanceof JComboBox) { 469 zone = ((JComboBox)zonecb).getSelectedIndex() + 1; 470 } 471 472 Object bPanel = p.getComponent(6); 473 if (bPanel instanceof JPanel) { 474 Object south = ((JPanel)bPanel).getComponent(4); 475 if (south instanceof JRadioButton) { 476 hemisphere = ((JRadioButton)south).isSelected()?Hemisphere.South:Hemisphere.North; 477 } 478 } 479 480 Object offsetBox = p.getComponent(10); 481 if (offsetBox instanceof JCheckBox) { 482 offset = ((JCheckBox) offsetBox).isSelected(); 483 } 484 485 return Arrays.asList(Integer.toString(zone), hemisphere.toString(), (offset?"offset":"standard")); 403 486 } 404 487 … … 406 489 { 407 490 zone = DEFAULT_ZONE; 491 hemisphere = DEFAULT_HEMISPHERE; 492 offset = true; //Default in previous versions 493 408 494 if(args != null) 409 495 { 496 String[] array = args.toArray(new String[0]); 410 497 try { 411 for(String s : args) 412 { 413 zone = Integer.parseInt(s); 414 if(zone <= 0 || zone > 60) { 415 zone = DEFAULT_ZONE; 416 } 417 break; 498 zone = Integer.parseInt(array[0]); 499 if(zone <= 0 || zone > 60) { 500 zone = DEFAULT_ZONE; 418 501 } 419 502 } catch(NumberFormatException e) {} 503 504 if (array.length > 1) { 505 hemisphere = Hemisphere.valueOf(array[1]); 506 } 507 508 if (array.length > 2) { 509 offset = array[2].equals("offset"); 510 } 420 511 } 421 512 } … … 423 514 public Collection<String> getPreferencesFromCode(String code) 424 515 { 425 if(code.startsWith("EPSG:3258")) 516 boolean offset = code.startsWith("EPSG:3258") || code.startsWith("EPSG:3259"); 517 518 if(code.startsWith("EPSG:326") || code.startsWith("EPSG:327") || offset) 426 519 { 427 520 try { 428 String zonestring = code.substring(9); 521 Hemisphere hemisphere; 522 String zonestring; 523 if (offset) { 524 hemisphere = code.charAt(8)=='8'?Hemisphere.North:Hemisphere.South; 525 zonestring = code.substring(9); 526 } else { 527 hemisphere = code.charAt(7)=='6'?Hemisphere.North:Hemisphere.South; 528 zonestring = code.substring(8); 529 } 530 429 531 int zoneval = Integer.parseInt(zonestring); 430 532 if(zoneval > 0 && zoneval <= 60) 431 return Collections.singleton(zonestring);533 return Arrays.asList(zonestring, hemisphere.toString(), (offset?"offset":"standard")); 432 534 } catch(NumberFormatException e) {} 433 535 }
Note:
See TracChangeset
for help on using the changeset viewer.