shp2geocouch 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.textile +3 -2
  2. data/VERSION +1 -1
  3. data/bin/shp2geocouch +27 -7
  4. metadata +4 -4
data/README.textile CHANGED
@@ -23,10 +23,10 @@ Install the @shp2geocouch@ gem:
23
23
 
24
24
  h2. Usage
25
25
 
26
- @shp2geocouch <path_to_shapefile> [your-geocouch-root-url (optional, default: http://localhost:5984)]@
26
+ @shp2geocouch <path_to_shapefile> [geocouch-url (optional, default: http://localhost:5984/zip_filename)]@
27
27
 
28
28
  example: @shp2geocouch /sweet_geo_data/Portland_Oregon_Public_Libraries.shp@
29
- another possible example: @shp2geocouch /zipped_shapfiles/US_Railroads.zip http://myusername.couchone.com@
29
+ another possible example: @shp2geocouch /zipped_shapfiles/US_Railroads.zip http://myusername.couchone.com/railroads@
30
30
 
31
31
  Once completed, you can run bounding box queries against your data! Visit the following link to receive a dump of your entire dataset as GeoJSON (a bounding box that covers the entire planet):
32
32
  @http://localhost:5984/your_db_name/_design/geojson/_spatial/points?bbox=-180,180,-90,90@
@@ -38,6 +38,7 @@ h3. Arguments:
38
38
  * You can feed in either a @.shp@ file or a @.zip@ that contains a @.shp@
39
39
  * @-v@ for verbose
40
40
  * @--no-cleanup@ if you want @shp2geocouch@ to leave you a copy of unzipped Shapefile and converted JSON.
41
+ * @--chunksize@ to customize the number of docs that it sends in each PUT to CouchDB's @_bulk_docs@ interface (default is 50)
41
42
 
42
43
  h2. What?
43
44
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/bin/shp2geocouch CHANGED
@@ -5,7 +5,7 @@ require 'optparse'
5
5
  require 'iconv'
6
6
 
7
7
  class ShapefileToGeoCouch
8
- attr_accessor :path, :extension, :name, :couch_url, :cleanup, :verbose
8
+ attr_accessor :path, :extension, :name, :couch_url, :cleanup, :verbose, :chunksize
9
9
 
10
10
  def initialize(options)
11
11
  set_accessors(options)
@@ -69,13 +69,29 @@ class ShapefileToGeoCouch
69
69
  %x!sed -e '/^\"type\": \"FeatureCollection\",$/d' -e '/^\"features\": \\[$/d' -e '/^{$/d' -e '/^,$/d' -e '/^}$/d' -e '/^]$/d' -e '/^$/d' -e 's/$/,/' #{json} > #{bulk}!
70
70
  end
71
71
 
72
- def upload
72
+ def post(string)
73
73
  ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') # disregard all UTF8 characters
74
+ valid_string = ic.iconv(string[0..-3] + ' ')[0..-3] # http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/
75
+ HTTParty.post(database_url + '/_bulk_docs', :body => '{"docs": [' + valid_string + "]}", :headers => {'content-type' => "application/json"})
76
+ end
77
+
78
+ def upload
74
79
  puts "Bulk loading data into GeoCouch... view progress at #{@couch_url}/_utils" if @verbose
75
- File.open(bulk).each_line do |line|
76
- valid_string = ic.iconv(line[0..-3] + ' ')[0..-3] # http://po-ru.com/diary/fixing-invalid-utf-8-in-ruby-revisited/
77
- HTTParty.post(database_url + '/_bulk_docs', :body => '{"docs": [' + valid_string + "]}", :headers => {'content-type' => "application/json"})
78
- end
80
+ group = []
81
+ length = File.open(bulk).lines.count - 1
82
+ File.open(bulk).each_with_index do |line, index|
83
+ if (index % @chunksize == 0)
84
+ post(group.join(''))
85
+ group = [line]
86
+ next
87
+ end
88
+ if (index == length)
89
+ group << line
90
+ post(group.join(''))
91
+ next
92
+ end
93
+ group << line
94
+ end
79
95
  end
80
96
 
81
97
  def add_ddoc
@@ -97,13 +113,17 @@ class ShapefileToGeoCouch
97
113
  end
98
114
  end
99
115
 
100
- defaults = {:cleanup => true, :verbose => false}
116
+ defaults = {:cleanup => true, :verbose => false, :chunksize => 50}
101
117
  OptionParser.new do |opts|
102
118
  opts.banner = "Usage: #{__FILE__} [path-to-shapefile] [your-geocouch-url (optional, default: http://localhost:5984/zip_filename)]"
103
119
  opts.on("--no-cleanup", "Don't remove converted files after upload") do |v|
104
120
  defaults[:cleanup] = false
105
121
  end
106
122
 
123
+ opts.on("--chunksize [SIZE]", "Couch bulk docs interface lines per chunk PUT (default 50)") do |size|
124
+ defaults[:chunksize] = size.to_i
125
+ end
126
+
107
127
  opts.on('-v') do |v|
108
128
  defaults[:verbose] = true
109
129
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shp2geocouch
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Max Ogden
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-23 00:00:00 -07:00
18
+ date: 2010-10-26 00:00:00 -07:00
19
19
  default_executable: shp2geocouch
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency