cartodb-importer 0.2.18 → 0.2.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+
2
+
3
+ module CartoDB
4
+ # class to get the point number in GPX files
5
+ class GPX
6
+
7
+ def initialize(filename)
8
+ @filename = filename
9
+ @ogr2ogr_bin_path = `which ogr2ogr`.strip
10
+ end
11
+
12
+ def _points_for(table)
13
+ cmd = "#{@ogr2ogr_bin_path} -f CSV /vsistdout/ #{@filename} -sql 'select count(*) from #{table}'"
14
+ #RUBY WAY
15
+ `#{cmd}`.strip.split[1].to_i
16
+ end
17
+
18
+ def track_points
19
+ _points_for('track_points')
20
+ end
21
+
22
+ def route_points
23
+ _points_for('route_points')
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+
@@ -1,5 +1,8 @@
1
1
  # coding: UTF-8
2
2
  #
3
+
4
+ require File.dirname(__FILE__) + '/gpx'
5
+
3
6
  def get_temporal_filename (prefix)
4
7
  tf = Tempfile.new(prefix)
5
8
  tempname = tf.path
@@ -154,16 +157,26 @@ module CartoDB
154
157
  ogr2ogr_command = %Q{#{ogr2ogr_bin_path} -fieldTypeToString DateTime -f "ESRI Shapefile" #{shp_file} #{path}}
155
158
  out = `#{ogr2ogr_command}`
156
159
 
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)
160
+ # GPX files has 3 interesting "tables", route points, track_points and way_points
161
+ # this importer tries to imprt track_points first, if thereis no points, route_points
162
+ # is imported
163
+ gpx = CartoDB::GPX.new path
164
+ if gpx.track_points > 0
165
+ points = "#{shp_file}/track_points.shp"
166
+ elsif gpx.route_points > 0
167
+ points = "#{shp_file}/route_points.shp"
168
+ else
169
+ points = "#{shp_file}/waypoints.shp"
170
+ end
171
+ runlog.stdout << points
172
+ # then choose the points file to import
173
+ if Dir.exists?(shp_file) and File.file?(points)
161
174
  # add all files to entries to be removed
162
175
  # add the path too in order to remove it
163
176
  entries = Dir["#{shp_file}/*"]
164
177
  entries << shp_file
165
178
 
166
- path = track_points
179
+ path = points
167
180
  # get the file to import and set extension to shp
168
181
  @ext = '.shp'
169
182
  else
@@ -1,6 +1,6 @@
1
1
  module CartoDB
2
2
  class Importer
3
- VERSION = "0.2.18"
3
+ VERSION = "0.2.19"
4
4
  end
5
5
  end
6
6
 
@@ -0,0 +1,26 @@
1
+
2
+ require 'spec_helper'
3
+ require File.expand_path("../../lib/cartodb-importer/gpx", __FILE__)
4
+
5
+
6
+ describe CartoDB::GPX do
7
+ it "should return the track point number in file" do
8
+ gpx = CartoDB::GPX.new (File.expand_path("../support/data/route2.gpx", __FILE__))
9
+ gpx.track_points.should == 822
10
+ end
11
+ it "should return the route point number in file" do
12
+ gpx = CartoDB::GPX.new (File.expand_path("../support/data/route2.gpx", __FILE__))
13
+ gpx.route_points.should == 0
14
+ end
15
+
16
+ it "should return the track point number in file whiout track_points" do
17
+ gpx = CartoDB::GPX.new (File.expand_path("../support/data/ex.gpx", __FILE__))
18
+ gpx.track_points.should == 0
19
+ end
20
+
21
+ it "should return the route point number in file whit only route points" do
22
+ gpx = CartoDB::GPX.new (File.expand_path("../support/data/ex.gpx", __FILE__))
23
+ gpx.route_points.should == 46
24
+ end
25
+ end
26
+
@@ -333,7 +333,17 @@ describe CartoDB::Importer do
333
333
  result = importer.import!
334
334
  result.should_not == nil
335
335
  result.name.should == 'route2'
336
- #result.rows_imported.should == 29
336
+ result.rows_imported.should == 822
337
+ result.import_type.should == '.gpx'
338
+ end
339
+ it "should import GPX file whiout track_points" do
340
+ importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/ex.gpx", __FILE__),
341
+ :database => "cartodb_importer_test", :username => 'postgres', :password => '',
342
+ :host => 'localhost', :port => 5432
343
+ result = importer.import!
344
+ result.should_not == nil
345
+ result.name.should == 'ex'
346
+ result.rows_imported.should == 46
337
347
  result.import_type.should == '.gpx'
338
348
  end
339
349
  end
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
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.19
4
5
  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,152 +12,147 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
-
16
- date: 2011-10-18 00:00:00 +02:00
17
- default_executable:
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
15
+ date: 2011-10-19 00:00:00.000000000Z
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
20
18
  name: pg
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
19
+ requirement: &70735990 !ruby/object:Gem::Requirement
23
20
  none: false
24
- requirements:
21
+ requirements:
25
22
  - - ~>
26
- - !ruby/object:Gem::Version
27
- version: "0.11"
23
+ - !ruby/object:Gem::Version
24
+ version: '0.11'
28
25
  type: :runtime
29
- version_requirements: *id001
30
- - !ruby/object:Gem::Dependency
31
- name: sequel
32
26
  prerelease: false
33
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ version_requirements: *70735990
28
+ - !ruby/object:Gem::Dependency
29
+ name: sequel
30
+ requirement: &70735570 !ruby/object:Gem::Requirement
34
31
  none: false
35
- requirements:
32
+ requirements:
36
33
  - - ~>
37
- - !ruby/object:Gem::Version
34
+ - !ruby/object:Gem::Version
38
35
  version: 3.28.0
39
36
  type: :runtime
40
- version_requirements: *id002
41
- - !ruby/object:Gem::Dependency
42
- name: roo
43
37
  prerelease: false
44
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ version_requirements: *70735570
39
+ - !ruby/object:Gem::Dependency
40
+ name: roo
41
+ requirement: &70735120 !ruby/object:Gem::Requirement
45
42
  none: false
46
- requirements:
43
+ requirements:
47
44
  - - ~>
48
- - !ruby/object:Gem::Version
45
+ - !ruby/object:Gem::Version
49
46
  version: 1.9.7
50
47
  type: :runtime
51
- version_requirements: *id003
52
- - !ruby/object:Gem::Dependency
53
- name: spreadsheet
54
48
  prerelease: false
55
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ version_requirements: *70735120
50
+ - !ruby/object:Gem::Dependency
51
+ name: spreadsheet
52
+ requirement: &70734620 !ruby/object:Gem::Requirement
56
53
  none: false
57
- requirements:
54
+ requirements:
58
55
  - - ~>
59
- - !ruby/object:Gem::Version
56
+ - !ruby/object:Gem::Version
60
57
  version: 0.6.5.9
61
58
  type: :runtime
62
- version_requirements: *id004
63
- - !ruby/object:Gem::Dependency
64
- name: google-spreadsheet-ruby
65
59
  prerelease: false
66
- requirement: &id005 !ruby/object:Gem::Requirement
60
+ version_requirements: *70734620
61
+ - !ruby/object:Gem::Dependency
62
+ name: google-spreadsheet-ruby
63
+ requirement: &70733970 !ruby/object:Gem::Requirement
67
64
  none: false
68
- requirements:
65
+ requirements:
69
66
  - - ~>
70
- - !ruby/object:Gem::Version
67
+ - !ruby/object:Gem::Version
71
68
  version: 0.1.5
72
69
  type: :runtime
73
- version_requirements: *id005
74
- - !ruby/object:Gem::Dependency
75
- name: rubyzip
76
70
  prerelease: false
77
- requirement: &id006 !ruby/object:Gem::Requirement
71
+ version_requirements: *70733970
72
+ - !ruby/object:Gem::Dependency
73
+ name: rubyzip
74
+ requirement: &70733530 !ruby/object:Gem::Requirement
78
75
  none: false
79
- requirements:
76
+ requirements:
80
77
  - - ~>
81
- - !ruby/object:Gem::Version
78
+ - !ruby/object:Gem::Version
82
79
  version: 0.9.4
83
80
  type: :runtime
84
- version_requirements: *id006
85
- - !ruby/object:Gem::Dependency
86
- name: builder
87
81
  prerelease: false
88
- requirement: &id007 !ruby/object:Gem::Requirement
82
+ version_requirements: *70733530
83
+ - !ruby/object:Gem::Dependency
84
+ name: builder
85
+ requirement: &70733160 !ruby/object:Gem::Requirement
89
86
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: "0"
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
94
91
  type: :runtime
95
- version_requirements: *id007
96
- - !ruby/object:Gem::Dependency
97
- name: rgeo
98
92
  prerelease: false
99
- requirement: &id008 !ruby/object:Gem::Requirement
93
+ version_requirements: *70733160
94
+ - !ruby/object:Gem::Dependency
95
+ name: rgeo
96
+ requirement: &70732740 !ruby/object:Gem::Requirement
100
97
  none: false
101
- requirements:
98
+ requirements:
102
99
  - - ~>
103
- - !ruby/object:Gem::Version
100
+ - !ruby/object:Gem::Version
104
101
  version: 0.3.2
105
102
  type: :runtime
106
- version_requirements: *id008
107
- - !ruby/object:Gem::Dependency
108
- name: rgeo-geojson
109
103
  prerelease: false
110
- requirement: &id009 !ruby/object:Gem::Requirement
104
+ version_requirements: *70732740
105
+ - !ruby/object:Gem::Dependency
106
+ name: rgeo-geojson
107
+ requirement: &70732330 !ruby/object:Gem::Requirement
111
108
  none: false
112
- requirements:
109
+ requirements:
113
110
  - - ~>
114
- - !ruby/object:Gem::Version
111
+ - !ruby/object:Gem::Version
115
112
  version: 0.2.1
116
113
  type: :runtime
117
- version_requirements: *id009
118
- - !ruby/object:Gem::Dependency
119
- name: rspec
120
114
  prerelease: false
121
- requirement: &id010 !ruby/object:Gem::Requirement
115
+ version_requirements: *70732330
116
+ - !ruby/object:Gem::Dependency
117
+ name: rspec
118
+ requirement: &70732040 !ruby/object:Gem::Requirement
122
119
  none: false
123
- requirements:
120
+ requirements:
124
121
  - - ~>
125
- - !ruby/object:Gem::Version
122
+ - !ruby/object:Gem::Version
126
123
  version: 2.6.0
127
124
  type: :development
128
- version_requirements: *id010
129
- - !ruby/object:Gem::Dependency
130
- name: mocha
131
125
  prerelease: false
132
- requirement: &id011 !ruby/object:Gem::Requirement
126
+ version_requirements: *70732040
127
+ - !ruby/object:Gem::Dependency
128
+ name: mocha
129
+ requirement: &70731730 !ruby/object:Gem::Requirement
133
130
  none: false
134
- requirements:
131
+ requirements:
135
132
  - - ~>
136
- - !ruby/object:Gem::Version
133
+ - !ruby/object:Gem::Version
137
134
  version: 0.10.0
138
135
  type: :development
139
- version_requirements: *id011
140
- - !ruby/object:Gem::Dependency
141
- name: ruby-debug19
142
136
  prerelease: false
143
- requirement: &id012 !ruby/object:Gem::Requirement
137
+ version_requirements: *70731730
138
+ - !ruby/object:Gem::Dependency
139
+ name: ruby-debug19
140
+ requirement: &70731440 !ruby/object:Gem::Requirement
144
141
  none: false
145
- requirements:
142
+ requirements:
146
143
  - - ~>
147
- - !ruby/object:Gem::Version
144
+ - !ruby/object:Gem::Version
148
145
  version: 0.11.6
149
146
  type: :development
150
- version_requirements: *id012
147
+ prerelease: false
148
+ version_requirements: *70731440
151
149
  description: Import CSV, SHP, and other files with data into a PostgreSQL table
152
- email:
150
+ email:
153
151
  - andrew@vizzuality.com
154
152
  executables: []
155
-
156
153
  extensions: []
157
-
158
154
  extra_rdoc_files: []
159
-
160
- files:
155
+ files:
161
156
  - .gitignore
162
157
  - .rvmrc
163
158
  - Gemfile
@@ -169,6 +164,7 @@ files:
169
164
  - lib/cartodb-exporter/exporter.rb
170
165
  - lib/cartodb-exporter/version.rb
171
166
  - lib/cartodb-importer.rb
167
+ - lib/cartodb-importer/gpx.rb
172
168
  - lib/cartodb-importer/importer.rb
173
169
  - lib/cartodb-importer/version.rb
174
170
  - lib/core_ext/.DS_Store
@@ -180,37 +176,31 @@ files:
180
176
  - misc/shp_normalizer.py
181
177
  - misc/srid_from_gdal.py
182
178
  - spec/export_spec.rb
179
+ - spec/gpx_spec.rb
183
180
  - spec/import_spec.rb
184
181
  - spec/spec_helper.rb
185
- has_rdoc: true
186
- homepage: ""
182
+ homepage: ''
187
183
  licenses: []
188
-
189
184
  post_install_message:
190
185
  rdoc_options: []
191
-
192
- require_paths:
186
+ require_paths:
193
187
  - lib
194
- required_ruby_version: !ruby/object:Gem::Requirement
188
+ required_ruby_version: !ruby/object:Gem::Requirement
195
189
  none: false
196
- requirements:
197
- - - ">="
198
- - !ruby/object:Gem::Version
199
- version: "0"
200
- required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
195
  none: false
202
- requirements:
203
- - - ">="
204
- - !ruby/object:Gem::Version
205
- version: "0"
196
+ requirements:
197
+ - - ! '>='
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
206
200
  requirements: []
207
-
208
201
  rubyforge_project: cartodb-importer
209
- rubygems_version: 1.6.2
202
+ rubygems_version: 1.8.10
210
203
  signing_key:
211
204
  specification_version: 3
212
205
  summary: Import CSV, SHP, and other files with data into a PostgreSQL table
213
- test_files:
214
- - spec/export_spec.rb
215
- - spec/import_spec.rb
216
- - spec/spec_helper.rb
206
+ test_files: []