Image-ExifTool

 view release on metacpan or  search on metacpan

lib/Image/ExifTool/Geotag.pm  view on Meta::CPAN

                        next;
                    }
                    $isDate = 1;
                    $canCut= 1 if defined $$fix{pdop} or defined $$fix{hdop} or defined $$fix{nsats};
                    # generate extra fixes assuming an equally spaced track
                    if ($$fix{begin}) {
                        my $begin = GetTime($$fix{begin});
                        undef $$fix{begin};
                        if (defined $begin and $begin < $time) {
                            $$fix{span} = $timeSpan = ($timeSpan || 0) + 1;
                            my $i;
                            # duplicate the fix if there is only one so we will have
                            # a fix and the start and end of the TimeSpan
                            @saveFix or push @saveFix, [ @$fix{'lon','lat','alt'} ];
                            for ($i=0; $i<@saveFix; ++$i) {
                                my $t = $begin + ($time - $begin) * ($i / scalar(@saveFix));
                                my %f;
                                @f{'lon','lat','alt'} = @{$saveFix[$i]};
                                $t += 0.001 if not $i and $$points{$t}; # (avoid dupicates)
                                $f{span} = $timeSpan;
                                $$points{$t} = \%f;
                                push @fixTimes, $t;
                            }
                        }
                    }
                    $$points{$time} = $fix;
                    push @fixTimes, $time;  # save times of all fixes in order
                    $fix = { };
                    undef @saveFix;
                    ++$numPoints;
                }
            }
            # last ditch check KML description for timestamp (assume it is UTC)
            $$fix{'time'} = "$1T$2Z" if $td and not $$fix{'time'} and
                /[\s>](\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2}(\.\d+)?)/;
            next;
#
# Winplus Beacon text file
#
        } elsif ($format eq 'Winplus') {
            # TP,D, 44.933666667, -93.186555556, 10/26/2011, 19:07:28, 0
            #       latitude      longitude      date        time
            /^TP,D,\s*([-+]?\d+\.\d*),\s*([-+]?\d+\.\d*),\s*(\d+)\/(\d+)\/(\d{4}),\s*(\d+):(\d+):(\d+)/ or next;
            $$fix{lat} = $1;
            $$fix{lon} = $2;
            $time = Time::Local::timegm($8,$7,$6,$4,$3-1,$5);
DoneFix:    $isDate = 1;
            $$points{$time} = $fix;
            push @fixTimes, $time;
            $fix = { };
            ++$numPoints;
            next;
#
# Bramor gEO log file
#
        } elsif ($format eq 'Bramor') {
            #   1 0015   18.723675   50.672752  149 169.31 22/04/2015 07:06:55 169.31    8.88   28.07 ypr
            #   ? index  latitude    longitude  alt track  date       time     dir       pitch  roll
            my @parts = split ' ', $_;
            next unless @parts == 12 and $parts[11] eq 'ypr';
            my @d = split m{/}, $parts[6];  # date (dd/mm/YYYY)
            my @t = split m{:}, $parts[7];  # time (HH:MM:SS)
            next unless @d == 3 and @t == 3;
            @$fix{qw(lat lon alt track dir pitch roll)} = @parts[2,3,4,5,8,9,10];
            # (add the seconds afterwards in case some models have decimal seconds)
            $time = Time::Local::timegm(0,$t[1],$t[0],$d[0],$d[1]-1,$d[2]) + $t[2];
            # set necessary flags for extra available information
            @$has{qw(alt track orient)} = (1,1,1);
            goto DoneFix;   # save this fix
        } elsif ($format eq 'CSV') {
            chomp;
            my @vals = SplitCSV($_, $csvDelim);
#
# CSV format output of GPS/IMU POS system
#   Date*           - date in DD/MM/YYYY format
#   Time*           - time in HH:MM:SS.SSS format
#   [Pos]Lat*       - latitude in decimal degrees
#   [Pos]Lon*       - longitude in decimal degrees
#   [Pos]Alt*       - altitude in m relative to sea level
#   [Angle]Heading* - GPSTrack in degrees true
#   [Angle]Pitch*   - pitch angle in degrees
#   [Angle]Roll*    - roll angle in degrees
# (ExifTool enhancements allow for standard tag names or descriptions as the column headings,
#  add support for time zones and flexible coordinates, and allow new DateTime and Shift columns)
#
            my ($param, $date, $secs, %neg);
            foreach $param (@csvHeadings) {
                my $val = shift @vals;
                last unless defined $val and length($val);
                next unless $param;
                if ($param eq 'datetime') {
                    # (fix formats like "24.07.2016 13:47:30")
                    $val =~ s/^(\d{2})[^\d](\d{2})[^\d](\d{4}) /$3:$2:$1 /;
                    local $SIG{'__WARN__'} = sub { };
                    my $dateTime = $et->InverseDateTime($val);
                    if ($dateTime) {
                        $date = Image::ExifTool::GetUnixTime($val, 2);
                        $secs = 0;
                    }
                } elsif ($param eq 'date') {
                    if ($val =~ m{^(\d{2})/(\d{2})/(\d{4})$}) {
                        $date = Time::Local::timegm(0,0,0,$1,$2-1,$3);
                    } elsif ($val =~ /(\d{4}).*?(\d{2}).*?(\d{2})/) {
                        $date = Time::Local::timegm(0,0,0,$3,$2-1,$1);
                    } elsif ($val =~ /^(\d{2})(\d{2})(\d{2})$/) { # (Columbus GPS logger)
                        $date = Time::Local::timegm(0,0,0,$3,$2-1,$1+2000);
                    }
                } elsif ($param eq 'time') {
                    if ($val =~ /^(\d{1,2}):(\d{2}):(\d{2}(\.\d+)?).*?(([-+])(\d{1,2}):?(\d{2}))?/) {
                        $secs = (($1 * 60) + $2) * 60 + $3;
                        # adjust for time zone if specified
                        $secs += ($7 * 60 + $8) * ($6 eq '-' ? 60 : -60) if $5;
                    } elsif ($val =~ /^(\d{2})(\d{2})(\d{2})$/) { # (Columbus GPS logger)
                        $secs = (($1 * 60) + $2) * 60 + $3;
                    }
                } elsif ($param eq 'lat' or $param eq 'lon') {
                    $$fix{$param} = Image::ExifTool::GPS::ToDegrees($val, 1);
                } elsif ($param eq 'latref') {
                    $neg{lat} = 1 if $val =~ /^S/i;
                } elsif ($param eq 'lonref') {
                    $neg{lon} = 1 if $val =~ /^W/i;
                } elsif ($param eq 'runtime') {



( run in 2.544 seconds using v1.01-cache-2.11-cpan-71847e10f99 )