Skip to content

Commit b5317ef

Browse files
author
nokutu
committed
Fixed upload with images taken with the Mapillary app.
git-svn-id: http://svn.openstreetmap.org/applications/editors/josm/plugins/mapillary@31496 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
1 parent 8ce6468 commit b5317ef

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
55
<property name="plugin.main.version" value="8433"/>
66
<property name="plugin.canloadatruntime" value="true"/>
7-
<property name="plugin.version" value="0.9.3"/>
7+
<property name="plugin.version" value="0.9.4"/>
88
<property name="plugin.author" value="nokutu &lt;nokutu@openmailbox.org&gt;"/>
99
<property name="plugin.class" value="org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin"/>
1010
<property name="plugin.description" value="Allows the user to work with pictures hosted at mapillary.com"/>

src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,25 +234,22 @@ public String getDate(String format) {
234234
* @param format
235235
* The format of the date.
236236
* @return The date in Epoch format.
237+
* @throws ParseException
237238
*/
238-
public static long getEpoch(String date, String format) {
239+
public static long getEpoch(String date, String format) throws ParseException {
239240

240241
SimpleDateFormat formatter = new SimpleDateFormat(format);
241-
try {
242-
Date dateTime = formatter.parse(date);
243-
return dateTime.getTime();
244-
} catch (ParseException e) {
245-
Main.error(e);
246-
}
247-
return currentTime();
242+
Date dateTime = formatter.parse(date);
243+
return dateTime.getTime();
244+
248245
}
249246

250247
/**
251248
* Returns current time in Epoch format
252249
*
253250
* @return The current date in Epoch format.
254251
*/
255-
private static long currentTime() {
252+
protected static long currentTime() {
256253
Calendar cal = Calendar.getInstance();
257254
return cal.getTimeInMillis();
258255
}

src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.image.BufferedImage;
44
import java.io.File;
55
import java.io.IOException;
6+
import java.text.ParseException;
67
import java.text.SimpleDateFormat;
78
import java.util.Calendar;
89

@@ -19,7 +20,7 @@ public class MapillaryImportedImage extends MapillaryAbstractImage {
1920
/** The picture file. */
2021
protected File file;
2122
/** The date when the picture was taken. */
22-
public final long datetimeOriginal;
23+
public long datetimeOriginal;
2324

2425
/**
2526
* Creates a new MapillaryImportedImage object using as date the current date,
@@ -56,7 +57,16 @@ public MapillaryImportedImage(double lat, double lon, double ca, File file,
5657
String datetimeOriginal) {
5758
super(lat, lon, ca);
5859
this.file = file;
59-
this.datetimeOriginal = getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
60+
try {
61+
this.datetimeOriginal = getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
62+
} catch (ParseException e) {
63+
try {
64+
this.datetimeOriginal = getEpoch(datetimeOriginal,
65+
"yyyy/MM/dd hh:mm:ss");
66+
} catch (ParseException e1) {
67+
this.datetimeOriginal = currentTime();
68+
}
69+
}
6070
}
6171

6272
/**

src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
2626
import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
2727
import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
28+
import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants;
2829
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory;
2930
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
3031
import org.apache.http.HttpEntity;
@@ -187,9 +188,9 @@ public void run() {
187188
} catch (InterruptedException e) {
188189
Main.error(e);
189190
}
190-
System.out.println(this.images.size());
191191
if (this.delete)
192-
MapillaryRecord.getInstance().addCommand(new CommandDelete(this.images));
192+
MapillaryRecord.getInstance()
193+
.addCommand(new CommandDelete(this.images));
193194
}
194195
}
195196

@@ -229,6 +230,8 @@ public static File updateFile(MapillaryImportedImage image)
229230
TiffOutputSet outputSet = null;
230231
TiffOutputDirectory exifDirectory = null;
231232
TiffOutputDirectory gpsDirectory = null;
233+
TiffOutputDirectory rootDirectory = null;
234+
232235
// If the image is imported, loads the rest of the EXIF data.
233236
JpegImageMetadata jpegMetadata = null;
234237
try {
@@ -247,6 +250,7 @@ public static File updateFile(MapillaryImportedImage image)
247250
}
248251
gpsDirectory = outputSet.getOrCreateGPSDirectory();
249252
exifDirectory = outputSet.getOrCreateExifDirectory();
253+
rootDirectory = outputSet.getOrCreateRootDirectory();
250254

251255
gpsDirectory.removeField(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF);
252256
gpsDirectory.add(GpsTagConstants.GPS_TAG_GPS_IMG_DIRECTION_REF,
@@ -260,6 +264,8 @@ public static File updateFile(MapillaryImportedImage image)
260264
exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
261265
((MapillaryImportedImage) image).getDate("yyyy/MM/dd hh:mm:ss"));
262266

267+
rootDirectory.removeField(TiffTagConstants.TIFF_TAG_IMAGE_DESCRIPTION);
268+
263269
outputSet.setGPSInDegrees(image.getLatLon().lon(), image.getLatLon().lat());
264270
File tempFile = File.createTempFile("imagetoupload_" + c, ".tmp");
265271
c++;

0 commit comments

Comments
 (0)