cartodb-importer 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/cartodb-importer.gemspec +1 -1
- data/lib/cartodb-importer/importer.rb +13 -6
- data/lib/cartodb-importer/version.rb +1 -1
- data/misc/shp_normalizer.py +3 -2
- metadata +23 -23
data/cartodb-importer.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_runtime_dependency "pg",
|
22
|
+
s.add_runtime_dependency "pg", "0.11"
|
23
23
|
s.add_runtime_dependency "sequel"
|
24
24
|
s.add_runtime_dependency "roo"
|
25
25
|
s.add_runtime_dependency "spreadsheet"
|
@@ -148,18 +148,25 @@ module CartoDB
|
|
148
148
|
port = @db_configuration[:port] ? "-p #{@db_configuration[:port]}" : ""
|
149
149
|
@suggested_name = get_valid_name(File.basename(path).tr('.','_').downcase.sanitize) unless @force_name
|
150
150
|
random_table_name = "importing_#{Time.now.to_i}_#{@suggested_name}"
|
151
|
-
|
151
|
+
|
152
152
|
normalizer_command = "#{python_bin_path} -Wignore #{File.expand_path("../../../misc/shp_normalizer.py", __FILE__)} #{path} #{random_table_name}"
|
153
|
-
shp_args_command = `#{normalizer_command}
|
154
|
-
|
153
|
+
shp_args_command = `#{normalizer_command}`.split( /, */, 4 )
|
154
|
+
|
155
|
+
#print "-e -i -I -g the_geom -W %s %s %s %s" %(srid,encoding,shp_file,name,flag)
|
156
|
+
|
157
|
+
if shp_args_command.length != 4
|
155
158
|
raise "Error running python shp_normalizer script: #{normalizer_command}"
|
156
159
|
end
|
157
|
-
full_shp_command = "#{shp2pgsql_bin_path} #{shp_args_command.strip} | #{psql_bin_path} #{host} #{port} -U #{@db_configuration[:username]} -w -d #{@db_configuration[:database]}"
|
160
|
+
full_shp_command = "#{shp2pgsql_bin_path} -s #{shp_args_command[0]} -e -i -I -g the_geom -W #{shp_args_command[1]} #{shp_args_command[2]} #{shp_args_command[3].strip} | #{psql_bin_path} #{host} #{port} -U #{@db_configuration[:username]} -w -d #{@db_configuration[:database]}"
|
158
161
|
log "Running shp2pgsql: #{full_shp_command}"
|
159
162
|
%x[#{full_shp_command}]
|
160
|
-
|
163
|
+
if shp_args_command[1] != '4326'
|
164
|
+
|
165
|
+
@db_connection.run("SELECT UpdateGeometrySRID('#{random_table_name}', 'the_geom', 4326)")
|
166
|
+
@db_connection.run("UPDATE #{random_table_name} SET the_geom = ST_Transform(the_geom, 4326)")
|
167
|
+
end
|
161
168
|
@db_connection.run("CREATE TABLE #{@suggested_name} AS SELECT * FROM #{random_table_name}")
|
162
|
-
|
169
|
+
@db_connection.run("DROP TABLE #{random_table_name}")
|
163
170
|
@table_created = true
|
164
171
|
|
165
172
|
entries.each{ |e| FileUtils.rm_rf(e) } if entries.any?
|
data/misc/shp_normalizer.py
CHANGED
@@ -15,6 +15,7 @@ name = sys.argv[2]
|
|
15
15
|
dbf_file = shp_file[0:-4] + '.dbf'
|
16
16
|
prj_file = shp_file[0:-4] + '.prj'
|
17
17
|
|
18
|
+
srid = 4326
|
18
19
|
#Try detecting the SRID
|
19
20
|
if os.path.isfile(prj_file):
|
20
21
|
prj_filef = open(prj_file, 'r')
|
@@ -37,7 +38,7 @@ if os.path.isfile(prj_file):
|
|
37
38
|
jres = json.loads(webres.read())
|
38
39
|
if jres['codes']:
|
39
40
|
srid = int(jres['codes'][0]['code'])
|
40
|
-
|
41
|
+
|
41
42
|
#Try to detect the encoding
|
42
43
|
dbf = open(dbf_file, 'rb')
|
43
44
|
db = dbfUtils.dbfreader(dbf)
|
@@ -53,4 +54,4 @@ encoding = detector.result["encoding"]
|
|
53
54
|
if encoding=="ascii":
|
54
55
|
encoding="LATIN1"
|
55
56
|
|
56
|
-
print "
|
57
|
+
print "%s,%s,%s,%s" % (srid,encoding,shp_file,name)
|
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.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,22 +11,22 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2011-09-
|
14
|
+
date: 2011-09-13 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: pg
|
18
|
-
requirement: &
|
18
|
+
requirement: &70174363629800 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - =
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: '0.11'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70174363629800
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sequel
|
29
|
-
requirement: &
|
29
|
+
requirement: &70174363629380 !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: *
|
37
|
+
version_requirements: *70174363629380
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: roo
|
40
|
-
requirement: &
|
40
|
+
requirement: &70174363628920 !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: *
|
48
|
+
version_requirements: *70174363628920
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
50
|
name: spreadsheet
|
51
|
-
requirement: &
|
51
|
+
requirement: &70174363628500 !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: *
|
59
|
+
version_requirements: *70174363628500
|
60
60
|
- !ruby/object:Gem::Dependency
|
61
61
|
name: google-spreadsheet-ruby
|
62
|
-
requirement: &
|
62
|
+
requirement: &70174363628080 !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: *
|
70
|
+
version_requirements: *70174363628080
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rubyzip
|
73
|
-
requirement: &
|
73
|
+
requirement: &70174363627660 !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: *
|
81
|
+
version_requirements: *70174363627660
|
82
82
|
- !ruby/object:Gem::Dependency
|
83
83
|
name: builder
|
84
|
-
requirement: &
|
84
|
+
requirement: &70174363627240 !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: *
|
92
|
+
version_requirements: *70174363627240
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
94
|
name: rspec
|
95
|
-
requirement: &
|
95
|
+
requirement: &70174363626820 !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: *
|
103
|
+
version_requirements: *70174363626820
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: mocha
|
106
|
-
requirement: &
|
106
|
+
requirement: &70174363626400 !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: *
|
114
|
+
version_requirements: *70174363626400
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: ruby-debug19
|
117
|
-
requirement: &
|
117
|
+
requirement: &70174363625980 !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: *
|
125
|
+
version_requirements: *70174363625980
|
126
126
|
description: Import CSV, SHP, and other files with data into a PostgreSQL table
|
127
127
|
email:
|
128
128
|
- andrew@vizzuality.com
|