Changeset 31378 in osm


Ignore:
Timestamp:
2015-07-15T16:34:48+02:00 (9 years ago)
Author:
nokutu
Message:

Now you can import a whole directory

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

Legend:

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

    r31376 r31378  
    4444
    4545  public MapillaryImportAction() {
    46     super(tr("Import pictures"), new ImageProvider("icon24.png"), tr("Import local pictures"), Shortcut
    47         .registerShortcut("Import Mapillary", tr("Import pictures into Mapillary layer"), KeyEvent.CHAR_UNDEFINED,
    48             Shortcut.NONE), false, "mapillaryImport", false);
     46    super(tr("Import pictures"), new ImageProvider("icon24.png"),
     47        tr("Import local pictures"), Shortcut.registerShortcut(
     48            "Import Mapillary", tr("Import pictures into Mapillary layer"),
     49            KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryImport",
     50        false);
    4951    this.setEnabled(false);
    5052  }
     
    5355  public void actionPerformed(ActionEvent e) {
    5456    chooser = new JFileChooser();
    55     File startDirectory = new File(Main.pref.get("mapillary.start-directory", System.getProperty("user.home")));
     57    File startDirectory = new File(Main.pref.get("mapillary.start-directory",
     58        System.getProperty("user.home")));
    5659    chooser.setCurrentDirectory(startDirectory);
    5760    chooser.setDialogTitle(tr("Select pictures"));
    5861    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    5962    chooser.setAcceptAllFileFilterUsed(false);
    60     chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg", "jpeg", "png"));
     63    chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg",
     64        "jpeg", "png"));
    6165    chooser.setMultiSelectionEnabled(true);
    6266    if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
     
    6670        MapillaryLayer.getInstance();
    6771        if (file.isDirectory()) {
    68           // TODO import directory
     72          for (int j = 0; j < file.listFiles().length; j++) {
     73            int k = file.listFiles()[j].getName().lastIndexOf('.');
     74            String extension = null;
     75            if (k > 0) {
     76              extension = file.listFiles()[j].getName().substring(k + 1);
     77            }
     78            try {
     79              if (extension.equals("jpg") || extension.equals("jpeg"))
     80                readJPG(file.listFiles()[j]);
     81
     82              else if (extension.equals("png"))
     83                readPNG(file.listFiles()[j]);
     84            } catch (ImageReadException | IOException e1) {
     85              Main.error(e1);
     86            }
     87          }
    6988        } else {
    70           if (file.getPath().substring(file.getPath().length() - 4).equals(".jpg")
    71               || file.getPath().substring(file.getPath().length() - 5).equals(".jpeg")) {
     89          if (file.getPath().substring(file.getPath().length() - 4)
     90              .equals(".jpg")
     91              || file.getPath().substring(file.getPath().length() - 5)
     92                  .equals(".jpeg")) {
    7293            try {
    7394              readJPG(file);
     
    7798              Main.error(ex);
    7899            }
    79           } else if (file.getPath().substring(file.getPath().length() - 4).equals(".png")) {
     100          } else if (file.getPath().substring(file.getPath().length() - 4)
     101              .equals(".png")) {
    80102            readPNG(file);
    81103          }
     
    97119    if (metadata instanceof JpegImageMetadata) {
    98120      final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
    99       final TiffField lat_ref = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
    100       final TiffField lat = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
    101       final TiffField lon_ref = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
    102       final TiffField lon = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
    103       final TiffField ca = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
     121      final TiffField lat_ref = jpegMetadata
     122          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
     123      final TiffField lat = jpegMetadata
     124          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
     125      final TiffField lon_ref = jpegMetadata
     126          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
     127      final TiffField lon = jpegMetadata
     128          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
     129      final TiffField ca = jpegMetadata
     130          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
    104131      final TiffField datetimeOriginal = jpegMetadata
    105132          .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
     
    112139      double caValue = 0;
    113140      if (lat.getValue() instanceof RationalNumber[])
    114         latValue = degMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
     141        latValue = degMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref
     142            .getValue().toString());
    115143      if (lon.getValue() instanceof RationalNumber[])
    116         lonValue = degMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
     144        lonValue = degMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref
     145            .getValue().toString());
    117146      if (ca != null && ca.getValue() instanceof RationalNumber)
    118147        caValue = ((RationalNumber) ca.getValue()).doubleValue();
    119148      if (datetimeOriginal != null)
    120         MapillaryData.getInstance()
    121             .add(new MapillaryImportedImage(latValue, lonValue, caValue, file, datetimeOriginal.getStringValue()));
     149        MapillaryData.getInstance().add(
     150            new MapillaryImportedImage(latValue, lonValue, caValue, file,
     151                datetimeOriginal.getStringValue()));
    122152      else
    123         MapillaryData.getInstance().add(new MapillaryImportedImage(latValue, lonValue, caValue, file));
     153        MapillaryData.getInstance().add(
     154            new MapillaryImportedImage(latValue, lonValue, caValue, file));
    124155    }
    125156  }
     
    138169    else
    139170      horDev = -HORIZONTAL_DISTANCE * ((noTagsPics + 1) / 2);
    140     LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(Main.map.mapView.getCenter());
    141     MapillaryData.getInstance().add(new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file));
     171    LatLon pos = Main.map.mapView.getProjection().eastNorth2latlon(
     172        Main.map.mapView.getCenter());
     173    MapillaryData.getInstance().add(
     174        new MapillaryImportedImage(pos.lat(), pos.lon() + horDev, 0, file));
    142175    noTagsPics++;
    143176  }
     
    148181
    149182  /**
    150    * Calculates the decimal degree-value from a degree value given in degrees-minutes-seconds-format
     183   * Calculates the decimal degree-value from a degree value given in
     184   * degrees-minutes-seconds-format
    151185   *
    152    * @param degMinSec an array of length 3, the values in there are (in this order) degrees, minutes and seconds
    153    * @param ref the latitude or longitude reference determining if the given value is:
    154    *        <ul>
    155    *        <li>north ({@link GpsTagConstants#GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH}) or
    156    *        south ({@link GpsTagConstants#GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH}) of the equator</li>
    157    *        <li>east ({@link GpsTagConstants#GPS_TAG_GPS_LONGITUDE_REF_VALUE_EAST}) or
    158    *        west ({@link GpsTagConstants#GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST}) of the equator</li>
    159    *        </ul>
    160    * @return the decimal degree-value for the given input, negative when west of 0-meridian or south of equator,
    161    *         positive otherwise
    162    * @throws IllegalArgumentException if {@code degMinSec} doesn't have length 3 or if {@code ref} is not one of the
    163    *         values mentioned above
    164    */ // TODO: Maybe move into a separate utility class?
     186   * @param degMinSec
     187   *          an array of length 3, the values in there are (in this order)
     188   *          degrees, minutes and seconds
     189   * @param ref
     190   *          the latitude or longitude reference determining if the given value
     191   *          is:
     192   *          <ul>
     193   *          <li>north (
     194   *          {@link GpsTagConstants#GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH}) or
     195   *          south (
     196   *          {@link GpsTagConstants#GPS_TAG_GPS_LATITUDE_REF_VALUE_SOUTH}) of
     197   *          the equator</li>
     198   *          <li>east (
     199   *          {@link GpsTagConstants#GPS_TAG_GPS_LONGITUDE_REF_VALUE_EAST}) or
     200   *          west ({@link GpsTagConstants#GPS_TAG_GPS_LONGITUDE_REF_VALUE_WEST}
     201   *          ) of the equator</li>
     202   *          </ul>
     203   * @return the decimal degree-value for the given input, negative when west of
     204   *         0-meridian or south of equator, positive otherwise
     205   * @throws IllegalArgumentException
     206   *           if {@code degMinSec} doesn't have length 3 or if {@code ref} is
     207   *           not one of the values mentioned above
     208   */
     209  // TODO: Maybe move into a separate utility class?
    165210  public static double degMinSecToDouble(RationalNumber[] degMinSec, String ref) {
    166     if (degMinSec == null || degMinSec.length != 3) { throw new IllegalArgumentException(); }
     211    if (degMinSec == null || degMinSec.length != 3) {
     212      throw new IllegalArgumentException();
     213    }
    167214    switch (ref) {
    168215    case GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF_VALUE_NORTH:
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/actions/MapillaryImportIntoSequenceAction.java

    r31376 r31378  
    3939
    4040  public MapillaryImportIntoSequenceAction() {
    41     super(tr("Import pictures into sequence"), new ImageProvider("icon24.png"), tr("Import local pictures"), Shortcut
    42         .registerShortcut("Import Mapillary Sequence", tr("Import pictures into Mapillary layer in a sequence"),
    43             KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false, "mapillaryImportSequence", false);
     41    super(tr("Import pictures into sequence"), new ImageProvider("icon24.png"),
     42        tr("Import local pictures"), Shortcut.registerShortcut(
     43            "Import Mapillary Sequence",
     44            tr("Import pictures into Mapillary layer in a sequence"),
     45            KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false,
     46        "mapillaryImportSequence", false);
    4447    this.setEnabled(false);
    4548  }
     
    5053
    5154    chooser = new JFileChooser();
    52     File startDirectory = new File(Main.pref.get("mapillary.start-directory", System.getProperty("user.home")));
    53     chooser.setCurrentDirectory(startDirectory);    chooser.setDialogTitle(tr("Select pictures"));
     55    File startDirectory = new File(Main.pref.get("mapillary.start-directory",
     56        System.getProperty("user.home")));
     57    chooser.setCurrentDirectory(startDirectory);
     58    chooser.setDialogTitle(tr("Select pictures"));
    5459    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    5560    chooser.setAcceptAllFileFilterUsed(false);
    56     chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg", "jpeg"));
     61    chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg",
     62        "jpeg"));
    5763    chooser.setMultiSelectionEnabled(true);
     64   
    5865    if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) {
    5966      for (int i = 0; i < chooser.getSelectedFiles().length; i++) {
    6067        File file = chooser.getSelectedFiles()[i];
    6168        Main.pref.put("mapillary.start-directory", file.getParent());
     69        MapillaryLayer.getInstance();
    6270        if (file.isDirectory()) {
    63           // TODO import directory
     71          for (int j = 0; j < file.listFiles().length; j++) {
     72            int k = file.listFiles()[j].getName().lastIndexOf('.');
     73            String extension = null;
     74            if (k > 0) {
     75              extension = file.listFiles()[j].getName().substring(k + 1);
     76            }
     77            try {
     78              if (extension.equals("jpg") || extension.equals("jpeg"))
     79                readJPG(file.listFiles()[j]);
     80            } catch (ImageReadException e) {
     81              Main.error(e);
     82            } catch (IOException e) {
     83              Main.error(e);
     84            }
     85          }
    6486        } else {
    65           MapillaryLayer.getInstance();
    66           if (file.getPath().substring(file.getPath().length() - 4).equals(".jpg")
    67               || file.getPath().substring(file.getPath().length() - 5).equals(".jpeg")) {
     87          if (file.getPath().substring(file.getPath().length() - 4)
     88              .equals(".jpg")
     89              || file.getPath().substring(file.getPath().length() - 5)
     90                  .equals(".jpeg")) {
    6891            try {
    6992              readJPG(file);
     
    92115    if (metadata instanceof JpegImageMetadata) {
    93116      final JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
    94       final TiffField lat_ref = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
    95       final TiffField lat = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
    96       final TiffField lon_ref = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
    97       final TiffField lon = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
    98       final TiffField ca = jpegMetadata.findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
     117      final TiffField lat_ref = jpegMetadata
     118          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
     119      final TiffField lat = jpegMetadata
     120          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
     121      final TiffField lon_ref = jpegMetadata
     122          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
     123      final TiffField lon = jpegMetadata
     124          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
     125      final TiffField ca = jpegMetadata
     126          .findEXIFValueWithExactMatch(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION);
    99127      final TiffField datetimeOriginal = jpegMetadata
    100128          .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
    101       if (lat_ref == null || lat == null || lon == null || lon_ref == null || datetimeOriginal == null)
    102         throw new IllegalArgumentException("The picture has not correct EXIF tags");
     129      if (lat_ref == null || lat == null || lon == null || lon_ref == null
     130          || datetimeOriginal == null)
     131        throw new IllegalArgumentException(
     132            "The picture has not correct EXIF tags");
    103133
    104134      double latValue = 0;
     
    106136      double caValue = 0;
    107137      if (lat.getValue() instanceof RationalNumber[])
    108         latValue = MapillaryImportAction.degMinSecToDouble((RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
     138        latValue = MapillaryImportAction.degMinSecToDouble(
     139            (RationalNumber[]) lat.getValue(), lat_ref.getValue().toString());
    109140      if (lon.getValue() instanceof RationalNumber[])
    110         lonValue = MapillaryImportAction.degMinSecToDouble((RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
     141        lonValue = MapillaryImportAction.degMinSecToDouble(
     142            (RationalNumber[]) lon.getValue(), lon_ref.getValue().toString());
    111143      if (ca != null && ca.getValue() instanceof RationalNumber)
    112144        caValue = ((RationalNumber) ca.getValue()).doubleValue();
    113145
    114       MapillaryImportedImage image = new MapillaryImportedImage(latValue, lonValue, caValue, file,
    115           datetimeOriginal.getStringValue());
     146      MapillaryImportedImage image = new MapillaryImportedImage(latValue,
     147          lonValue, caValue, file, datetimeOriginal.getStringValue());
    116148      MapillaryData.getInstance().add(image);
    117149      image.getCapturedAt();
     
    130162  }
    131163
    132   public class MapillaryEpochComparator implements Comparator<MapillaryAbstractImage> {
     164  public class MapillaryEpochComparator implements
     165      Comparator<MapillaryAbstractImage> {
    133166
    134167    @Override
Note: See TracChangeset for help on using the changeset viewer.