Changeset 31549 in osm for applications/editors/josm


Ignore:
Timestamp:
2015-09-13T17:59:23+02:00 (9 years ago)
Author:
nokutu
Message:

Fixed importing bug. Images without gps data would not get their timestamp imported.

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

Legend:

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

    r31515 r31549  
    1818
    1919  /** The time the image was captured, in Epoch format. */
    20   private long capturedAt;
     20  protected long capturedAt;
    2121  /** Sequence of pictures containing this object. */
    2222  private MapillarySequence sequence;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

    r31513 r31549  
    2121  protected File file;
    2222  /** The date when the picture was taken. */
    23   public long datetimeOriginal;
    2423
    2524  /**
     
    5958    this.file = file;
    6059    try {
    61       this.datetimeOriginal = MapillaryUtils.getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
     60      this.capturedAt = MapillaryUtils.getEpoch(datetimeOriginal,
     61          "yyyy:MM:dd hh:mm:ss");
    6262    } catch (ParseException e) {
    6363      try {
    64         this.datetimeOriginal = MapillaryUtils.getEpoch(datetimeOriginal,
     64        this.capturedAt = MapillaryUtils.getEpoch(datetimeOriginal,
    6565            "yyyy/MM/dd hh:mm:ss");
    6666      } catch (ParseException e1) {
    67         this.datetimeOriginal = MapillaryUtils.currentTime();
     67        this.capturedAt = MapillaryUtils.currentTime();
    6868      }
    6969    }
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/MapillaryUser.java

    r31515 r31549  
    3737            .getString("username");
    3838      } catch (IOException e) {
    39         Main.error(e);
    40         isTokenValid = false;
     39        Main.info("Invalid Mapillary token, reseting field");
     40        reset();
    4141      }
    4242    return username;
     
    6666            .getString("images_policy");
    6767    } catch (IOException e) {
    68       Main.error(e);
    69       isTokenValid = false;
     68      Main.info("Invalid Mapillary token, reseting field");
     69      reset();
    7070    }
    7171    hash.put("images_policy", images_policy);
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

    r31515 r31549  
    211211    String key = MapillaryUser.getUsername() + "/" + uuid.toString() + "/"
    212212        + image.getLatLon().lat() + "_" + image.getLatLon().lon() + "_"
    213         + image.getCa() + "_" + image.datetimeOriginal + ".jpg";
     213        + image.getCa() + "_" + image.getCapturedAt() + ".jpg";
    214214
    215215    String policy = null;
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31513 r31549  
    118118   *           not one of the values mentioned above
    119119   */
    120   public static double degMinSecToDouble(RationalNumber[] degMinSec, String ref) {
     120  public static double degMinSecToDouble(RationalNumber[] degMinSec,
     121      String ref) {
    121122    if (degMinSec == null || degMinSec.length != 3) {
    122123      throw new IllegalArgumentException("Array's length must be 3.");
     
    145146    }
    146147
    147     result = 360 * ((result + 180) / 360 - Math.floor((result + 180) / 360)) - 180;
     148    result = 360 * ((result + 180) / 360 - Math.floor((result + 180) / 360))
     149        - 180;
    148150    return result;
    149151  }
     
    159161   * @throws ParseException
    160162   */
    161   public static long getEpoch(String date, String format) throws ParseException {
     163  public static long getEpoch(String date, String format)
     164      throws ParseException {
    162165    SimpleDateFormat formatter = new SimpleDateFormat(format);
    163166    Date dateTime = formatter.parse(date);
     
    229232   *           If the file doesn't have the valid metadata.
    230233   */
    231   public static MapillaryImportedImage readJPG(File file) throws IOException,
    232       ImageReadException {
     234  public static MapillaryImportedImage readJPG(File file)
     235      throws IOException, ImageReadException {
    233236    return readJPG(file, false);
    234237  }
     
    259262    if (metadata instanceof JpegImageMetadata) {
    260263      final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
    261       final TiffField lat_ref = jpegMetadata
    262           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
     264      final TiffField lat_ref = jpegMetadata.findEXIFValueWithExactMatch(
     265          GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
    263266      final TiffField lat = jpegMetadata
    264267          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
    265       final TiffField lon_ref = jpegMetadata
    266           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
     268      final TiffField lon_ref = jpegMetadata.findEXIFValueWithExactMatch(
     269          GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
    267270      final TiffField lon = jpegMetadata
    268271          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
    269       final TiffField ca = jpegMetadata
    270           .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
     272      final TiffField ca = jpegMetadata.findEXIFValueWithExactMatch(
     273          GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
    271274      final TiffField datetimeOriginal = jpegMetadata
    272           .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
     275          .findEXIFValueWithExactMatch(
     276              ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
    273277      if (lat_ref == null || lat == null || lon == null || lon_ref == null) {
    274278        if (exceptionNoTags)
     
    307311   */
    308312  public static MapillaryImportedImage readNoTags(File file) {
    309     return readNoTags(
    310         file,
    311         Main.map.mapView.getProjection().eastNorth2latlon(
    312             Main.map.mapView.getCenter()));
     313    return readNoTags(file, Main.map.mapView.getProjection()
     314        .eastNorth2latlon(Main.map.mapView.getCenter()));
    313315  }
    314316
     
    327329    double HORIZONTAL_DISTANCE = 0.0001;
    328330    double horDev;
     331
    329332    if (noTagsPics % 2 == 0)
    330333      horDev = HORIZONTAL_DISTANCE * noTagsPics / 2;
     
    332335      horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2);
    333336    noTagsPics++;
     337
     338    ImageMetadata metadata = null;
     339    try {
     340      metadata = Imaging.getMetadata(file);
     341    } catch (IOException e) {
     342      Main.error(e);
     343    } catch (ImageReadException e) {
     344      Main.error(e);
     345    }
     346    if (metadata instanceof JpegImageMetadata) {
     347      final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
     348      final TiffField datetimeOriginal = jpegMetadata
     349          .findEXIFValueWithExactMatch(
     350              ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
     351      if (datetimeOriginal == null)
     352        return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0,
     353            file);
     354      else {
     355        try {
     356          return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0,
     357              file, datetimeOriginal.getStringValue());
     358        } catch (ImageReadException e) {
     359          Main.error(e);
     360        }
     361      }
     362    }
    334363    return new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file);
    335364  }
     
    386415          maxLon = img.getLatLon().lon();
    387416      }
    388       Bounds zoomBounds = new Bounds(new LatLon(minLat, minLon), new LatLon(
    389           maxLat, maxLon));
     417      Bounds zoomBounds = new Bounds(new LatLon(minLat, minLon),
     418          new LatLon(maxLat, maxLon));
    390419      // The zoom rectangle must have a minimum size.
    391       double latExtent = zoomBounds.getMaxLat() - zoomBounds.getMinLat() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
    392           .getMaxLat() - zoomBounds.getMinLat()
    393           : MIN_ZOOM_SQUARE_SIDE;
    394       double lonExtent = zoomBounds.getMaxLon() - zoomBounds.getMinLon() >= MIN_ZOOM_SQUARE_SIDE ? zoomBounds
    395           .getMaxLon() - zoomBounds.getMinLon()
    396           : MIN_ZOOM_SQUARE_SIDE;
     420      double latExtent = zoomBounds.getMaxLat()
     421          - zoomBounds.getMinLat() >= MIN_ZOOM_SQUARE_SIDE
     422              ? zoomBounds.getMaxLat() - zoomBounds.getMinLat()
     423              : MIN_ZOOM_SQUARE_SIDE;
     424      double lonExtent = zoomBounds.getMaxLon()
     425          - zoomBounds.getMinLon() >= MIN_ZOOM_SQUARE_SIDE
     426              ? zoomBounds.getMaxLon() - zoomBounds.getMinLon()
     427              : MIN_ZOOM_SQUARE_SIDE;
    397428      zoomBounds = new Bounds(zoomBounds.getCenter(), latExtent, lonExtent);
    398429
     
    423454    }
    424455
    425     ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(firstImage
    426         .getSequence().getImages()
    427         .subList(0, firstImage.getSequence().getImages().indexOf(secondImage)));
    428     ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(firstImage
    429         .getSequence()
    430         .getImages()
    431         .subList(firstImage.getSequence().getImages().indexOf(secondImage),
     456    ArrayList<MapillaryAbstractImage> firstHalf = new ArrayList<>(
     457        firstImage.getSequence().getImages().subList(0,
     458            firstImage.getSequence().getImages().indexOf(secondImage)));
     459    ArrayList<MapillaryAbstractImage> secondHalf = new ArrayList<>(
     460        firstImage.getSequence().getImages().subList(
     461            firstImage.getSequence().getImages().indexOf(secondImage),
    432462            firstImage.getSequence().getImages().size()));
    433463
     
    455485      ret += tr("Downloading Mapillary images");
    456486    else if (MapillaryLayer.getInstance().getData().size() > 0)
    457       ret += tr("Total Mapillary images: {0}", MapillaryLayer.getInstance()
    458           .getData().size());
     487      ret += tr("Total Mapillary images: {0}",
     488          MapillaryLayer.getInstance().getData().size());
    459489    else
    460490      ret += tr("No images found");
Note: See TracChangeset for help on using the changeset viewer.