scensus-utils 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/lib/scensus-utils.rb +191 -0
- data/test/helper.rb +10 -0
- data/test/test_scensus-utils.rb +7 -0
- metadata +94 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Tony Wieczorek
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
= scensus-utils
|
2
|
+
|
3
|
+
Utility library to do some fancy geo transformations with Ruby. Provides glue between projects like GeoRuby and the Scensus project. Not required to run scensus, but merely provides and open sources the tools used to create Scensus.
|
4
|
+
|
5
|
+
== Copyright
|
6
|
+
|
7
|
+
Copyright (c) 2009 Tony Wieczorek. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "scensus-utils"
|
8
|
+
gem.summary = %Q{Utilities used to construct the Scensus project, using Ruby to visualize the US Census.}
|
9
|
+
gem.description = %Q{The US Census can be hard to digest for mere mortals. Geographic data is hidden away in shapefiles, a format unsupported by the freely available mapping sites like Google Maps and OpenStreetMap. Map servers, like GeoServer and MapServer have support for shapefiles, but those solutions are often too much for smaller organizations to set up and maintain. Scensus is a project to bring simple mapping of US Census data to the rest of us. Scensus-utils is a set of ruby scripts and files necessary to transform the census data in use for the Scensus project. You do not need to install Scensus-utils to run Scensus, but they are provided to foster further collaboration on the techniques and tools used to map.}
|
10
|
+
gem.email = "tonyjw@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/tonyjw/scensus-utils"
|
12
|
+
gem.authors = ["Tony Wieczorek"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
|
16
|
+
gem.add_dependency('GeoRuby', '>= 1.3.4')
|
17
|
+
gem.add_dependency('json', '>= 1.2.0')
|
18
|
+
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/test_*.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/test_*.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :test => :check_dependencies
|
46
|
+
|
47
|
+
task :default => :test
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "scensus-utils #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,191 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# == Synopsis
|
4
|
+
# Utilities to support Scensus. Converts shapefiles into encoded and
|
5
|
+
# simplified polylines useful for display on Google Maps.
|
6
|
+
#
|
7
|
+
# == Examples
|
8
|
+
# This command does blah blah blah.
|
9
|
+
# scensus-utils
|
10
|
+
#
|
11
|
+
# Other examples:
|
12
|
+
# scensus-utils -q bar.doc
|
13
|
+
# scensus-utils --verbose foo.html
|
14
|
+
#
|
15
|
+
# == Usage
|
16
|
+
# scensus-utils [options] shapefiles_to_convert.shp
|
17
|
+
#
|
18
|
+
# For help use: scensus-utils -h
|
19
|
+
#
|
20
|
+
# == Options
|
21
|
+
# -h, --help Displays help message
|
22
|
+
# -v, --version Display the version, then exit
|
23
|
+
# -q, --quiet Output as little as possible, overrides verbose
|
24
|
+
# -V, --verbose Verbose output
|
25
|
+
#
|
26
|
+
# -o, --output TODO: Output file
|
27
|
+
# -s, --[no-]simplify Whether to simplify the polygons before encoding them. Default: simplify
|
28
|
+
#
|
29
|
+
# == Author
|
30
|
+
# Tony Wieczorek (tonyjw@gmail.com)
|
31
|
+
#
|
32
|
+
# == Copyright
|
33
|
+
# Copyright (c) 2009 Tony Wieczorek. Licensed under the MIT License:
|
34
|
+
# http://www.opensource.org/licenses/mit-license.php
|
35
|
+
|
36
|
+
require 'optparse'
|
37
|
+
require 'rdoc/usage'
|
38
|
+
require 'ostruct'
|
39
|
+
require 'date'
|
40
|
+
|
41
|
+
require 'json'
|
42
|
+
require "geo_ruby"
|
43
|
+
include GeoRuby::Shp4r
|
44
|
+
|
45
|
+
class App
|
46
|
+
VERSION = '0.1.0'
|
47
|
+
|
48
|
+
attr_reader :options
|
49
|
+
|
50
|
+
def initialize(arguments, stdin)
|
51
|
+
@arguments = arguments
|
52
|
+
@stdin = stdin
|
53
|
+
|
54
|
+
# Set defaults
|
55
|
+
@options = OpenStruct.new
|
56
|
+
@options.verbose = false
|
57
|
+
@options.quiet = false
|
58
|
+
@options.output = 'scensus-utils-output.js'
|
59
|
+
@options.simplify_p = true
|
60
|
+
end
|
61
|
+
|
62
|
+
# Parse options, check arguments, then process the command
|
63
|
+
def run
|
64
|
+
|
65
|
+
if parsed_options? && arguments_valid?
|
66
|
+
|
67
|
+
puts "Start at #{DateTime.now}\n\n" if @options.verbose
|
68
|
+
|
69
|
+
output_options if @options.verbose # [Optional]
|
70
|
+
|
71
|
+
process_arguments
|
72
|
+
process_command
|
73
|
+
|
74
|
+
puts "\nFinished at #{DateTime.now}" if @options.verbose
|
75
|
+
|
76
|
+
else
|
77
|
+
output_usage
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
def parsed_options?
|
85
|
+
|
86
|
+
# Specify options
|
87
|
+
opts = OptionParser.new
|
88
|
+
opts.on('-v', '--version') { output_version ; exit 0 }
|
89
|
+
opts.on('-h', '--help') { output_help }
|
90
|
+
opts.on('-V', '--verbose') { @options.verbose = true }
|
91
|
+
opts.on('-q', '--quiet') { @options.quiet = true }
|
92
|
+
|
93
|
+
opts.on('-o', '--output FILE', "Output file") do |f|
|
94
|
+
@options.output = f
|
95
|
+
end
|
96
|
+
opts.on('-s', '--[no-]simplify') do |simplify|
|
97
|
+
@options.simplify_p = simplify
|
98
|
+
end
|
99
|
+
|
100
|
+
opts.parse!(@arguments) rescue return false
|
101
|
+
|
102
|
+
process_options
|
103
|
+
true
|
104
|
+
end
|
105
|
+
|
106
|
+
# Performs post-parse processing on options
|
107
|
+
def process_options
|
108
|
+
@options.verbose = false if @options.quiet
|
109
|
+
end
|
110
|
+
|
111
|
+
def output_options
|
112
|
+
puts "Options:\n"
|
113
|
+
|
114
|
+
@options.marshal_dump.each do |name, val|
|
115
|
+
puts " #{name} = #{val}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# True if required arguments were provided
|
120
|
+
def arguments_valid?
|
121
|
+
# TODO - implement your real logic here
|
122
|
+
true if @arguments.length >= 1
|
123
|
+
|
124
|
+
# TODO: Does the directory specified exist and have at least 1 shapefile?
|
125
|
+
end
|
126
|
+
|
127
|
+
# Setup the arguments
|
128
|
+
def process_arguments
|
129
|
+
# TO DO - place in local vars, etc
|
130
|
+
end
|
131
|
+
|
132
|
+
def output_help
|
133
|
+
output_version
|
134
|
+
RDoc::usage() #exits app
|
135
|
+
end
|
136
|
+
|
137
|
+
def output_usage
|
138
|
+
RDoc::usage('usage') # gets usage from comments above
|
139
|
+
end
|
140
|
+
|
141
|
+
def output_version
|
142
|
+
puts "#{File.basename(__FILE__)} version #{VERSION}"
|
143
|
+
end
|
144
|
+
|
145
|
+
def process_command
|
146
|
+
# Loop over each shapefile specified on the command line
|
147
|
+
# and process the shapes contained within
|
148
|
+
|
149
|
+
puts "Finding geo shapes in the following files:"
|
150
|
+
|
151
|
+
ARGV.each do |a|
|
152
|
+
Dir.glob(a) do |shp|
|
153
|
+
puts " #{a} ..."
|
154
|
+
shp_basename = File.basename(shp)
|
155
|
+
if shp_basename =~ /(.*)\.shp/
|
156
|
+
puts "\nImporting " + File.basename(shp)
|
157
|
+
ShpFile.open(shp) do |shp|
|
158
|
+
shp.each do |shape|
|
159
|
+
# add the statefp00 + countyfp00 + tractce00 (if they exist) and see if there
|
160
|
+
# is already a Place object representing this one.
|
161
|
+
|
162
|
+
shape.data["STATEFP00"] ||= ""
|
163
|
+
shape.data["COUNTYFP00"] ||= ""
|
164
|
+
shape.data["TRACTCE00"] ||= ""
|
165
|
+
|
166
|
+
fp_id = shape.data["STATEFP00"] + shape.data["COUNTYFP00"] + shape.data["TRACTCE00"]
|
167
|
+
|
168
|
+
print "."
|
169
|
+
|
170
|
+
# Loop over each field in this shapefile, and add
|
171
|
+
shp.fields.each do |field|
|
172
|
+
puts "#{field.name}"
|
173
|
+
#new_place[field.name.downcase] = shape.data[field.name]
|
174
|
+
end
|
175
|
+
|
176
|
+
#new_place.the_geom = shape.geometry
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
# TO DO - Add your Modules, Classes, etc
|
187
|
+
|
188
|
+
|
189
|
+
# Create and run the application
|
190
|
+
app = App.new(ARGV, STDIN)
|
191
|
+
app.run
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: scensus-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tony Wieczorek
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-25 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: thoughtbot-shoulda
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: GeoRuby
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.4
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: json
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.2.0
|
44
|
+
version:
|
45
|
+
description: The US Census can be hard to digest for mere mortals. Geographic data is hidden away in shapefiles, a format unsupported by the freely available mapping sites like Google Maps and OpenStreetMap. Map servers, like GeoServer and MapServer have support for shapefiles, but those solutions are often too much for smaller organizations to set up and maintain. Scensus is a project to bring simple mapping of US Census data to the rest of us. Scensus-utils is a set of ruby scripts and files necessary to transform the census data in use for the Scensus project. You do not need to install Scensus-utils to run Scensus, but they are provided to foster further collaboration on the techniques and tools used to map.
|
46
|
+
email: tonyjw@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- lib/scensus-utils.rb
|
62
|
+
- test/helper.rb
|
63
|
+
- test/test_scensus-utils.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/tonyjw/scensus-utils
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Utilities used to construct the Scensus project, using Ruby to visualize the US Census.
|
92
|
+
test_files:
|
93
|
+
- test/test_scensus-utils.rb
|
94
|
+
- test/helper.rb
|