Changeset 31359 in osm for applications/editors/josm


Ignore:
Timestamp:
2015-07-09T16:09:25+02:00 (9 years ago)
Author:
floscher
Message:

Improved method MapillaryImportAction.degMinSecToDouble()

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java

    r31355 r31359  
    204204    SimpleDateFormat formatter = new SimpleDateFormat(format);
    205205    try {
    206       Date dateTime = (Date) formatter.parse(date);
     206      Date dateTime = formatter.parse(date);
    207207      return dateTime.getTime();
    208208    } catch (ParseException e) {
     
    224224  /**
    225225   * Sets the MapillarySequence object which contains the MapillaryImage.
    226    * 
     226   *
    227227   * @param sequence
    228228   *          The MapillarySequence that contains the MapillaryImage.
     
    234234  /**
    235235   * Returns the sequence which contains this image.
    236    * 
     236   *
    237237   * @return The MapillarySequence object that contains this MapillaryImage.
    238238   */
     
    244244   * If the MapillaryImage belongs to a MapillarySequence, returns the next
    245245   * MapillarySequence in it.
    246    * 
     246   *
    247247   * @return The following MapillaryImage, or null if there is none.
    248248   */
     
    258258   * If the MapillaryImage belongs to a MapillarySequence, returns the previous
    259259   * MapillarySequence in it.
    260    * 
     260   *
    261261   * @return The previous MapillaryImage, or null if there is none.
    262262   */
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImage.java

    r31355 r31359  
    8989  }
    9090
     91  @Override
    9192  public String toString() {
    9293    return "Image[key=" + this.key + ";lat=" + this.latLon.lat() + ";lon=" + this.latLon.lon() + ";ca=" + this.ca + "]";
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportAction.java

    r31357 r31359  
    109109      double lonValue = 0;
    110110      double caValue = 0;
    111       if (lat != null && lat.getValue() instanceof RationalNumber[])
    112         latValue = DegMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
    113       if (lon != null && lon.getValue() instanceof RationalNumber[])
    114         lonValue = DegMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
     111      if (lat.getValue() instanceof RationalNumber[])
     112        latValue = degMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
     113      if (lon.getValue() instanceof RationalNumber[])
     114        lonValue = degMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
    115115      if (ca != null && ca.getValue() instanceof RationalNumber)
    116116        caValue = ((RationalNumber) ca.getValue()).doubleValue();
    117       if (lat_ref.getValue().toString().equals("S"))
    118         latValue = -latValue;
    119       if (lon_ref.getValue().toString().equals("W"))
    120         lonValue = -lonValue;
    121117      if (datetimeOriginal != null)
    122         MapillaryData.getInstance().add(
    123             new MapillaryImportedImage(latValue, lonValue, caValue, file, datetimeOriginal.getStringValue()));
     118        MapillaryData.getInstance()
     119            .add(new MapillaryImportedImage(latValue, lonValue, caValue, file, datetimeOriginal.getStringValue()));
    124120      else
    125121        MapillaryData.getInstance().add(new MapillaryImportedImage(latValue, lonValue, caValue, file));
     
    149145  }
    150146
    151   public static double DegMinSecToDouble(RationalNumber[] degMinSec, String ref) {
    152     RationalNumber deg = degMinSec[0];
    153     RationalNumber min = degMinSec[1];
    154     RationalNumber sec = degMinSec[2];
    155     return deg.doubleValue() + min.doubleValue() / 60 + sec.doubleValue() / 3600;
     147  /**
     148   * Calculates the decimal degree-value from a degree value given in degrees-minutes-seconds-format
     149   *
     150   * @param degMinSec an array of length 3, the values in there are (in this order) degrees, minutes and seconds
     151   * @param ref the latitude or longitude reference determining if the given value is:
     152   *        <ul>
     153   *        <li>north ({@link GpsTagConstants#GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH}) or
     154   *        south ({@link GpsTagConstants#GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH}) of the equator</li>
     155   *        <li>east ({@link GpsTagConstants#GPS_TAG_GPS_LONGITUDE_REF_VALUE_EAST}) or
     156   *        west ({@link GpsTagConstants#GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST}) of the equator</li>
     157   *        </ul>
     158   * @return the decimal degree-value for the given input, negative when west of 0-meridian or south of equator,
     159   *         positive otherwise
     160   * @throws IllegalArgumentException if {@code degMinSec} doesn't have length 3 or if {@code ref} is not one of the
     161   *         values mentioned above
     162   */ // TODO: Maybe move into a separate utility class?
     163  public static double degMinSecToDouble(RationalNumber[] degMinSec, String ref) {
     164    if (degMinSec == null || degMinSec.length != 3) { throw new IllegalArgumentException(); }
     165    switch (ref) {
     166    case GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH:
     167    case GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH:
     168    case GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_EAST:
     169    case GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST:
     170      break;
     171    default:
     172      throw new IllegalArgumentException();
     173    }
     174
     175    double result = degMinSec[0].doubleValue(); // degrees
     176    result += degMinSec[1].doubleValue() / 60; // minutes
     177    result += degMinSec[2].doubleValue() / 3600; // seconds
     178
     179    if (ref == GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH
     180        || ref == GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST) {
     181      result *= -1;
     182    }
     183
     184    return result;
    156185  }
    157186}
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31355 r31359  
    104104      double lonValue = 0;
    105105      double caValue = 0;
    106       if (lat != null && lat.getValue() instanceof RationalNumber[])
    107         latValue = MapillaryImportAction.DegMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref.getValue()
    108             .toString());
    109       if (lon != null && lon.getValue() instanceof RationalNumber[])
    110         lonValue = MapillaryImportAction.DegMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref.getValue()
    111             .toString());
     106      if (lat.getValue() instanceof RationalNumber[])
     107        latValue = MapillaryImportAction.degMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
     108      if (lon.getValue() instanceof RationalNumber[])
     109        lonValue = MapillaryImportAction.degMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
    112110      if (ca != null && ca.getValue() instanceof RationalNumber)
    113111        caValue = ((RationalNumber) ca.getValue()).doubleValue();
    114       if (lat_ref.getValue().toString().equals("S"))
    115         latValue = -latValue;
    116       if (lon_ref.getValue().toString().equals("W"))
    117         lonValue = -lonValue;
    118112
    119113      MapillaryImportedImage image = new MapillaryImportedImage(latValue, lonValue, caValue, file,
Note: See TracChangeset for help on using the changeset viewer.