cartodb-importer 0.2.13 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -209,6 +209,36 @@ module CartoDB
209
209
  end
210
210
  end
211
211
 
212
+ #Now, if there is a ltitude and longitude column, lets create a the_geom for it
213
+ latitude_possible_names = "'latitude','lat','latitudedecimal','latitud','lati'"
214
+ longitude_possible_names = "'longitude','lon','lng','longitudedecimal','longitud','long'"
215
+
216
+ matching_latitude = nil
217
+ res = @db_connection["select column_name from information_schema.columns where table_name ='#{@suggested_name}'
218
+ and lower(column_name) in (#{latitude_possible_names}) LIMIT 1"]
219
+ if !res.first.nil?
220
+ matching_latitude= res.first[:column_name]
221
+ end
222
+ matching_longitude = nil
223
+ res = @db_connection["select column_name from information_schema.columns where table_name ='#{@suggested_name}'
224
+ and lower(column_name) in (#{longitude_possible_names}) LIMIT 1"]
225
+ if !res.first.nil?
226
+ matching_longitude= res.first[:column_name]
227
+ end
228
+
229
+
230
+ if matching_latitude and matching_longitude
231
+ #we know there is a latitude/longitude columns
232
+ @db_connection.run("SELECT AddGeometryColumn('#{@suggested_name}','the_geom',4326, 'POINT', 2);")
233
+ @db_connection.run("UPDATE \"#{@suggested_name}\" SET the_geom = ST_GeomFromText('POINT('|| \"#{matching_longitude}\" ||' '|| \"#{matching_latitude}\" ||')',4326)
234
+ WHERE \"#{matching_longitude}\" IS NOT NULL AND \"#{matching_latitude}\" IS NOT NULL AND \"#{matching_longitude}\"<>'' AND \"#{matching_latitude}\"<>''")
235
+ @db_connection.run("CREATE INDEX \"#{@suggested_name}_the_geom_gist\" ON \"#{@suggested_name}\" USING GIST (the_geom)")
236
+ end
237
+
238
+
239
+
240
+
241
+
212
242
  @table_created = true
213
243
 
214
244
  FileUtils.rm_rf(path)
@@ -253,7 +283,7 @@ module CartoDB
253
283
  @db_connection.run("ALTER TABLE #{random_table_name} RENAME COLUMN the_geom TO the_geom_orig;")
254
284
  geom_type = @db_connection["SELECT GeometryType(the_geom_orig) as type from #{random_table_name} LIMIT 1"].first[:type]
255
285
  @db_connection.run("SELECT AddGeometryColumn('#{random_table_name}','the_geom',4326, '#{geom_type}', 2);")
256
- @db_connection.run("UPDATE \"#{random_table_name}\" SET the_geom = ST_Transform(the_geom_orig, 4326)")
286
+ @db_connection.run("UPDATE \"#{random_table_name}\" SET the_geom = ST_Force_2D(ST_Transform(the_geom_orig, 4326))")
257
287
  @db_connection.run("ALTER TABLE #{random_table_name} DROP COLUMN the_geom_orig")
258
288
  @db_connection.run("CREATE INDEX \"#{random_table_name}_the_geom_gist\" ON \"#{random_table_name}\" USING GIST (the_geom)")
259
289
  rescue Exception => msg
@@ -1,6 +1,6 @@
1
1
  module CartoDB
2
2
  class Importer
3
- VERSION = "0.2.13"
3
+ VERSION = "0.2.14"
4
4
  end
5
5
  end
6
6
 
data/spec/import_spec.rb CHANGED
@@ -333,4 +333,41 @@ describe CartoDB::Importer do
333
333
  result.import_type.should == '.shp'
334
334
  end
335
335
  end
336
+
337
+ describe "Import KML" do
338
+ it "should import a KML ZIP file" do
339
+ importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/states.kml.zip", __FILE__),
340
+ :database => "cartodb_importer_test", :username => 'postgres', :password => '',
341
+ :host => 'localhost', :port => 5432
342
+ result = importer.import!
343
+ #result.rows_imported.should == 312
344
+ #result.import_type.should == '.shp'
345
+ end
346
+ end
347
+
348
+ describe "Import CSV with latidude/logitude" do
349
+ it "should import estaciones2.csv" do
350
+ importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/walmart.csv", __FILE__),
351
+ :database => "cartodb_importer_test", :username => 'postgres', :password => '',
352
+ :host => 'localhost', :port => 5432, :suggested_name => 'walmart'
353
+ result = importer.import!
354
+ result.name.should == 'walmart'
355
+ #result.rows_imported.should == 30
356
+ result.import_type.should == '.csv'
357
+ end
358
+ end
359
+
360
+ describe "Import CSV with lat/lon" do
361
+ it "should import estaciones2.csv" do
362
+ importer = CartoDB::Importer.new :import_from_file => File.expand_path("../support/data/walmart_latlon.csv", __FILE__),
363
+ :database => "cartodb_importer_test", :username => 'postgres', :password => '',
364
+ :host => 'localhost', :port => 5432, :suggested_name => 'walmart_latlon'
365
+ result = importer.import!
366
+ result.name.should == 'walmart_latlon'
367
+ #result.rows_imported.should == 30
368
+ result.import_type.should == '.csv'
369
+ end
370
+ end
371
+
372
+
336
373
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartodb-importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-09-27 00:00:00.000000000Z
14
+ date: 2011-10-03 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: pg
18
- requirement: &70158459012880 !ruby/object:Gem::Requirement
18
+ requirement: &70348306305600 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0.11'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70158459012880
26
+ version_requirements: *70348306305600
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sequel
29
- requirement: &70158459012340 !ruby/object:Gem::Requirement
29
+ requirement: &70348306288700 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70158459012340
37
+ version_requirements: *70348306288700
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: roo
40
- requirement: &70158459011620 !ruby/object:Gem::Requirement
40
+ requirement: &70348306287760 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *70158459011620
48
+ version_requirements: *70348306287760
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: spreadsheet
51
- requirement: &70158459010380 !ruby/object:Gem::Requirement
51
+ requirement: &70348306287120 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *70158459010380
59
+ version_requirements: *70348306287120
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: google-spreadsheet-ruby
62
- requirement: &70158459009780 !ruby/object:Gem::Requirement
62
+ requirement: &70348306286400 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: '0'
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *70158459009780
70
+ version_requirements: *70348306286400
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rubyzip
73
- requirement: &70158459009140 !ruby/object:Gem::Requirement
73
+ requirement: &70348306285500 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :runtime
80
80
  prerelease: false
81
- version_requirements: *70158459009140
81
+ version_requirements: *70348306285500
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: builder
84
- requirement: &70158459008540 !ruby/object:Gem::Requirement
84
+ requirement: &70348306284860 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ! '>='
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
- version_requirements: *70158459008540
92
+ version_requirements: *70348306284860
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: rspec
95
- requirement: &70158459007920 !ruby/object:Gem::Requirement
95
+ requirement: &70348306284240 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ! '>='
@@ -100,10 +100,10 @@ dependencies:
100
100
  version: '0'
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *70158459007920
103
+ version_requirements: *70348306284240
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: mocha
106
- requirement: &70158459007480 !ruby/object:Gem::Requirement
106
+ requirement: &70348306283580 !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
109
109
  - - ! '>='
@@ -111,10 +111,10 @@ dependencies:
111
111
  version: '0'
112
112
  type: :development
113
113
  prerelease: false
114
- version_requirements: *70158459007480
114
+ version_requirements: *70348306283580
115
115
  - !ruby/object:Gem::Dependency
116
116
  name: ruby-debug19
117
- requirement: &70158459007000 !ruby/object:Gem::Requirement
117
+ requirement: &70348306282880 !ruby/object:Gem::Requirement
118
118
  none: false
119
119
  requirements:
120
120
  - - ! '>='
@@ -122,7 +122,7 @@ dependencies:
122
122
  version: '0'
123
123
  type: :development
124
124
  prerelease: false
125
- version_requirements: *70158459007000
125
+ version_requirements: *70348306282880
126
126
  description: Import CSV, SHP, and other files with data into a PostgreSQL table
127
127
  email:
128
128
  - andrew@vizzuality.com