cartodb-importer 0.2.17 → 0.2.18
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cartodb-importer/importer.rb +40 -0
- data/lib/cartodb-importer/version.rb +2 -2
- data/spec/import_spec.rb +15 -0
- metadata +106 -97
@@ -1,4 +1,11 @@
|
|
1
1
|
# coding: UTF-8
|
2
|
+
#
|
3
|
+
def get_temporal_filename (prefix)
|
4
|
+
tf = Tempfile.new(prefix)
|
5
|
+
tempname = tf.path
|
6
|
+
tf.close!
|
7
|
+
return tempname
|
8
|
+
end
|
2
9
|
|
3
10
|
module CartoDB
|
4
11
|
class Importer
|
@@ -131,6 +138,39 @@ module CartoDB
|
|
131
138
|
@ext = '.csv'
|
132
139
|
path = @import_from_file.path
|
133
140
|
end
|
141
|
+
|
142
|
+
# if the file is a gpx file import the track points with all associated data
|
143
|
+
# A GPX file generates 3 tables so it would be good to have the option to create
|
144
|
+
# and import all of them
|
145
|
+
if %W{ .gpx }.include?(@ext)
|
146
|
+
# generate a temporally file
|
147
|
+
shp_file = get_temporal_filename(path)
|
148
|
+
|
149
|
+
# extract the 3 shp files (and associated dbf and so on)
|
150
|
+
# it will create a folder
|
151
|
+
ogr2ogr_bin_path = `which ogr2ogr`.strip
|
152
|
+
# ogr2ogr does not manage well datetime fields in gpx to transform it to string in
|
153
|
+
# order to import correctly
|
154
|
+
ogr2ogr_command = %Q{#{ogr2ogr_bin_path} -fieldTypeToString DateTime -f "ESRI Shapefile" #{shp_file} #{path}}
|
155
|
+
out = `#{ogr2ogr_command}`
|
156
|
+
|
157
|
+
track_points = "#{shp_file}/track_points.shp"
|
158
|
+
runlog.stdout << track_points
|
159
|
+
# then choose the track_points file to import
|
160
|
+
if Dir.exists?(shp_file) and File.file?(track_points)
|
161
|
+
# add all files to entries to be removed
|
162
|
+
# add the path too in order to remove it
|
163
|
+
entries = Dir["#{shp_file}/*"]
|
164
|
+
entries << shp_file
|
165
|
+
|
166
|
+
path = track_points
|
167
|
+
# get the file to import and set extension to shp
|
168
|
+
@ext = '.shp'
|
169
|
+
else
|
170
|
+
runlog.err << "failed to create shp file from GPX"
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
134
174
|
|
135
175
|
if %W{ .kmz .kml .json .js }.include?(@ext)
|
136
176
|
ogr2ogr_bin_path = `which ogr2ogr`.strip
|
data/spec/import_spec.rb
CHANGED
@@ -322,6 +322,21 @@ describe CartoDB::Importer do
|
|
322
322
|
result.import_type.should == '.shp'
|
323
323
|
end
|
324
324
|
end
|
325
|
+
|
326
|
+
|
327
|
+
|
328
|
+
describe "import GPX file" do
|
329
|
+
it "should import GPX file" do
|
330
|
+
importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/route2.gpx", __FILE__),
|
331
|
+
:database => "cartodb_importer_test", :username => 'postgres', :password => '',
|
332
|
+
:host => 'localhost', :port => 5432
|
333
|
+
result = importer.import!
|
334
|
+
result.should_not == nil
|
335
|
+
result.name.should == 'route2'
|
336
|
+
#result.rows_imported.should == 29
|
337
|
+
result.import_type.should == '.gpx'
|
338
|
+
end
|
339
|
+
end
|
325
340
|
|
326
341
|
describe "Import from Simon file" do
|
327
342
|
it "should import a shapefile from Simon" do
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: cartodb-importer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.17
|
3
|
+
version: !ruby/object:Gem::Version
|
5
4
|
prerelease:
|
5
|
+
version: 0.2.18
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Fernando Blat
|
9
9
|
- Andrew Hill
|
10
10
|
- Javier de la Torre
|
@@ -12,147 +12,152 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
|
16
|
+
date: 2011-10-18 00:00:00 +02:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
18
20
|
name: pg
|
19
|
-
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
23
|
none: false
|
21
|
-
requirements:
|
24
|
+
requirements:
|
22
25
|
- - ~>
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version:
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: "0.11"
|
25
28
|
type: :runtime
|
26
|
-
|
27
|
-
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
+
version_requirements: *id001
|
30
|
+
- !ruby/object:Gem::Dependency
|
29
31
|
name: sequel
|
30
|
-
|
32
|
+
prerelease: false
|
33
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
34
|
none: false
|
32
|
-
requirements:
|
35
|
+
requirements:
|
33
36
|
- - ~>
|
34
|
-
- !ruby/object:Gem::Version
|
37
|
+
- !ruby/object:Gem::Version
|
35
38
|
version: 3.28.0
|
36
39
|
type: :runtime
|
37
|
-
|
38
|
-
|
39
|
-
- !ruby/object:Gem::Dependency
|
40
|
+
version_requirements: *id002
|
41
|
+
- !ruby/object:Gem::Dependency
|
40
42
|
name: roo
|
41
|
-
|
43
|
+
prerelease: false
|
44
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
45
|
none: false
|
43
|
-
requirements:
|
46
|
+
requirements:
|
44
47
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
48
|
+
- !ruby/object:Gem::Version
|
46
49
|
version: 1.9.7
|
47
50
|
type: :runtime
|
48
|
-
|
49
|
-
|
50
|
-
- !ruby/object:Gem::Dependency
|
51
|
+
version_requirements: *id003
|
52
|
+
- !ruby/object:Gem::Dependency
|
51
53
|
name: spreadsheet
|
52
|
-
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
56
|
none: false
|
54
|
-
requirements:
|
57
|
+
requirements:
|
55
58
|
- - ~>
|
56
|
-
- !ruby/object:Gem::Version
|
59
|
+
- !ruby/object:Gem::Version
|
57
60
|
version: 0.6.5.9
|
58
61
|
type: :runtime
|
59
|
-
|
60
|
-
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
+
version_requirements: *id004
|
63
|
+
- !ruby/object:Gem::Dependency
|
62
64
|
name: google-spreadsheet-ruby
|
63
|
-
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
67
|
none: false
|
65
|
-
requirements:
|
68
|
+
requirements:
|
66
69
|
- - ~>
|
67
|
-
- !ruby/object:Gem::Version
|
70
|
+
- !ruby/object:Gem::Version
|
68
71
|
version: 0.1.5
|
69
72
|
type: :runtime
|
70
|
-
|
71
|
-
|
72
|
-
- !ruby/object:Gem::Dependency
|
73
|
+
version_requirements: *id005
|
74
|
+
- !ruby/object:Gem::Dependency
|
73
75
|
name: rubyzip
|
74
|
-
|
76
|
+
prerelease: false
|
77
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
78
|
none: false
|
76
|
-
requirements:
|
79
|
+
requirements:
|
77
80
|
- - ~>
|
78
|
-
- !ruby/object:Gem::Version
|
81
|
+
- !ruby/object:Gem::Version
|
79
82
|
version: 0.9.4
|
80
83
|
type: :runtime
|
81
|
-
|
82
|
-
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
+
version_requirements: *id006
|
85
|
+
- !ruby/object:Gem::Dependency
|
84
86
|
name: builder
|
85
|
-
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
89
|
none: false
|
87
|
-
requirements:
|
88
|
-
- -
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version:
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
91
94
|
type: :runtime
|
92
|
-
|
93
|
-
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
+
version_requirements: *id007
|
96
|
+
- !ruby/object:Gem::Dependency
|
95
97
|
name: rgeo
|
96
|
-
|
98
|
+
prerelease: false
|
99
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
97
100
|
none: false
|
98
|
-
requirements:
|
101
|
+
requirements:
|
99
102
|
- - ~>
|
100
|
-
- !ruby/object:Gem::Version
|
103
|
+
- !ruby/object:Gem::Version
|
101
104
|
version: 0.3.2
|
102
105
|
type: :runtime
|
103
|
-
|
104
|
-
|
105
|
-
- !ruby/object:Gem::Dependency
|
106
|
+
version_requirements: *id008
|
107
|
+
- !ruby/object:Gem::Dependency
|
106
108
|
name: rgeo-geojson
|
107
|
-
|
109
|
+
prerelease: false
|
110
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
108
111
|
none: false
|
109
|
-
requirements:
|
112
|
+
requirements:
|
110
113
|
- - ~>
|
111
|
-
- !ruby/object:Gem::Version
|
114
|
+
- !ruby/object:Gem::Version
|
112
115
|
version: 0.2.1
|
113
116
|
type: :runtime
|
114
|
-
|
115
|
-
|
116
|
-
- !ruby/object:Gem::Dependency
|
117
|
+
version_requirements: *id009
|
118
|
+
- !ruby/object:Gem::Dependency
|
117
119
|
name: rspec
|
118
|
-
|
120
|
+
prerelease: false
|
121
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
119
122
|
none: false
|
120
|
-
requirements:
|
123
|
+
requirements:
|
121
124
|
- - ~>
|
122
|
-
- !ruby/object:Gem::Version
|
125
|
+
- !ruby/object:Gem::Version
|
123
126
|
version: 2.6.0
|
124
127
|
type: :development
|
125
|
-
|
126
|
-
|
127
|
-
- !ruby/object:Gem::Dependency
|
128
|
+
version_requirements: *id010
|
129
|
+
- !ruby/object:Gem::Dependency
|
128
130
|
name: mocha
|
129
|
-
|
131
|
+
prerelease: false
|
132
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
130
133
|
none: false
|
131
|
-
requirements:
|
134
|
+
requirements:
|
132
135
|
- - ~>
|
133
|
-
- !ruby/object:Gem::Version
|
136
|
+
- !ruby/object:Gem::Version
|
134
137
|
version: 0.10.0
|
135
138
|
type: :development
|
136
|
-
|
137
|
-
|
138
|
-
- !ruby/object:Gem::Dependency
|
139
|
+
version_requirements: *id011
|
140
|
+
- !ruby/object:Gem::Dependency
|
139
141
|
name: ruby-debug19
|
140
|
-
|
142
|
+
prerelease: false
|
143
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
141
144
|
none: false
|
142
|
-
requirements:
|
145
|
+
requirements:
|
143
146
|
- - ~>
|
144
|
-
- !ruby/object:Gem::Version
|
147
|
+
- !ruby/object:Gem::Version
|
145
148
|
version: 0.11.6
|
146
149
|
type: :development
|
147
|
-
|
148
|
-
version_requirements: *70363733324700
|
150
|
+
version_requirements: *id012
|
149
151
|
description: Import CSV, SHP, and other files with data into a PostgreSQL table
|
150
|
-
email:
|
152
|
+
email:
|
151
153
|
- andrew@vizzuality.com
|
152
154
|
executables: []
|
155
|
+
|
153
156
|
extensions: []
|
157
|
+
|
154
158
|
extra_rdoc_files: []
|
155
|
-
|
159
|
+
|
160
|
+
files:
|
156
161
|
- .gitignore
|
157
162
|
- .rvmrc
|
158
163
|
- Gemfile
|
@@ -177,31 +182,35 @@ files:
|
|
177
182
|
- spec/export_spec.rb
|
178
183
|
- spec/import_spec.rb
|
179
184
|
- spec/spec_helper.rb
|
180
|
-
|
185
|
+
has_rdoc: true
|
186
|
+
homepage: ""
|
181
187
|
licenses: []
|
188
|
+
|
182
189
|
post_install_message:
|
183
190
|
rdoc_options: []
|
184
|
-
|
191
|
+
|
192
|
+
require_paths:
|
185
193
|
- lib
|
186
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
194
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
195
|
none: false
|
188
|
-
requirements:
|
189
|
-
- -
|
190
|
-
- !ruby/object:Gem::Version
|
191
|
-
version:
|
192
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - ">="
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: "0"
|
200
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
201
|
none: false
|
194
|
-
requirements:
|
195
|
-
- -
|
196
|
-
- !ruby/object:Gem::Version
|
197
|
-
version:
|
202
|
+
requirements:
|
203
|
+
- - ">="
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: "0"
|
198
206
|
requirements: []
|
207
|
+
|
199
208
|
rubyforge_project: cartodb-importer
|
200
|
-
rubygems_version: 1.
|
209
|
+
rubygems_version: 1.6.2
|
201
210
|
signing_key:
|
202
211
|
specification_version: 3
|
203
212
|
summary: Import CSV, SHP, and other files with data into a PostgreSQL table
|
204
|
-
test_files:
|
213
|
+
test_files:
|
205
214
|
- spec/export_spec.rb
|
206
215
|
- spec/import_spec.rb
|
207
216
|
- spec/spec_helper.rb
|