geodublincreate 0.0.2
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.
- data/doc/classes/MyCallbacks.html +227 -0
- data/doc/classes/MyCallbacks.src/M000001.html +31 -0
- data/doc/classes/MyCallbacks.src/M000002.html +18 -0
- data/doc/classes/MyCallbacks.src/M000003.html +18 -0
- data/doc/classes/MyCallbacks.src/M000004.html +27 -0
- data/doc/classes/MyCallbacks.src/M000005.html +44 -0
- data/doc/classes/MyCallbacks.src/M000006.html +47 -0
- data/doc/created.rid +1 -0
- data/doc/files/geodublincreate_rb.html +194 -0
- data/doc/fr_class_index.html +27 -0
- data/doc/fr_file_index.html +27 -0
- data/doc/fr_method_index.html +32 -0
- data/doc/index.html +24 -0
- data/doc/rdoc-style.css +208 -0
- data/geodublincreate-0.0.1.gem +0 -0
- data/geodublincreate.gemspec +12 -0
- data/geodublincreate.gemspec~ +12 -0
- data/lib/configuration/database.yml +5 -0
- data/lib/data/dublinmap.osm +0 -0
- data/lib/data/testdata.osm +87976 -0
- data/lib/geodublincreate.rb +271 -0
- data/lib/geodublincreate.rb~ +261 -0
- data/lib/log/loggerfile +1 -0
- metadata +91 -0
@@ -0,0 +1,271 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
#
|
3
|
+
# geodublincreate.rb This file is a ruby file to take as input
|
4
|
+
# geo located data. This data is stored to a mysql database. The
|
5
|
+
# process will create and load the necessary table to store the
|
6
|
+
# geo located services data
|
7
|
+
#
|
8
|
+
# The process uses the Open Street Map data to find service geo
|
9
|
+
# located data such as
|
10
|
+
# - transport services
|
11
|
+
# - atm services
|
12
|
+
# - bicycle rental services
|
13
|
+
# - cafe/resturant services
|
14
|
+
# - shopping services
|
15
|
+
#
|
16
|
+
# See http://www.openstreetmap.org for details
|
17
|
+
#
|
18
|
+
# Requires Database table 'overlays' which is created by the process
|
19
|
+
#
|
20
|
+
# CREATE TABLE IF NOT EXISTS `event_publisher`.`overlays` (
|
21
|
+
# `id` INT NOT NULL AUTO_INCREMENT ,
|
22
|
+
# `ref_id` INT NOT NULL ,
|
23
|
+
# `lon` DOUBLE NOT NULL ,
|
24
|
+
# `lat` DOUBLE NOT NULL ,
|
25
|
+
# `name` VARCHAR(45) NULL ,
|
26
|
+
# `amenity` VARCHAR(45) NULL ,
|
27
|
+
# `operator` VARCHAR(45) NULL ,
|
28
|
+
# `typeof` VARCHAR(45) NOT NULL ,
|
29
|
+
# PRIMARY KEY (`id`) )
|
30
|
+
# ENGINE = InnoDB;
|
31
|
+
#
|
32
|
+
# Copyright (c) 2011 Sean Cahill
|
33
|
+
# Released under the same terms as Ruby
|
34
|
+
#
|
35
|
+
# read command line arguments
|
36
|
+
# Arguments optional [-f filename] where filename contains osm data
|
37
|
+
#
|
38
|
+
# Arguments optional if no file passed
|
39
|
+
# bounding box to pull geo located nodes from openstreet data
|
40
|
+
# by calling openstreet api
|
41
|
+
#
|
42
|
+
# -n nothern latitude
|
43
|
+
# -s southern latitude
|
44
|
+
# -w western latiude
|
45
|
+
# -e eastern lattitude
|
46
|
+
#
|
47
|
+
# optional argument -mode "test"/"prod"
|
48
|
+
#
|
49
|
+
# example useage
|
50
|
+
#
|
51
|
+
# ruby geodublincreate.rb -f ./data/geocreateddata.osm
|
52
|
+
#
|
53
|
+
# ruby geodublincreate.rb -mode test
|
54
|
+
#
|
55
|
+
# ruby geodublincreate.rb -n 53.3606 -s 53.333 -e -6.2069 -w -6.275
|
56
|
+
#
|
57
|
+
# database configuration file contained in ./data
|
58
|
+
# database.yml
|
59
|
+
# hostname : name of host server
|
60
|
+
# username : mysql database user id
|
61
|
+
# password : mysql database password
|
62
|
+
# database : mysql database
|
63
|
+
#
|
64
|
+
# log file created in ./log as loggerfile
|
65
|
+
#
|
66
|
+
require 'rubygems'
|
67
|
+
require 'net/http'
|
68
|
+
require 'mysql2'
|
69
|
+
require 'OSM/Database'
|
70
|
+
ENV['OSMLIBX_XML_PARSER']='Libxml'
|
71
|
+
require 'OSM/StreamParser'
|
72
|
+
|
73
|
+
class MyCallbacks < OSM::Callbacks
|
74
|
+
|
75
|
+
attr_accessor :dbconn
|
76
|
+
|
77
|
+
def initialize(conn)
|
78
|
+
@dbconn = conn
|
79
|
+
dropstring = "DROP TABLE IF EXISTS overlays"
|
80
|
+
@dbconn.query(dropstring)
|
81
|
+
createstring="CREATE TABLE overlays
|
82
|
+
(id INT NOT NULL AUTO_INCREMENT ,
|
83
|
+
ref_id INT NOT NULL ,
|
84
|
+
lon DOUBLE NOT NULL ,
|
85
|
+
lat DOUBLE NOT NULL ,
|
86
|
+
name VARCHAR(45) NULL ,
|
87
|
+
amenity VARCHAR(45) NULL ,
|
88
|
+
operator VARCHAR(45) NULL ,
|
89
|
+
typeof VARCHAR(45) NOT NULL ,
|
90
|
+
PRIMARY KEY (id) ) ENGINE = InnoDB;"
|
91
|
+
@dbconn.query(createstring)
|
92
|
+
end
|
93
|
+
|
94
|
+
def way(way)
|
95
|
+
false
|
96
|
+
end
|
97
|
+
|
98
|
+
def relation(relation)
|
99
|
+
false
|
100
|
+
end
|
101
|
+
|
102
|
+
def formatandstore(nodetostore)
|
103
|
+
insertstring = "insert into overlays (ref_id,lon,lat,typeof,name,amenity,operator) values (" +
|
104
|
+
nodetostore[:id].to_s + "," +
|
105
|
+
nodetostore[:lon].to_s + "," +
|
106
|
+
nodetostore[:lat].to_s + ",\"" +
|
107
|
+
nodetostore[:type].to_s + "\",\"" +
|
108
|
+
nodetostore[:name].to_s + "\",\"" +
|
109
|
+
nodetostore[:amenity].to_s + "\",\"" +
|
110
|
+
nodetostore[:operator].to_s + "\")"
|
111
|
+
|
112
|
+
@dbconn.query(insertstring)
|
113
|
+
end
|
114
|
+
|
115
|
+
def extract_data(id,lon,lat,type,tags)
|
116
|
+
node_to_store = {:id => nil,:lon => nil, :lat => nil, :type => nil, :name => nil, :amenity => nil, :operator => nil}
|
117
|
+
node_to_store[:id] = id
|
118
|
+
node_to_store[:lon] = lon
|
119
|
+
node_to_store[:lat] = lat
|
120
|
+
node_to_store[:type] = type
|
121
|
+
|
122
|
+
tags.each_pair do
|
123
|
+
| key,value |
|
124
|
+
|
125
|
+
if key == 'name'
|
126
|
+
node_to_store[:name] = value
|
127
|
+
end
|
128
|
+
if key == 'amenity'
|
129
|
+
node_to_store[:amenity] = value
|
130
|
+
end
|
131
|
+
if key == 'operator'
|
132
|
+
node_to_store[:operator] = value
|
133
|
+
end
|
134
|
+
if key == 'highway' || key == 'railway'
|
135
|
+
node_to_store[:name] = value if node_to_store[:name].nil?
|
136
|
+
node_to_store[:amenity] = value
|
137
|
+
end
|
138
|
+
if key == 'shop'
|
139
|
+
node_to_store[:amenity] = key if node_to_store[:amenity].nil?
|
140
|
+
end
|
141
|
+
end
|
142
|
+
self.formatandstore(node_to_store)
|
143
|
+
end
|
144
|
+
|
145
|
+
def node(node)
|
146
|
+
|
147
|
+
if (node.amenity == 'cafe' || node.amenity == 'fast_food' || node.amenity == 'resturant' || node.amenity == 'cafe')
|
148
|
+
extract_data(node.id,node.lon,node.lat,"eating",node.tags)
|
149
|
+
return true
|
150
|
+
end
|
151
|
+
if (node.amenity == 'bank' and node.atm = "yes")
|
152
|
+
extract_data(node.id,node.lon,node.lat,"atm",node.tags)
|
153
|
+
return true
|
154
|
+
end
|
155
|
+
if node.amenity == 'atm'
|
156
|
+
extract_data(node.id,node.lon,node.lat,"atm",node.tags)
|
157
|
+
return true
|
158
|
+
end
|
159
|
+
if (node.shop == 'convenience' || node.shop == 'supermarket')
|
160
|
+
extract_data(node.id,node.lon,node.lat,node.shop,node.tags)
|
161
|
+
return true
|
162
|
+
end
|
163
|
+
if (node.railway == 'station' || node.railway == 'tram_stop' || node.highway == 'bus_stop')
|
164
|
+
extract_data(node.id,node.lon,node.lat,"transport",node.tags)
|
165
|
+
return true
|
166
|
+
end
|
167
|
+
if (node.amenity == 'bicycle_rental' )
|
168
|
+
extract_data(node.id,node.lon,node.lat,"bike rental",node.tags)
|
169
|
+
return true
|
170
|
+
end
|
171
|
+
if (node.amenity == 'pub' )
|
172
|
+
extract_data(node.id,node.lon,node.lat,"pub",node.tags)
|
173
|
+
return true
|
174
|
+
end
|
175
|
+
false
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
begin
|
180
|
+
mode = "prod"
|
181
|
+
filename = nil
|
182
|
+
logfile = File.new("./log/loggerfile","w")
|
183
|
+
logfile.puts "You entered the following #{ARGV.length} command line arguments:"
|
184
|
+
raise ArgumentError,"Invalid number of Arguments" unless ARGV.count.even?
|
185
|
+
raise ArgumentError,"Error No Arguments" if ARGV.length == 0
|
186
|
+
count = 0
|
187
|
+
argshash = {}
|
188
|
+
ARGV.each do|arg|
|
189
|
+
if count.even?
|
190
|
+
geonumber = ARGV[count + 1].to_f
|
191
|
+
raise ArgumentError,"invalid parameter ,format is -n latitude/longitude number" if geonumber == 0.0 and arg != "-mode" and arg != "-f"
|
192
|
+
|
193
|
+
|
194
|
+
if geonumber == 0.0
|
195
|
+
argshash[arg] = ARGV[count + 1]
|
196
|
+
else
|
197
|
+
argshash[arg] = geonumber
|
198
|
+
end
|
199
|
+
end
|
200
|
+
count = count + 1
|
201
|
+
end
|
202
|
+
if !(argshash.keys.include?("-f"))
|
203
|
+
raise ArgumentError,"-n parameter required" unless argshash.keys.include?("-n")
|
204
|
+
raise ArgumentError,"-s parameter required" unless argshash.keys.include?("-s")
|
205
|
+
raise ArgumentError,"-e parameter required" unless argshash.keys.include?("-e")
|
206
|
+
raise ArgumentError,"-w parameter required" unless argshash.keys.include?("-w")
|
207
|
+
else
|
208
|
+
filename = argshash["-f"]
|
209
|
+
raise ArgumentError,"No file exists,#{filename}" unless File.exists?(filename)
|
210
|
+
puts filename
|
211
|
+
end
|
212
|
+
rescue => e
|
213
|
+
logfile.puts e.message + " exiting"
|
214
|
+
logfile.close if logfile
|
215
|
+
exit
|
216
|
+
end
|
217
|
+
if filename.nil? ## we are passing a file to the osm parser
|
218
|
+
begin
|
219
|
+
logfile.puts "Getting OpenStreet Data"
|
220
|
+
|
221
|
+
mode = argshash["-mode"] if argshash.keys.include?("-mode")
|
222
|
+
logfile.puts mode.inspect
|
223
|
+
if mode == "test"
|
224
|
+
logfile.puts "In test mode"
|
225
|
+
## format of call to openstreet api left,bottom,right,top west,south,east,north
|
226
|
+
resp = Net::HTTP.get_response(URI.parse('http://www.openstreetmap.org/api/0.6/map?bbox=-6.24571,53.3473,-6.23951,53.35006'))
|
227
|
+
else
|
228
|
+
logfile.puts "In prod mode"
|
229
|
+
url = "http://www.openstreetmap.org/api/0.6/map?bbox=#{argshash["-w"]},#{argshash["-s"]},#{argshash["-e"]},#{argshash["-n"]}"
|
230
|
+
logfile.puts url
|
231
|
+
resp = Net::HTTP.get_response(URI.parse("http://www.openstreetmap.org/api/0.6/map?bbox=#{argshash["-w"]},#{argshash["-s"]},#{argshash["-e"]},#{argshash["-n"]}"))
|
232
|
+
end
|
233
|
+
|
234
|
+
puts resp.inspect
|
235
|
+
filename = "./data/dublinmap.osm"
|
236
|
+
f = File.new(filename,"w")
|
237
|
+
|
238
|
+
logfile.puts "Response from openstreet not valid" unless resp.value.nil?
|
239
|
+
|
240
|
+
f.puts resp.body if resp.value.nil?
|
241
|
+
rescue => e
|
242
|
+
logfile.puts "Exception Reading openstreet data"
|
243
|
+
f.close if f
|
244
|
+
logfile.close if logfile
|
245
|
+
exit
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
begin
|
250
|
+
require 'yaml'
|
251
|
+
dbconfig = YAML::load(File.open("./configuration/database.yml","r"))
|
252
|
+
|
253
|
+
client = Mysql2::Client.new(:host => dbconfig[:host], :username => dbconfig[:username], :password => dbconfig[:password], :database => dbconfig[:database])
|
254
|
+
puts client.inspect
|
255
|
+
cb = MyCallbacks.new(client)
|
256
|
+
parser = OSM::StreamParser.new(:filename => filename, :callbacks => cb)
|
257
|
+
|
258
|
+
parser.parse
|
259
|
+
|
260
|
+
rescue Mysql2::Error => e
|
261
|
+
logfile.puts "Error code: #{e.errno}"
|
262
|
+
logfile.puts "Error message: #{e.error}"
|
263
|
+
logfile.puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
|
264
|
+
rescue => e
|
265
|
+
logfile.puts "Exception Error: " + e.message
|
266
|
+
ensure
|
267
|
+
# disconnect from server
|
268
|
+
client.close if client
|
269
|
+
end
|
270
|
+
|
271
|
+
|
@@ -0,0 +1,261 @@
|
|
1
|
+
#!/usr/local/bin/ruby
|
2
|
+
#
|
3
|
+
# geodublincreate.rb This file is a ruby file to take as input
|
4
|
+
# geo located data. This data is stored to a mysql database. The
|
5
|
+
# process will create and load the necessary table to store the
|
6
|
+
# geo located services data
|
7
|
+
#
|
8
|
+
# The process uses the Open Street Map data to find service geo
|
9
|
+
# located data such as
|
10
|
+
# - transport services
|
11
|
+
# - atm services
|
12
|
+
# - bicycle rental services
|
13
|
+
# - cafe/resturant services
|
14
|
+
# - shopping services
|
15
|
+
#
|
16
|
+
# See http://www.openstreetmap.org for details
|
17
|
+
#
|
18
|
+
# Requires Database table 'overlays' which is created by the process
|
19
|
+
#
|
20
|
+
# CREATE TABLE IF NOT EXISTS `event_publisher`.`overlays` (
|
21
|
+
# `id` INT NOT NULL AUTO_INCREMENT ,
|
22
|
+
# `ref_id` INT NOT NULL ,
|
23
|
+
# `lon` DOUBLE NOT NULL ,
|
24
|
+
# `lat` DOUBLE NOT NULL ,
|
25
|
+
# `name` VARCHAR(45) NULL ,
|
26
|
+
# `amenity` VARCHAR(45) NULL ,
|
27
|
+
# `operator` VARCHAR(45) NULL ,
|
28
|
+
# `typeof` VARCHAR(45) NOT NULL ,
|
29
|
+
# PRIMARY KEY (`id`) )
|
30
|
+
# ENGINE = InnoDB;
|
31
|
+
#
|
32
|
+
# Copyright (c) 2011 Sean Cahill
|
33
|
+
# Released under the same terms as Ruby
|
34
|
+
#
|
35
|
+
# read command line arguments
|
36
|
+
# Arguments optional [-f filename] where filename contains osm data
|
37
|
+
#
|
38
|
+
# Arguments optional if no file passed
|
39
|
+
# bounding box to pull geo located nodes from openstreet data
|
40
|
+
# by calling openstreet api
|
41
|
+
# -n nothern latitude
|
42
|
+
# -s southern latitude
|
43
|
+
# -w western latiude
|
44
|
+
# -e eastern lattitude
|
45
|
+
#
|
46
|
+
# optional argument -mode "test"/"prod"
|
47
|
+
#
|
48
|
+
#
|
49
|
+
# database configuration file
|
50
|
+
# database.yml
|
51
|
+
# hostname : name of host server
|
52
|
+
# username : mysql database user id
|
53
|
+
# password : mysql database password
|
54
|
+
# database : mysql database
|
55
|
+
#
|
56
|
+
require 'rubygems'
|
57
|
+
require 'net/http'
|
58
|
+
require 'mysql2'
|
59
|
+
require 'OSM/Database'
|
60
|
+
ENV['OSMLIBX_XML_PARSER']='Libxml'
|
61
|
+
require 'OSM/StreamParser'
|
62
|
+
|
63
|
+
class MyCallbacks < OSM::Callbacks
|
64
|
+
|
65
|
+
attr_accessor :dbconn
|
66
|
+
|
67
|
+
def initialize(conn)
|
68
|
+
@dbconn = conn
|
69
|
+
dropstring = "DROP TABLE IF EXISTS overlays"
|
70
|
+
@dbconn.query(dropstring)
|
71
|
+
createstring="CREATE TABLE overlays
|
72
|
+
(id INT NOT NULL AUTO_INCREMENT ,
|
73
|
+
ref_id INT NOT NULL ,
|
74
|
+
lon DOUBLE NOT NULL ,
|
75
|
+
lat DOUBLE NOT NULL ,
|
76
|
+
name VARCHAR(45) NULL ,
|
77
|
+
amenity VARCHAR(45) NULL ,
|
78
|
+
operator VARCHAR(45) NULL ,
|
79
|
+
typeof VARCHAR(45) NOT NULL ,
|
80
|
+
PRIMARY KEY (id) ) ENGINE = InnoDB;"
|
81
|
+
@dbconn.query(createstring)
|
82
|
+
end
|
83
|
+
|
84
|
+
def way(way)
|
85
|
+
false
|
86
|
+
end
|
87
|
+
|
88
|
+
def relation(relation)
|
89
|
+
false
|
90
|
+
end
|
91
|
+
|
92
|
+
def formatandstore(nodetostore)
|
93
|
+
insertstring = "insert into overlays (ref_id,lon,lat,typeof,name,amenity,operator) values (" +
|
94
|
+
nodetostore[:id].to_s + "," +
|
95
|
+
nodetostore[:lon].to_s + "," +
|
96
|
+
nodetostore[:lat].to_s + ",\"" +
|
97
|
+
nodetostore[:type].to_s + "\",\"" +
|
98
|
+
nodetostore[:name].to_s + "\",\"" +
|
99
|
+
nodetostore[:amenity].to_s + "\",\"" +
|
100
|
+
nodetostore[:operator].to_s + "\")"
|
101
|
+
|
102
|
+
@dbconn.query(insertstring)
|
103
|
+
end
|
104
|
+
|
105
|
+
def extract_data(id,lon,lat,type,tags)
|
106
|
+
node_to_store = {:id => nil,:lon => nil, :lat => nil, :type => nil, :name => nil, :amenity => nil, :operator => nil}
|
107
|
+
node_to_store[:id] = id
|
108
|
+
node_to_store[:lon] = lon
|
109
|
+
node_to_store[:lat] = lat
|
110
|
+
node_to_store[:type] = type
|
111
|
+
|
112
|
+
tags.each_pair do
|
113
|
+
| key,value |
|
114
|
+
|
115
|
+
if key == 'name'
|
116
|
+
node_to_store[:name] = value
|
117
|
+
end
|
118
|
+
if key == 'amenity'
|
119
|
+
node_to_store[:amenity] = value
|
120
|
+
end
|
121
|
+
if key == 'operator'
|
122
|
+
node_to_store[:operator] = value
|
123
|
+
end
|
124
|
+
if key == 'highway' || key == 'railway'
|
125
|
+
node_to_store[:name] = value if node_to_store[:name].nil?
|
126
|
+
node_to_store[:amenity] = value
|
127
|
+
end
|
128
|
+
if key == 'shop'
|
129
|
+
node_to_store[:amenity] = key if node_to_store[:amenity].nil?
|
130
|
+
end
|
131
|
+
end
|
132
|
+
self.formatandstore(node_to_store)
|
133
|
+
end
|
134
|
+
|
135
|
+
def node(node)
|
136
|
+
|
137
|
+
if (node.amenity == 'cafe' || node.amenity == 'fast_food' || node.amenity == 'resturant' || node.amenity == 'cafe')
|
138
|
+
extract_data(node.id,node.lon,node.lat,"eating",node.tags)
|
139
|
+
return true
|
140
|
+
end
|
141
|
+
if (node.amenity == 'bank' and node.atm = "yes")
|
142
|
+
extract_data(node.id,node.lon,node.lat,"atm",node.tags)
|
143
|
+
return true
|
144
|
+
end
|
145
|
+
if node.amenity == 'atm'
|
146
|
+
extract_data(node.id,node.lon,node.lat,"atm",node.tags)
|
147
|
+
return true
|
148
|
+
end
|
149
|
+
if (node.shop == 'convenience' || node.shop == 'supermarket')
|
150
|
+
extract_data(node.id,node.lon,node.lat,node.shop,node.tags)
|
151
|
+
return true
|
152
|
+
end
|
153
|
+
if (node.railway == 'station' || node.railway == 'tram_stop' || node.highway == 'bus_stop')
|
154
|
+
extract_data(node.id,node.lon,node.lat,"transport",node.tags)
|
155
|
+
return true
|
156
|
+
end
|
157
|
+
if (node.amenity == 'bicycle_rental' )
|
158
|
+
extract_data(node.id,node.lon,node.lat,"bike rental",node.tags)
|
159
|
+
return true
|
160
|
+
end
|
161
|
+
if (node.amenity == 'pub' )
|
162
|
+
extract_data(node.id,node.lon,node.lat,"pub",node.tags)
|
163
|
+
return true
|
164
|
+
end
|
165
|
+
false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
begin
|
170
|
+
mode = "prod"
|
171
|
+
filename = nil
|
172
|
+
logfile = File.new("./log/loggerfile","w")
|
173
|
+
logfile.puts "You entered the following #{ARGV.length} command line arguments:"
|
174
|
+
raise ArgumentError,"Invalid number of Arguments" unless ARGV.count.even?
|
175
|
+
raise ArgumentError,"Error No Arguments" if ARGV.length == 0
|
176
|
+
count = 0
|
177
|
+
argshash = {}
|
178
|
+
ARGV.each do|arg|
|
179
|
+
if count.even?
|
180
|
+
geonumber = ARGV[count + 1].to_f
|
181
|
+
raise ArgumentError,"invalid parameter ,format is -n latitude/longitude number" if geonumber == 0.0 and arg != "-mode" and arg != "-f"
|
182
|
+
|
183
|
+
|
184
|
+
if geonumber == 0.0
|
185
|
+
argshash[arg] = ARGV[count + 1]
|
186
|
+
else
|
187
|
+
argshash[arg] = geonumber
|
188
|
+
end
|
189
|
+
end
|
190
|
+
count = count + 1
|
191
|
+
end
|
192
|
+
if !(argshash.keys.include?("-f"))
|
193
|
+
raise ArgumentError,"-n parameter required" unless argshash.keys.include?("-n")
|
194
|
+
raise ArgumentError,"-s parameter required" unless argshash.keys.include?("-s")
|
195
|
+
raise ArgumentError,"-e parameter required" unless argshash.keys.include?("-e")
|
196
|
+
raise ArgumentError,"-w parameter required" unless argshash.keys.include?("-w")
|
197
|
+
else
|
198
|
+
filename = argshash["-f"]
|
199
|
+
raise ArgumentError,"No file exists,#{filename}" unless File.exists?(filename)
|
200
|
+
puts filename
|
201
|
+
end
|
202
|
+
rescue => e
|
203
|
+
logfile.puts e.message + " exiting"
|
204
|
+
logfile.close if logfile
|
205
|
+
exit
|
206
|
+
end
|
207
|
+
if filename.nil? ## we are passing a file to the osm parser
|
208
|
+
begin
|
209
|
+
logfile.puts "Getting OpenStreet Data"
|
210
|
+
|
211
|
+
mode = argshash["-mode"] if argshash.keys.include?("-mode")
|
212
|
+
logfile.puts mode.inspect
|
213
|
+
if mode == "test"
|
214
|
+
logfile.puts "In test mode"
|
215
|
+
## format of call to openstreet api left,bottom,right,top west,south,east,north
|
216
|
+
resp = Net::HTTP.get_response(URI.parse('http://www.openstreetmap.org/api/0.6/map?bbox=-6.24571,53.3473,-6.23951,53.35006'))
|
217
|
+
else
|
218
|
+
logfile.puts "In prod mode"
|
219
|
+
url = "http://www.openstreetmap.org/api/0.6/map?bbox=#{argshash["-w"]},#{argshash["-s"]},#{argshash["-e"]},#{argshash["-n"]}"
|
220
|
+
logfile.puts url
|
221
|
+
resp = Net::HTTP.get_response(URI.parse("http://www.openstreetmap.org/api/0.6/map?bbox=#{argshash["-w"]},#{argshash["-s"]},#{argshash["-e"]},#{argshash["-n"]}"))
|
222
|
+
end
|
223
|
+
|
224
|
+
puts resp.inspect
|
225
|
+
filename = "./data/dublinmap.osm"
|
226
|
+
f = File.new(filename,"w")
|
227
|
+
|
228
|
+
logfile.puts "Response from openstreet not valid" unless resp.value.nil?
|
229
|
+
|
230
|
+
f.puts resp.body if resp.value.nil?
|
231
|
+
rescue => e
|
232
|
+
logfile.puts "Exception Reading openstreet data"
|
233
|
+
f.close if f
|
234
|
+
logfile.close if logfile
|
235
|
+
exit
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
begin
|
240
|
+
require 'yaml'
|
241
|
+
dbconfig = YAML::load(File.open("./configuration/database.yml","r"))
|
242
|
+
|
243
|
+
client = Mysql2::Client.new(:host => dbconfig[:host], :username => dbconfig[:username], :password => dbconfig[:password], :database => dbconfig[:database])
|
244
|
+
puts client.inspect
|
245
|
+
cb = MyCallbacks.new(client)
|
246
|
+
parser = OSM::StreamParser.new(:filename => filename, :callbacks => cb)
|
247
|
+
|
248
|
+
parser.parse
|
249
|
+
|
250
|
+
rescue Mysql2::Error => e
|
251
|
+
logfile.puts "Error code: #{e.errno}"
|
252
|
+
logfile.puts "Error message: #{e.error}"
|
253
|
+
logfile.puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
|
254
|
+
rescue => e
|
255
|
+
logfile.puts "Exception Error: " + e.message
|
256
|
+
ensure
|
257
|
+
# disconnect from server
|
258
|
+
client.close if client
|
259
|
+
end
|
260
|
+
|
261
|
+
|
data/lib/log/loggerfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
You entered the following 2 command line arguments:
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geodublincreate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Sean Cahill
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-27 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description:
|
23
|
+
email: sean.cahill@student.ncirl.ie
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- geodublincreate-0.0.1.gem
|
32
|
+
- lib/geodublincreate.rb
|
33
|
+
- lib/geodublincreate.rb~
|
34
|
+
- lib/log/loggerfile
|
35
|
+
- lib/data/dublinmap.osm
|
36
|
+
- lib/data/testdata.osm
|
37
|
+
- lib/configuration/database.yml
|
38
|
+
- geodublincreate.gemspec
|
39
|
+
- doc/created.rid
|
40
|
+
- doc/rdoc-style.css
|
41
|
+
- doc/fr_method_index.html
|
42
|
+
- doc/classes/MyCallbacks.html
|
43
|
+
- doc/classes/MyCallbacks.src/M000006.html
|
44
|
+
- doc/classes/MyCallbacks.src/M000002.html
|
45
|
+
- doc/classes/MyCallbacks.src/M000004.html
|
46
|
+
- doc/classes/MyCallbacks.src/M000001.html
|
47
|
+
- doc/classes/MyCallbacks.src/M000005.html
|
48
|
+
- doc/classes/MyCallbacks.src/M000003.html
|
49
|
+
- doc/files/geodublincreate_rb.html
|
50
|
+
- doc/index.html
|
51
|
+
- doc/fr_class_index.html
|
52
|
+
- doc/fr_file_index.html
|
53
|
+
- geodublincreate.gemspec~
|
54
|
+
has_rdoc: true
|
55
|
+
homepage:
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 51
|
69
|
+
segments:
|
70
|
+
- 1
|
71
|
+
- 8
|
72
|
+
- 2
|
73
|
+
version: 1.8.2
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.4.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: GeoDublinCreate takes openstreet data and stores geo located services to a mysql database file
|
90
|
+
test_files: []
|
91
|
+
|