Esempio n. 1
0
  /**
   * Returns a list of images that fulfill the given criteria. Default setting is to return untagged
   * images, but may be overwritten.
   *
   * @param exif also returns images with exif-gps info
   * @param tagged also returns tagged images
   * @return matching images
   */
  private List<ImageEntry> getSortedImgList(boolean exif, boolean tagged) {
    if (yLayer.data == null) {
      return Collections.emptyList();
    }
    List<ImageEntry> dateImgLst = new ArrayList<>(yLayer.data.size());
    for (ImageEntry e : yLayer.data) {
      if (!e.hasExifTime()) {
        continue;
      }

      if (e.getExifCoor() != null && !exif) {
        continue;
      }

      if (e.isTagged() && e.getExifCoor() == null && !tagged) {
        continue;
      }

      dateImgLst.add(e);
    }

    Collections.sort(
        dateImgLst,
        new Comparator<ImageEntry>() {
          @Override
          public int compare(ImageEntry arg0, ImageEntry arg1) {
            return arg0.getExifTime().compareTo(arg1.getExifTime());
          }
        });

    return dateImgLst;
  }
Esempio n. 2
0
  private static void extractExif(ImageEntry e) {

    double deg;
    double min, sec;
    double lon, lat;
    Metadata metadata = null;
    Directory dir = null;

    try {
      metadata = JpegMetadataReader.readMetadata(e.getFile());
      dir = metadata.getDirectory(GpsDirectory.class);
    } catch (CompoundException p) {
      e.setExifCoor(null);
      e.setPos(null);
      return;
    }

    try {
      // longitude

      Rational[] components = dir.getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);

      deg = components[0].doubleValue();
      min = components[1].doubleValue();
      sec = components[2].doubleValue();

      if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec))
        throw new IllegalArgumentException();

      lon =
          (Double.isNaN(deg)
              ? 0
              : deg
                  + (Double.isNaN(min) ? 0 : (min / 60))
                  + (Double.isNaN(sec) ? 0 : (sec / 3600)));

      if (dir.getString(GpsDirectory.TAG_GPS_LONGITUDE_REF).charAt(0) == 'W') {
        lon = -lon;
      }

      // latitude

      components = dir.getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);

      deg = components[0].doubleValue();
      min = components[1].doubleValue();
      sec = components[2].doubleValue();

      if (Double.isNaN(deg) && Double.isNaN(min) && Double.isNaN(sec))
        throw new IllegalArgumentException();

      lat =
          (Double.isNaN(deg)
              ? 0
              : deg
                  + (Double.isNaN(min) ? 0 : (min / 60))
                  + (Double.isNaN(sec) ? 0 : (sec / 3600)));

      if (Double.isNaN(lat)) throw new IllegalArgumentException();

      if (dir.getString(GpsDirectory.TAG_GPS_LATITUDE_REF).charAt(0) == 'S') {
        lat = -lat;
      }

      // Store values

      e.setExifCoor(new LatLon(lat, lon));
      e.setPos(e.getExifCoor());

    } catch (CompoundException p) {
      // Try to read lon/lat as double value (Nonstandard, created by some cameras -> #5220)
      try {
        Double longitude = dir.getDouble(GpsDirectory.TAG_GPS_LONGITUDE);
        Double latitude = dir.getDouble(GpsDirectory.TAG_GPS_LATITUDE);
        if (longitude == null || latitude == null) throw new CompoundException("");

        // Store values

        e.setExifCoor(new LatLon(latitude, longitude));
        e.setPos(e.getExifCoor());
      } catch (CompoundException ex) {
        e.setExifCoor(null);
        e.setPos(null);
      }
    } catch (Exception ex) { // (other exceptions, e.g. #5271)
      System.err.println("Error when reading EXIF from file: " + ex);
      e.setExifCoor(null);
      e.setPos(null);
    }

    // compass direction value

    Rational direction = null;

    try {
      direction = dir.getRational(GpsDirectory.TAG_GPS_IMG_DIRECTION);
      if (direction != null) {
        e.setExifImgDir(direction.doubleValue());
      }
    } catch (Exception ex) { // (CompoundException and other exceptions, e.g. #5271)
      // Do nothing
    }
  }