Skip to content

Commit

Permalink
Fixed upload with images taken with the Mapillary app.
Browse files Browse the repository at this point in the history
  • Loading branch information
nokutu committed Aug 12, 2015
1 parent 8ce6468 commit b5317ef
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
<property name="plugin.main.version" value="8433"/>
<property name="plugin.canloadatruntime" value="true"/>
<property name="plugin.version" value="0.9.3"/>
<property name="plugin.version" value="0.9.4"/>
<property name="plugin.author" value="nokutu &lt;nokutu@openmailbox.org&gt;"/>
<property name="plugin.class" value="org.openstreetmap.josm.plugins.mapillary.MapillaryPlugin"/>
<property name="plugin.description" value="Allows the user to work with pictures hosted at mapillary.com"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,22 @@ public String getDate(String format) {
* @param format
* The format of the date.
* @return The date in Epoch format.
* @throws ParseException
*/
public static long getEpoch(String date, String format) {
public static long getEpoch(String date, String format) throws ParseException {

SimpleDateFormat formatter = new SimpleDateFormat(format);
try {
Date dateTime = formatter.parse(date);
return dateTime.getTime();
} catch (ParseException e) {
Main.error(e);
}
return currentTime();
Date dateTime = formatter.parse(date);
return dateTime.getTime();

}

/**
* Returns current time in Epoch format
*
* @return The current date in Epoch format.
*/
private static long currentTime() {
protected static long currentTime() {
Calendar cal = Calendar.getInstance();
return cal.getTimeInMillis();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

Expand All @@ -19,7 +20,7 @@ public class MapillaryImportedImage extends MapillaryAbstractImage {
/** The picture file. */
protected File file;
/** The date when the picture was taken. */
public final long datetimeOriginal;
public long datetimeOriginal;

/**
* Creates a new MapillaryImportedImage object using as date the current date,
Expand Down Expand Up @@ -56,7 +57,16 @@ public MapillaryImportedImage(double lat, double lon, double ca, File file,
String datetimeOriginal) {
super(lat, lon, ca);
this.file = file;
this.datetimeOriginal = getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
try {
this.datetimeOriginal = getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
} catch (ParseException e) {
try {
this.datetimeOriginal = getEpoch(datetimeOriginal,
"yyyy/MM/dd hh:mm:ss");
} catch (ParseException e1) {
this.datetimeOriginal = currentTime();
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
import org.apache.commons.imaging.formats.tiff.constants.ExifTagConstants;
import org.apache.commons.imaging.formats.tiff.constants.GpsTagConstants;
import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants;
import org.apache.commons.imaging.formats.tiff.write.TiffOutputDirectory;
import org.apache.commons.imaging.formats.tiff.write.TiffOutputSet;
import org.apache.http.HttpEntity;
Expand Down Expand Up @@ -187,9 +188,9 @@ public void run() {
} catch (InterruptedException e) {
Main.error(e);
}
System.out.println(this.images.size());
if (this.delete)
MapillaryRecord.getInstance().addCommand(new CommandDelete(this.images));
MapillaryRecord.getInstance()
.addCommand(new CommandDelete(this.images));
}
}

Expand Down Expand Up @@ -229,6 +230,8 @@ public static File updateFile(MapillaryImportedImage image)
TiffOutputSet outputSet = null;
TiffOutputDirectory exifDirectory = null;
TiffOutputDirectory gpsDirectory = null;
TiffOutputDirectory rootDirectory = null;

// If the image is imported, loads the rest of the EXIF data.
JpegImageMetadata jpegMetadata = null;
try {
Expand All @@ -247,6 +250,7 @@ public static File updateFile(MapillaryImportedImage image)
}
gpsDirectory = outputSet.getOrCreateGPSDirectory();
exifDirectory = outputSet.getOrCreateExifDirectory();
rootDirectory = outputSet.getOrCreateRootDirectory();

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

rootDirectory.removeField(TiffTagConstants.TIFF_TAG_IMAGE_DESCRIPTION);

outputSet.setGPSInDegrees(image.getLatLon().lon(), image.getLatLon().lat());
File tempFile = File.createTempFile("imagetoupload_" + c, ".tmp");
c++;
Expand Down

0 comments on commit b5317ef

Please sign in to comment.