Skip to content

Commit

Permalink
Support --direction and --heading (sort of) with --latlong
Browse files Browse the repository at this point in the history
--direction sets the camera direction directly, while --heading will only write
a heading of 0 degrees.
  • Loading branch information
dfandrich committed Nov 20, 2023
1 parent 2337f75 commit 649869c
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 19 deletions.
6 changes: 6 additions & 0 deletions doc/gpscorrelate-manpage.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@
inaccurate at slow speeds. Use your knowledge of the recording application
to determine how much faith you can place in the resulting tags.
</para>
<para>If this is used with <option>--latlong</option> instead of with
<option>--gps</option>, then a fixed heading of 0 is written.
</para>
</listitem>
</varlistentry>

Expand Down Expand Up @@ -554,6 +557,9 @@
applies along the entire track, it's only generally useful when the
camera is fixed in the vehicle during the trip.
</para>
<para>This may be used with <option>--latlong</option> in which case
the argument is used as the camera direction without alteration.
</para>
</listitem>
</varlistentry>

Expand Down
11 changes: 10 additions & 1 deletion latlong.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ int ParseLatLong(const char *latlongstr, struct GPSPoint* point)
}

/* Make a track from a single point */
int MakeTrackFromLatLong(const struct GPSPoint* latlong, struct GPSTrack* track)
int MakeTrackFromLatLong(const struct GPSPoint* latlong, int direction,
struct GPSTrack* track)
{
struct GPSPoint* p1 = NewGPSPoint();
struct GPSPoint* p2 = NewGPSPoint();
Expand All @@ -262,10 +263,18 @@ int MakeTrackFromLatLong(const struct GPSPoint* latlong, struct GPSTrack* track)
return 0;
}
memcpy(p1, latlong, sizeof(*p1));
if (direction >= 0) {
p1->Heading = direction;
p1->MoveHeading = 0;
}
p1->Time = track->MinTime = 0;
p1->Next = p2;

memcpy(p2, latlong, sizeof(*p2));
if (direction >= 0) {
p2->Heading = direction;
p2->MoveHeading = 0;
}
p2->Time = track->MaxTime = INT_MAX;
p2->Next = NULL;
p2->EndOfSegment = 1;
Expand Down
2 changes: 1 addition & 1 deletion latlong.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

struct GPSPoint *NewGPSPoint(void);
int ParseLatLong(const char *latlongstr, struct GPSPoint* point);
int MakeTrackFromLatLong(const struct GPSPoint* latlong, struct GPSTrack* track);
int MakeTrackFromLatLong(const struct GPSPoint* latlong, int direction, struct GPSTrack* track);
int NumDecimals(const char *Decimal);

38 changes: 21 additions & 17 deletions main-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,23 +466,6 @@ int main(int argc, char** argv)
fprintf(stderr, _("Error parsing location.\n"));
exit(EXIT_FAILURE);
}
if (!MakeTrackFromLatLong(LatLong, &Track[NumTracks]))
{
fprintf(stderr, _("Out of memory.\n"));
exit(EXIT_FAILURE);
}
free(LatLong);
LatLong = NULL;

/* Make room for a new end-of-array entry */
++NumTracks;
Track = (struct GPSTrack*) realloc(Track, sizeof(*Track)*(NumTracks+1));
if (!Track)
{
fprintf(stderr, _("Out of memory.\n"));
exit(EXIT_FAILURE);
}
memset(&Track[NumTracks], 0, sizeof(*Track));
break;

case 'z':
Expand Down Expand Up @@ -633,6 +616,27 @@ int main(int argc, char** argv)
break;
} /* End switch(c) */
} /* End While(1) */

/* Create a fake track if a position was manually given */
if (LatLong) {
if (!MakeTrackFromLatLong(LatLong, HeadingOffset, &Track[NumTracks]))
{
fprintf(stderr, _("Out of memory.\n"));
exit(EXIT_FAILURE);
}
free(LatLong);
LatLong = NULL;

/* Make room for a new end-of-array entry */
++NumTracks;
Track = (struct GPSTrack*) realloc(Track, sizeof(*Track)*(NumTracks+1));
if (!Track)
{
fprintf(stderr, _("Out of memory.\n"));
exit(EXIT_FAILURE);
}
memset(&Track[NumTracks], 0, sizeof(*Track));
}

/* Check to see if the user passed some files to work with. Not much
* good if they didn't. */
Expand Down
6 changes: 6 additions & 0 deletions tests/data/test171.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TITLE='Geotag a file from a specified location with direction'
PRECOMMAND='cat "$STAGINGDIR/point1-1.jpg" >"$LOGDIR/test.jpg"'
# Run in C locale to correctly parse these decimal numbers
COMMAND='env LC_ALL=C $PROGRAM -z+1 -l 12.34567,-123.456,78.9 --direction 321 "$LOGDIR/test.jpg" > "$OUTFILE" 2>&1 && exiv2 -pv pr "$LOGDIR/test.jpg" >> "$OUTFILE" 2>&1'
POSTCOMMAND='rm -f "$LOGDIR/test.jpg"'
RESULTCODE=0
36 changes: 36 additions & 0 deletions tests/data/test171.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Legend: . = Ok, / = Interpolated, < = Rounded, - = No match, ^ = Too far
w = Write Fail, ? = No EXIF date, ! = GPS already present

Correlate: /

Completed correlation process.
Matched: 1 (0 Exact, 1 Interpolated, 0 Rounded).
Failed: 0 (0 Not matched, 0 Write failure, 0 Too Far,
0 No Date, 0 GPS Already Present.)
0x011a Image XResolution Rational 1 72/1
0x011b Image YResolution Rational 1 72/1
0x0128 Image ResolutionUnit Short 1 2
0x0132 Image DateTime Ascii 20 2012:11:22 12:34:56
0x0213 Image YCbCrPositioning Short 1 1
0x8769 Image ExifTag Long 1 134
0x9000 Photo ExifVersion Undefined 4 48 50 49 48
0x9003 Photo DateTimeOriginal Ascii 20 2012:11:22 12:34:56
0x9004 Photo DateTimeDigitized Ascii 20 2012:11:22 12:34:56
0x9101 Photo ComponentsConfiguration Undefined 4 1 2 3 0
0xa000 Photo FlashpixVersion Undefined 4 48 49 48 48
0xa001 Photo ColorSpace Short 1 65535
0xa002 Photo PixelXDimension Long 1 64
0xa003 Photo PixelYDimension Long 1 64
0x8825 Image GPSTag Long 1 276
0x0000 GPSInfo GPSVersionID Byte 4 2 2 0 0
0x0001 GPSInfo GPSLatitudeRef Ascii 2 N
0x0002 GPSInfo GPSLatitude Rational 3 12/1 20/1 4441/100
0x0003 GPSInfo GPSLongitudeRef Ascii 2 W
0x0004 GPSInfo GPSLongitude Rational 3 123/1 27/1 22/1
0x0005 GPSInfo GPSAltitudeRef Byte 1 0
0x0006 GPSInfo GPSAltitude Rational 1 789/10
0x0007 GPSInfo GPSTimeStamp Rational 3 11/1 34/1 56/1
0x0010 GPSInfo GPSImgDirectionRef Ascii 2 T
0x0011 GPSInfo GPSImgDirection Rational 1 321/1
0x0012 GPSInfo GPSMapDatum Ascii 7 WGS-84
0x001d GPSInfo GPSDateStamp Ascii 11 2012:11:22
6 changes: 6 additions & 0 deletions tests/data/test172.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TITLE='Geotag a file from a specified location with direction and heading'
PRECOMMAND='cat "$STAGINGDIR/point1-1.jpg" >"$LOGDIR/test.jpg"'
# Run in C locale to correctly parse these decimal numbers
COMMAND='env LC_ALL=C $PROGRAM -z0 -l "12.34567,-123.456 78.9" --direction 12 --heading "$LOGDIR/test.jpg" > "$OUTFILE" 2>&1 && exiv2 -pv pr "$LOGDIR/test.jpg" >> "$OUTFILE" 2>&1'
POSTCOMMAND='rm -f "$LOGDIR/test.jpg"'
RESULTCODE=0
38 changes: 38 additions & 0 deletions tests/data/test172.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Legend: . = Ok, / = Interpolated, < = Rounded, - = No match, ^ = Too far
w = Write Fail, ? = No EXIF date, ! = GPS already present

Correlate: /

Completed correlation process.
Matched: 1 (0 Exact, 1 Interpolated, 0 Rounded).
Failed: 0 (0 Not matched, 0 Write failure, 0 Too Far,
0 No Date, 0 GPS Already Present.)
0x011a Image XResolution Rational 1 72/1
0x011b Image YResolution Rational 1 72/1
0x0128 Image ResolutionUnit Short 1 2
0x0132 Image DateTime Ascii 20 2012:11:22 12:34:56
0x0213 Image YCbCrPositioning Short 1 1
0x8769 Image ExifTag Long 1 134
0x9000 Photo ExifVersion Undefined 4 48 50 49 48
0x9003 Photo DateTimeOriginal Ascii 20 2012:11:22 12:34:56
0x9004 Photo DateTimeDigitized Ascii 20 2012:11:22 12:34:56
0x9101 Photo ComponentsConfiguration Undefined 4 1 2 3 0
0xa000 Photo FlashpixVersion Undefined 4 48 49 48 48
0xa001 Photo ColorSpace Short 1 65535
0xa002 Photo PixelXDimension Long 1 64
0xa003 Photo PixelYDimension Long 1 64
0x8825 Image GPSTag Long 1 276
0x0000 GPSInfo GPSVersionID Byte 4 2 2 0 0
0x0001 GPSInfo GPSLatitudeRef Ascii 2 N
0x0002 GPSInfo GPSLatitude Rational 3 12/1 20/1 4441/100
0x0003 GPSInfo GPSLongitudeRef Ascii 2 W
0x0004 GPSInfo GPSLongitude Rational 3 123/1 27/1 22/1
0x0005 GPSInfo GPSAltitudeRef Byte 1 0
0x0006 GPSInfo GPSAltitude Rational 1 789/10
0x0007 GPSInfo GPSTimeStamp Rational 3 12/1 34/1 56/1
0x000e GPSInfo GPSTrackRef Ascii 2 T
0x000f GPSInfo GPSTrack Rational 1 0/1
0x0010 GPSInfo GPSImgDirectionRef Ascii 2 T
0x0011 GPSInfo GPSImgDirection Rational 1 12/1
0x0012 GPSInfo GPSMapDatum Ascii 7 WGS-84
0x001d GPSInfo GPSDateStamp Ascii 11 2012:11:22

0 comments on commit 649869c

Please sign in to comment.