Changeset 31378 in osm for applications
- Timestamp:
- 2015-07-15T16:34:48+02:00 (9 years ago)
- 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 44 44 45 45 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); 49 51 this.setEnabled(false); 50 52 } … … 53 55 public void actionPerformed(ActionEvent e) { 54 56 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"))); 56 59 chooser.setCurrentDirectory(startDirectory); 57 60 chooser.setDialogTitle(tr("Select pictures")); 58 61 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 59 62 chooser.setAcceptAllFileFilterUsed(false); 60 chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg", "jpeg", "png")); 63 chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg", 64 "jpeg", "png")); 61 65 chooser.setMultiSelectionEnabled(true); 62 66 if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { … … 66 70 MapillaryLayer.getInstance(); 67 71 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 } 69 88 } 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")) { 72 93 try { 73 94 readJPG(file); … … 77 98 Main.error(ex); 78 99 } 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")) { 80 102 readPNG(file); 81 103 } … … 97 119 if (metadata instanceof JpegImageMetadata) { 98 120 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); 104 131 final TiffField datetimeOriginal = jpegMetadata 105 132 .findEXIFValueWithExactMatch(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL); … … 112 139 double caValue = 0; 113 140 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()); 115 143 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()); 117 146 if (ca != null && ca.getValue() instanceof RationalNumber) 118 147 caValue = ((RationalNumber) ca.getValue()).doubleValue(); 119 148 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())); 122 152 else 123 MapillaryData.getInstance().add(new MapillaryImportedImage(latValue, lonValue, caValue, file)); 153 MapillaryData.getInstance().add( 154 new MapillaryImportedImage(latValue, lonValue, caValue, file)); 124 155 } 125 156 } … … 138 169 else 139 170 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)); 142 175 noTagsPics++; 143 176 } … … 148 181 149 182 /** 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 151 185 * 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? 165 210 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 } 167 214 switch (ref) { 168 215 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 39 39 40 40 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); 44 47 this.setEnabled(false); 45 48 } … … 50 53 51 54 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")); 54 59 chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 55 60 chooser.setAcceptAllFileFilterUsed(false); 56 chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg", "jpeg")); 61 chooser.addChoosableFileFilter(new FileNameExtensionFilter("images", "jpg", 62 "jpeg")); 57 63 chooser.setMultiSelectionEnabled(true); 64 58 65 if (chooser.showOpenDialog(Main.parent) == JFileChooser.APPROVE_OPTION) { 59 66 for (int i = 0; i < chooser.getSelectedFiles().length; i++) { 60 67 File file = chooser.getSelectedFiles()[i]; 61 68 Main.pref.put("mapillary.start-directory", file.getParent()); 69 MapillaryLayer.getInstance(); 62 70 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 } 64 86 } 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")) { 68 91 try { 69 92 readJPG(file); … … 92 115 if (metadata instanceof JpegImageMetadata) { 93 116 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); 99 127 final TiffField datetimeOriginal = jpegMetadata 100 128 .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"); 103 133 104 134 double latValue = 0; … … 106 136 double caValue = 0; 107 137 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()); 109 140 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()); 111 143 if (ca != null && ca.getValue() instanceof RationalNumber) 112 144 caValue = ((RationalNumber) ca.getValue()).doubleValue(); 113 145 114 MapillaryImportedImage image = new MapillaryImportedImage(latValue, lonValue, caValue, file,115 datetimeOriginal.getStringValue());146 MapillaryImportedImage image = new MapillaryImportedImage(latValue, 147 lonValue, caValue, file, datetimeOriginal.getStringValue()); 116 148 MapillaryData.getInstance().add(image); 117 149 image.getCapturedAt(); … … 130 162 } 131 163 132 public class MapillaryEpochComparator implements Comparator<MapillaryAbstractImage> { 164 public class MapillaryEpochComparator implements 165 Comparator<MapillaryAbstractImage> { 133 166 134 167 @Override
Note:
See TracChangeset
for help on using the changeset viewer.