xdata 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'zlib'
4
+ require 'stringio'
5
+
6
+ class PC4
7
+ data = File.read(File.dirname(__FILE__) + "/pc4.gz")
8
+ @@pc = Marshal.load(Zlib::GzipReader.new(StringIO.new(data)).read)
9
+ data = nil
10
+ def self.lookup(str)
11
+ str = str.gsub(/[^\d]/,'')[0..3]
12
+ bbox = @@pc[str]
13
+ return [[bbox[0][0].unpack('e')[0], bbox[0][1].unpack('e')[0]],[bbox[1][0].unpack('e')[0], bbox[1][1].unpack('e')[0]]] if bbox
14
+ nil
15
+ end
16
+ end
17
+
18
+ #
19
+ #
20
+ # if ARGV[0]
21
+ # h = PC4.lookup ARGV[0]
22
+ # if(h)
23
+ # puts "bl: #{h[0][0]}, #{h[0][1]}\ntr: #{h[1][0]}, #{h[1][1]}"
24
+ # else
25
+ # STDERR.puts "'#{ARGV[0]}' does not seem to be a valid postcode."
26
+ # exit(1)
27
+ # end
28
+ # end
29
+ # # puts PC.lookup('1012 CR')
30
+ #
31
+ #
@@ -0,0 +1,99 @@
1
+ require 'json'
2
+ require 'i18n'
3
+ require 'proj4'
4
+ require 'net/http'
5
+ require 'net/https'
6
+
7
+ class String
8
+ def remove_non_ascii
9
+ self.encode( "UTF-8", "binary", :invalid => :replace, :undef => :replace, :replace => '§')
10
+ end
11
+ def starts_with?(aString)
12
+ index(aString) == 0
13
+ end
14
+ end
15
+
16
+ class Object
17
+ def deep_copy
18
+ Marshal.load(Marshal.dump(self))
19
+ end
20
+ def blank?
21
+ return false if self.class == Symbol
22
+ self.nil? or (self.class==String and self.strip == '') or (self.respond_to?(:empty?) ? self.empty? : false)
23
+ end
24
+ end
25
+
26
+
27
+
28
+ module XData
29
+ ::I18n.enforce_available_locales = false
30
+ RD_P = Proj4::Projection.new('+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs')
31
+ LL_P = Proj4::Projection.new('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
32
+
33
+ def toPolygon(twopoints)
34
+ lon1 = twopoints[0].lon
35
+ lat1 = twopoints[0].lat
36
+ lon2 = twopoints[1].lon
37
+ lat2 = twopoints[1].lat
38
+
39
+ if lon1.between?(-7000.0,300000.0) and lat1.between?(289000.0,629000.0)
40
+ # Simple minded check for Dutch new rd system
41
+ a = XData.rd_to_wgs84(lon1,lat1)
42
+ lon1 = a[0]; lat1 = a[1]
43
+ a = XData.rd_to_wgs84(lon2,lat2)
44
+ lon2 = a[0]; lat2 = a[1]
45
+ end
46
+ return { type: 'Polygon', coordinates: [[lon1,lat1], [lon1,lat2], [lon2,lat2], [lon2,lat1], [lon1,lat1]] }
47
+ end
48
+
49
+
50
+ def self.rd_to_wgs84(x,y)
51
+ srcPoint = Proj4::Point.new(x, y)
52
+ dstPoint = RD_P.transform(LL_P, srcPoint)
53
+ [dstPoint.lon * (180 / Math::PI), dstPoint.lat * (180 / Math::PI)]
54
+ end
55
+
56
+ def self.headers(url)
57
+ begin
58
+ uri = URI(url)
59
+ http = Net::HTTP.new(uri.host, uri.port)
60
+ if url.scheme == 'https'
61
+ http.use_ssl = true
62
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
63
+ end
64
+ return http.head(uri.path.blank? ? "/" : uri.path).to_hash
65
+ rescue
66
+ end
67
+ nil
68
+ end
69
+
70
+ # for debugging purposes...
71
+ def jsonlog(o)
72
+ STDERR.puts JSON.pretty_generate({ o.class.to_s => o })
73
+ end
74
+
75
+ class Exception < ::Exception
76
+ def initialize(message,parms=nil,srcfile=nil,srcline=nil)
77
+ if parms and srcfile and srcline
78
+ file = File.basename( parms[:originalfile] ? parms[:originalfile] : ( parms[:file_path] || '-' ) )
79
+ m = "#{Time.now.strftime("%b %M %Y, %H:%M")}; XData, processing file: #{file}\n Exception in #{File.basename(srcfile)}, #{srcline}\n #{message}"
80
+ else
81
+ m = "#{Time.now.strftime("%b %M %Y, %H:%M")}; XData Exception: #{message}"
82
+ end
83
+ super(m)
84
+ $stderr.puts(m) if parms and parms[:verbose]
85
+ end
86
+ end
87
+
88
+ def self.parse_json(str)
89
+ begin
90
+ return str.blank? ? {} : JSON.parse(str, symbolize_names: true)
91
+ rescue Exception => e
92
+ raise XData::Exception.new("#{e.message}; input: #{str}")
93
+ end
94
+ end
95
+
96
+ end
97
+
98
+
99
+
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xdata
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Tom Demeyer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dbf
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: georuby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rgeo
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: charlock_holmes
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.6'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: curses
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ description: Provides analysis of (geo)data files.
98
+ email:
99
+ - tom@waag.org
100
+ executables:
101
+ - xdata
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/xdata
112
+ - lib/xdata.rb
113
+ - lib/xdata/file_reader.rb
114
+ - lib/xdata/pc4.gz
115
+ - lib/xdata/postcodes_4.rb
116
+ - lib/xdata/util.rb
117
+ homepage: http://waag.org
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.8
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Provides analisis of (geo)data files. Both interactive and command-line driven
141
+ test_files: []