ivebeen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/ivebeen +20 -0
  2. data/lib/exif2geojson.rb +58 -0
  3. metadata +80 -0
data/bin/ivebeen ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+ require "exif2geojson"
5
+
6
+ class IveBeenApp < Thor
7
+ desc "generate", "Extract EXIF from photo and generate geojson file"
8
+ # method_option :path, :aliases => "-p", :desc => "path of where you're storing your photos", :required => true
9
+ # method_option :result, :aliases => "-f", :desc => "the result geojson file, default value is places.geojson", :default => "places.geojson"
10
+ def generate(path, file="places.geojson")
11
+ # path = options[:path]
12
+ # file = options[:result] || "places.geojson"
13
+ info = extract_image_info(path)
14
+ File.open(file, "w") do |f|
15
+ f.write(info)
16
+ end
17
+ end
18
+ end
19
+
20
+ IveBeenApp.start(ARGV)
@@ -0,0 +1,58 @@
1
+ require 'json'
2
+ require 'exifr'
3
+
4
+ def to_decimal(dms)
5
+ dms[0].to_f + dms[1].to_f / 60 + dms[2].to_f / 3600
6
+ end
7
+
8
+ def to_geojson(exif)
9
+ lat_exif = exif.gps_latitude
10
+ lon_exif = exif.gps_longitude
11
+ return "" unless lon_exif && lat_exif
12
+ lon = to_decimal(lon_exif.map(&:to_f))
13
+ lon = -lon if exif.gps_longitude_ref == "W"
14
+ lat = to_decimal(lat_exif.map(&:to_f))
15
+ lat = -lat if exif.gps_latitude_ref == "S"
16
+ {
17
+ :type => "Point",
18
+ :coordinates => [lon, lat]
19
+ }
20
+ end
21
+
22
+ def format_attachment_gps(file)
23
+ geometry, altitude = nil, nil
24
+ body = File.read file
25
+ r, w = IO.pipe
26
+ w.write_nonblock(body)
27
+ exif = EXIFR::JPEG.new(r)
28
+ geometry = to_geojson(exif)
29
+ altitude = exif.gps_altitude.to_f
30
+ altitude = -altitude if exif.gps_altitude_ref.to_i < 0
31
+ { :type => "Feature",
32
+ :geometry => geometry,
33
+ :properties => {
34
+ :altitude => altitude
35
+ }
36
+ }
37
+ end
38
+
39
+ def extract_image_info(path)
40
+ image_types = "*.jpg"
41
+
42
+ info = []
43
+ Dir.glob("#{path}/#{image_types}") do |jpg|
44
+ begin
45
+ info << format_attachment_gps(jpg)
46
+ print "."
47
+ rescue Exception => e
48
+ print "E"
49
+ end
50
+ end
51
+
52
+ puts "\n"
53
+
54
+ {
55
+ :type => "FeatureCollection",
56
+ :features => info
57
+ }.to_json
58
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ivebeen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Juntao Qiu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.18.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.18.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: exifr
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.1.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.3
46
+ description: extract exif from image, and convert it to a geojson file, for present
47
+ email: juntao.qiu@gmail.com
48
+ executables:
49
+ - ivebeen
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - bin/ivebeen
54
+ - lib/exif2geojson.rb
55
+ homepage: https://github.com/abruzzi/ivebeen
56
+ licenses:
57
+ - MIT
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.25
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: extract exif from image, and convert it to a geojson file
80
+ test_files: []