Registration has been disabled and the moderation extension has been turned off.

Contact an admin on Discord or EDF if you want an account. Also fuck bots.

User:Doxcat/gpstool: Difference between revisions

From Encyclopedia Dramatica
Jump to navigation Jump to search
imported>Doxcat
Created page with "so i wrote dis here perl script to extract gps information from exif tags in an image if they exist, as well as determine the nearest address given that information. dependencie..."
imported>Doxcat
Created page with "so i wrote dis here perl script to extract gps information from exif tags in an image if they exist, as well as determine the nearest address given that information. dependencie..."
 
(5 intermediate revisions by the same user not shown)
(No difference)

Latest revision as of 00:15, 13 July 2012

so i wrote dis here perl script to extract gps information from exif tags in an image if they exist, as well as determine the nearest address given that information.

dependencies: Image::ExifTool, Geo::GeoNames, Geo::Coordinates::DecimalDegrees

sauce:

#!/usr/bin/perl

use strict;
use warnings;
use Image::ExifTool;
use Geo::GeoNames;
use Geo::Coordinates::DecimalDegrees;

my $et = Image::ExifTool->new;
my $geo = Geo::GeoNames->new;
my $file = shift;
die("Please include a filename") if !defined $file;
die("$file does not exist") if !-f $file;
print "GPS info for " . `basename $file` . "\n";

my $info = $et->ImageInfo($file);
my ($mTag, $mVal) = (0,0);
my $out = {};
foreach my $el (keys %$info) {
        next if $el !~ /GPS/;
        if(length $el > $mTag) {
                $mTag = length $el;
        }
        if(length $info->{$el} > $mVal) {
                $mVal = length $info->{$el};
        }
        $out->{$el} = $info->{$el};
}

map { printf("\%-${mTag}s : \%-${mVal}s\n", $_, $out->{$_}) } keys %$out;
my ($lat, $lng)  = split(/, /,$out->{GPSPosition});
my @lt = ($lat =~ /([\d\.]+) deg ([\d\.]+)' ([\d\.]+)" (\w)/i);
my @ln = ($lng =~ /([\d\.]+) deg ([\d\.]+)' ([\d\.]+)" (\w)/i);
$lt[0] = -$lt[0] if $lt[3] eq "S";
$ln[0] = -$ln[0] if $ln[3] eq "W";
my $latD = dms2decimal($lt[0],$lt[1],$lt[2]);
my $lngD = dms2decimal($ln[0],$ln[1],$ln[2]);
my $n = $geo->find_nearest_address(lat => $latD, lng => $lngD);
if(defined $n and scalar @$n != 0) {
        my $nearest = $n->[0];
        my $num = $nearest->{streetNumber};
        my $street = $nearest->{street};
        my $city = $nearest->{placename};
        my $state = $nearest->{adminCode1};
        my $zip = $nearest->{postalcode};
        my $address = "$num $street, $city, $state $zip";
        print "\nNearest detected address: $address";
}   
print "\n";