shp2geocouch 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +0 -0
- data/README.textile +1 -1
- data/Rakefile +0 -0
- data/VERSION +1 -1
- data/bin/shp2geocouch +35 -18
- data/pkg/shp2geocouch-0.0.5.gem +0 -0
- data/shp2geocouch.gemspec +50 -0
- metadata +10 -9
- data/.gitignore +0 -1
data/LICENSE
CHANGED
File without changes
|
data/README.textile
CHANGED
@@ -29,7 +29,7 @@ example: @shp2geocouch /sweet_geo_data/Portland_Oregon_Public_Libraries.shp@
|
|
29
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
|
-
@http://localhost:5984/your_db_name/_design/geojson/_spatial/points?bbox=-180
|
32
|
+
@http://localhost:5984/your_db_name/_design/geojson/_spatial/points?bbox=-180,-90,180,90@
|
33
33
|
|
34
34
|
If you uploaded a large dataset, you may experience a delay on the first ever spatial query as GeoCouch builds it's spatial index. You can check the status of the indexer by visiting @http://localhost:5984/_utils/status.html@
|
35
35
|
|
data/Rakefile
CHANGED
File without changes
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/bin/shp2geocouch
CHANGED
@@ -3,19 +3,22 @@ require 'httparty'
|
|
3
3
|
require 'couchrest'
|
4
4
|
require 'optparse'
|
5
5
|
require 'iconv'
|
6
|
+
require 'net/http'
|
7
|
+
require 'uri'
|
6
8
|
|
7
9
|
class ShapefileToGeoCouch
|
8
|
-
attr_accessor :path, :extension, :name, :
|
10
|
+
attr_accessor :path, :extension, :name, :database_url, :cleanup, :verbose, :chunksize, :uri
|
9
11
|
|
10
12
|
def initialize(options)
|
11
13
|
set_accessors(options)
|
12
|
-
@
|
14
|
+
@uri = parse_database_url
|
15
|
+
@db = CouchRest.database! @database_url
|
13
16
|
verify_dependencies
|
14
17
|
convert
|
15
18
|
upload
|
16
19
|
add_ddoc
|
17
20
|
cleanup if @cleanup
|
18
|
-
puts "Upload complete. Test your data at #{database_url}/_design/
|
21
|
+
puts "Upload complete. Test your data at #{@database_url}/_design/geo/_spatial/full?bbox=-180,180,-90,90" if @verbose
|
19
22
|
end
|
20
23
|
|
21
24
|
def set_accessors(options)
|
@@ -30,8 +33,13 @@ class ShapefileToGeoCouch
|
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
33
|
-
def
|
34
|
-
@
|
36
|
+
def parse_database_url
|
37
|
+
URI.parse(@database_url)
|
38
|
+
end
|
39
|
+
|
40
|
+
def couch_url
|
41
|
+
port = @uri.port && @uri.port != 80 ? ":#{@uri.port}" : ""
|
42
|
+
"#{@uri.scheme}://#{@uri.host}#{port}"
|
35
43
|
end
|
36
44
|
|
37
45
|
def output_folder
|
@@ -72,11 +80,11 @@ class ShapefileToGeoCouch
|
|
72
80
|
def post(string)
|
73
81
|
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') # disregard all UTF8 characters
|
74
82
|
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"})
|
83
|
+
HTTParty.post(@database_url + '/_bulk_docs', :body => '{"docs": [' + valid_string + "]}", :headers => {'content-type' => "application/json"})
|
76
84
|
end
|
77
85
|
|
78
86
|
def upload
|
79
|
-
puts "Bulk loading data into GeoCouch... view progress at #{@
|
87
|
+
puts "Bulk loading data into GeoCouch... view progress at #{@database_url}/_utils" if @verbose
|
80
88
|
group = []
|
81
89
|
length = File.open(bulk).lines.count - 1
|
82
90
|
File.open(bulk).each_with_index do |line, index|
|
@@ -94,17 +102,26 @@ class ShapefileToGeoCouch
|
|
94
102
|
end
|
95
103
|
end
|
96
104
|
|
105
|
+
# replicates geocouch-utils into the db via http://max.iriscouch.com/apps/_design/geo
|
97
106
|
def add_ddoc
|
98
|
-
puts "
|
99
|
-
view_exists = @db.get('_design/
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
"
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
107
|
+
puts "Replicating http://github.com/maxogden/geocouch-utils..." if @verbose
|
108
|
+
view_exists = @db.get('_design/geo') rescue false
|
109
|
+
internet_connection = HTTParty.get('http://localhost:5984') rescue false
|
110
|
+
if !view_exists && internet_connection
|
111
|
+
resp = HTTParty.post(couch_url + '/_replicate',
|
112
|
+
:body => '{"source":"http://localhost:5984/catmapper","target":"' + @name + '", "doc_ids":["_design/geo"]}',
|
113
|
+
:headers => {'content-type' => "application/json"}
|
114
|
+
)
|
115
|
+
resp = JSON.parse(resp)
|
116
|
+
if ((resp.keys.include? 'ok') && (resp['ok'] == true))
|
117
|
+
puts "View your data at #{@database_url}/_design/geo/_rewrite"
|
118
|
+
else
|
119
|
+
puts "View your data at http://#{couch_url}/_utils"
|
120
|
+
end
|
121
|
+
elsif @verbose
|
122
|
+
puts "Did not push geocouch-utils -- either it already exists or internet is off"
|
123
|
+
puts "You can get geocouch-utils from http://github.com/maxogden/geocouch-utils"
|
124
|
+
end
|
108
125
|
end
|
109
126
|
|
110
127
|
def cleanup
|
@@ -137,6 +154,6 @@ raise "You must specify a .shp or a .zip" unless extension =~ /zip|shp/i
|
|
137
154
|
name = ARGV[0].split('/')[-1].split('.')[0]
|
138
155
|
|
139
156
|
options = {:path => ARGV[0], :name => name.downcase, :extension => extension}.merge(defaults)
|
140
|
-
options[:
|
157
|
+
options[:database_url] = ARGV[1] || "http://localhost:5984/#{name.downcase}"
|
141
158
|
|
142
159
|
ShapefileToGeoCouch.new(options)
|
Binary file
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{shp2geocouch}
|
8
|
+
s.version = "0.0.5"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Max Ogden"]
|
12
|
+
s.date = %q{2011-04-21}
|
13
|
+
s.default_executable = %q{shp2geocouch}
|
14
|
+
s.description = %q{rubygem that converts Shapefiles into GeoCouch databases}
|
15
|
+
s.email = %q{max@maxogden.com}
|
16
|
+
s.executables = ["shp2geocouch"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.textile"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
"LICENSE",
|
23
|
+
"README.textile",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"bin/shp2geocouch",
|
27
|
+
"pkg/shp2geocouch-0.0.5.gem",
|
28
|
+
"shp2geocouch.gemspec"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/maxogden/shp2geocouch}
|
31
|
+
s.require_paths = ["lib"]
|
32
|
+
s.rubygems_version = %q{1.4.2}
|
33
|
+
s.summary = %q{rubygem that converts Shapefiles into GeoCouch databases}
|
34
|
+
|
35
|
+
if s.respond_to? :specification_version then
|
36
|
+
s.specification_version = 3
|
37
|
+
|
38
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
39
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
40
|
+
s.add_runtime_dependency(%q<couchrest>, [">= 0"])
|
41
|
+
else
|
42
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
43
|
+
s.add_dependency(%q<couchrest>, [">= 0"])
|
44
|
+
end
|
45
|
+
else
|
46
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
47
|
+
s.add_dependency(%q<couchrest>, [">= 0"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
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:
|
18
|
+
date: 2011-04-21 00:00:00 -07:00
|
19
19
|
default_executable: shp2geocouch
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -56,19 +56,20 @@ extra_rdoc_files:
|
|
56
56
|
- LICENSE
|
57
57
|
- README.textile
|
58
58
|
files:
|
59
|
-
- .gitignore
|
60
59
|
- LICENSE
|
61
60
|
- README.textile
|
62
61
|
- Rakefile
|
63
62
|
- VERSION
|
64
63
|
- bin/shp2geocouch
|
64
|
+
- pkg/shp2geocouch-0.0.5.gem
|
65
|
+
- shp2geocouch.gemspec
|
65
66
|
has_rdoc: true
|
66
67
|
homepage: http://github.com/maxogden/shp2geocouch
|
67
68
|
licenses: []
|
68
69
|
|
69
70
|
post_install_message:
|
70
|
-
rdoc_options:
|
71
|
-
|
71
|
+
rdoc_options: []
|
72
|
+
|
72
73
|
require_paths:
|
73
74
|
- lib
|
74
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
93
|
requirements: []
|
93
94
|
|
94
95
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.
|
96
|
+
rubygems_version: 1.4.2
|
96
97
|
signing_key:
|
97
98
|
specification_version: 3
|
98
99
|
summary: rubygem that converts Shapefiles into GeoCouch databases
|
data/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
.DS_Store
|