koeppen_geiger 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +0 -0
- data/LICENSE +18 -0
- data/Manifest +21 -0
- data/README.rdoc +52 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/data/koeppen-geiger.zip +0 -0
- data/generators/koeppen_geiger_generator.rb +16 -0
- data/generators/templates/migration.rb +34 -0
- data/koeppen_geiger.gemspec +32 -0
- data/lib/koeppen_geiger/climate_classification.rb +30 -0
- data/lib/koeppen_geiger/has_climate_classification.rb +67 -0
- data/lib/koeppen_geiger/pg_climate_classification.rb +61 -0
- data/lib/koeppen_geiger/utils.rb +125 -0
- data/lib/koeppen_geiger.rb +17 -0
- data/lib/locales/de.yml +33 -0
- data/lib/locales/en.yml +33 -0
- data/lib/tasks/koeppen_geiger.rake +16 -0
- data/test/test_helper.rb +5 -0
- data/test/unit/climate_classification_test.rb +5 -0
- data/test/unit/pg_climate_classification_test.rb +5 -0
- data/test/unit/utils_test.rb +5 -0
- data.tar.gz.sig +2 -0
- metadata +128 -0
- metadata.gz.sig +1 -0
data/CHANGELOG
ADDED
File without changes
|
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2011 Tobias Weiß
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
data/Manifest
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
LICENSE
|
3
|
+
Manifest
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
VERSION
|
7
|
+
data/koeppen-geiger.zip
|
8
|
+
generators/koeppen_geiger_generator.rb
|
9
|
+
generators/templates/migration.rb
|
10
|
+
lib/koeppen_geiger.rb
|
11
|
+
lib/koeppen_geiger/climate_classification.rb
|
12
|
+
lib/koeppen_geiger/has_climate_classification.rb
|
13
|
+
lib/koeppen_geiger/pg_climate_classification.rb
|
14
|
+
lib/koeppen_geiger/utils.rb
|
15
|
+
lib/locales/de.yml
|
16
|
+
lib/locales/en.yml
|
17
|
+
lib/tasks/koeppen_geiger.rake
|
18
|
+
test/test_helper.rb
|
19
|
+
test/unit/climate_classification_test.rb
|
20
|
+
test/unit/pg_climate_classification_test.rb
|
21
|
+
test/unit/utils_test.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
= KoeppenGeiger
|
2
|
+
|
3
|
+
This gem adds a climate classification parameter to a location object based upon observed or predicted climate data
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install koeppen_geiger
|
8
|
+
|
9
|
+
To install the gem, add this to your config/environment.rb:
|
10
|
+
config.gem 'koeppen_geiger'
|
11
|
+
|
12
|
+
== Post Installation
|
13
|
+
|
14
|
+
script/generate koeppen_geiger
|
15
|
+
rake koeppen_geiger:configure
|
16
|
+
sudo rake koeppen_geiger:extract_gis_data
|
17
|
+
rake koeppen_geiger:import_gis_data
|
18
|
+
rake db:migrate
|
19
|
+
|
20
|
+
== Requirements
|
21
|
+
|
22
|
+
Rails 2.3.x
|
23
|
+
|
24
|
+
Install PostgreSQL
|
25
|
+
http://www.postgresql.org
|
26
|
+
|
27
|
+
Install Postgis
|
28
|
+
http://www.postgis.org
|
29
|
+
|
30
|
+
Create a spatially-enabled database
|
31
|
+
http://www.postgis.org/documentation/manual-1.5/ch02.html#id2630392
|
32
|
+
|
33
|
+
== Usage
|
34
|
+
|
35
|
+
class Location < ActiveRecord::Base
|
36
|
+
has_climate_classification
|
37
|
+
has_climate_classification :lat_column_name => "latitude", :lng_column_name => "longitude"
|
38
|
+
end
|
39
|
+
|
40
|
+
location = Location.find(1)
|
41
|
+
location.classify
|
42
|
+
|
43
|
+
location.classified(:observed,1901,1925)
|
44
|
+
=> "Am"
|
45
|
+
|
46
|
+
location.classified(:observed,1901,1925).to_words
|
47
|
+
=> "Equatorial monsoon"
|
48
|
+
|
49
|
+
== Data
|
50
|
+
|
51
|
+
The underlying data has been taken from:
|
52
|
+
http://koeppen-geiger.vu-wien.ac.at/shifts.htm
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('koeppen_geiger', '0.0.1') do |p|
|
6
|
+
p.summary = "A Climate Classification Gem for ActiveRecord"
|
7
|
+
p.description = "A gem that adds a climate classification parameter based upon the Koeppen-Geiger climate classification system to a point location"
|
8
|
+
p.url = "http://github.com/tpunkt/koeppen_geiger"
|
9
|
+
p.author = "Tobias Weiss"
|
10
|
+
p.email = "tobias.weiss@gmail.com"
|
11
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
12
|
+
p.development_dependencies = []
|
13
|
+
end
|
14
|
+
|
15
|
+
# Load rake files used with this gem
|
16
|
+
# Dir["#{File.dirname(__FILE__)}/lib/tasks/*.rake"].sort.each { |ext| load ext }
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
Binary file
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class KoeppenGeigerGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
def manifest
|
4
|
+
record do |m|
|
5
|
+
# Create a directory if missing
|
6
|
+
m.directory 'lib/tasks'
|
7
|
+
|
8
|
+
# Copy rake files to Rails application
|
9
|
+
m.file('../../lib/tasks/koeppen_geiger.rake', 'lib/tasks/koeppen_geiger.rake')
|
10
|
+
|
11
|
+
# Copy migration file to Rails application
|
12
|
+
m.migration_template('migration.rb', 'db/migrate', :migration_file_name => "create_climate_classifications.rb")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class CreateClimateClassifications < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :climate_classifications, :force => true do |t|
|
5
|
+
t.integer :classified_id
|
6
|
+
t.string :observed_1901_1925
|
7
|
+
t.string :observed_1926_1950
|
8
|
+
t.string :observed_1951_1975
|
9
|
+
t.string :observed_1976_2000
|
10
|
+
t.string :a1f1_2001_2025
|
11
|
+
t.string :a1f1_2026_2050
|
12
|
+
t.string :a1f1_2051_2075
|
13
|
+
t.string :a1f1_2076_2100
|
14
|
+
t.string :a2_2001_2025
|
15
|
+
t.string :a2_2026_2050
|
16
|
+
t.string :a2_2051_2075
|
17
|
+
t.string :a2_2076_2100
|
18
|
+
t.string :b1_2001_2025
|
19
|
+
t.string :b1_2026_2050
|
20
|
+
t.string :b1_2051_2075
|
21
|
+
t.string :b1_2076_2100
|
22
|
+
t.string :b2_2001_2025
|
23
|
+
t.string :b2_2026_2050
|
24
|
+
t.string :b2_2051_2075
|
25
|
+
t.string :b2_2076_2100
|
26
|
+
t.timestamps
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.down
|
31
|
+
drop_table :climate_classifications
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{koeppen_geiger}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Tobias Weiss"]
|
9
|
+
s.date = %q{2011-03-23}
|
10
|
+
s.description = %q{A gem that adds a climate classification parameter based upon the Koeppen-Geiger climate classification system to a point location}
|
11
|
+
s.email = %q{tobias.weiss@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.rdoc", "lib/koeppen_geiger.rb", "lib/koeppen_geiger/climate_classification.rb", "lib/koeppen_geiger/has_climate_classification.rb", "lib/koeppen_geiger/pg_climate_classification.rb", "lib/koeppen_geiger/utils.rb", "lib/locales/de.yml", "lib/locales/en.yml", "lib/tasks/koeppen_geiger.rake"]
|
13
|
+
s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.rdoc", "Rakefile", "VERSION", "data/koeppen-geiger.zip", "generators/koeppen_geiger_generator.rb", "generators/templates/migration.rb", "lib/koeppen_geiger.rb", "lib/koeppen_geiger/climate_classification.rb", "lib/koeppen_geiger/has_climate_classification.rb", "lib/koeppen_geiger/pg_climate_classification.rb", "lib/koeppen_geiger/utils.rb", "lib/locales/de.yml", "lib/locales/en.yml", "lib/tasks/koeppen_geiger.rake", "test/test_helper.rb", "test/unit/climate_classification_test.rb", "test/unit/pg_climate_classification_test.rb", "test/unit/utils_test.rb", "koeppen_geiger.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/tpunkt/koeppen_geiger}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Koeppen_geiger", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{koeppen_geiger}
|
18
|
+
s.rubygems_version = %q{1.6.2}
|
19
|
+
s.summary = %q{A Climate Classification Gem for ActiveRecord}
|
20
|
+
s.test_files = ["test/test_helper.rb", "test/unit/climate_classification_test.rb", "test/unit/pg_climate_classification_test.rb", "test/unit/utils_test.rb"]
|
21
|
+
s.signing_key = '/Users/tweiss/Documents/#private_keys/gem-private_key.pem'
|
22
|
+
s.cert_chain = ['gem-public_cert.pem']
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
s.specification_version = 3
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
28
|
+
else
|
29
|
+
end
|
30
|
+
else
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module KoeppenGeiger
|
2
|
+
|
3
|
+
# 1. Has a table in the RDBMS of the Rails App
|
4
|
+
# 2. Copy migration from lib/migrate/template.rb to RAILS_ROOT/db/migrate
|
5
|
+
# 3. Create table via rake db:migrate
|
6
|
+
# 5. Defines a method thats grabs climate classifications from PostgreSQL and store it in RDBMS after creation
|
7
|
+
# 6. Defines methods to get climate classification for a "scenario" and "time period"
|
8
|
+
|
9
|
+
class ClimateClassification < ActiveRecord::Base
|
10
|
+
|
11
|
+
CLIMATE_ZONES = {"11" => "Af","12" => "Am","13" => "As","14" => "Aw",
|
12
|
+
"21" => "BWk","22" => "BWh","26" => "BSk","27" => "BSh",
|
13
|
+
"31" => "Cfa","32" => "Cfb","33" => "Cfc","34" => "Csa",
|
14
|
+
"35" => "Csb","36" => "Csc","37" => "Cwa","38" => "Cwb",
|
15
|
+
"39" => "Cwc","41" => "Dfa","42" => "Dfb","43" => "Dfc",
|
16
|
+
"44" => "Dfd","45" => "Dsa","46" => "Dsb","47" => "Dsc",
|
17
|
+
"48" => "Dsd","49" => "Dwa","50" => "Dwb","51" => "Dwc",
|
18
|
+
"52" => "Dwd","61" => "EF","62" => "ET" }
|
19
|
+
|
20
|
+
def self.create_column_name(*args)
|
21
|
+
args.join("_")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.climate_zone_to_words(str)
|
25
|
+
I18n.t(str.downcase.to_sym, :scope => [:climate_zones])
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module KoeppenGeiger
|
2
|
+
|
3
|
+
# Can be mixed into any ActiveRecord class that has lat/lng columns
|
4
|
+
#
|
5
|
+
# Example:
|
6
|
+
# class Location < ActiveRecord::Base
|
7
|
+
# has_climate_classification
|
8
|
+
# has_climate_classification :lat_column_name => "latitude", :lng_column_name => "longitude"
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# location = Location.find(1)
|
12
|
+
# location.climate_classification("observed",1901,1925)
|
13
|
+
# => "Cfa"
|
14
|
+
# location.climate_classification("observed",1901,1925).to_words
|
15
|
+
# => "Equatorial climate, fully humid, hot summer"
|
16
|
+
#
|
17
|
+
# Declares a 1:1 association to the model when embedding has_climate_classification
|
18
|
+
|
19
|
+
module HasClimateClassification
|
20
|
+
|
21
|
+
def has_climate_classification(options = {})
|
22
|
+
|
23
|
+
@@options = options
|
24
|
+
|
25
|
+
class_eval do
|
26
|
+
has_one :climate_classification, :class_name => "KoeppenGeiger::ClimateClassification", :foreign_key => "classified_id"
|
27
|
+
|
28
|
+
def classify
|
29
|
+
unless @@options[:lat_column_name].nil? || @@options[:lng_column_name].nil?
|
30
|
+
self[:lat] = self[@@options[:lat_column_name].to_sym] || self[:lat]
|
31
|
+
self[:lng] = self[@@options[:lng_column_name].to_sym] || self[:lng]
|
32
|
+
end
|
33
|
+
|
34
|
+
if self.has_coordinates?
|
35
|
+
self.climate_classification = KoeppenGeiger::ClimateClassification.new if self.climate_classification.nil?
|
36
|
+
pg_cc = KoeppenGeiger::PgClimateClassification.new
|
37
|
+
self.climate_classification.attributes = pg_cc.get_climate_zones(self[:lat],self[:lng])
|
38
|
+
self.climate_classification.save
|
39
|
+
else
|
40
|
+
"Object cannot be classified. Please specify correct column names and make sure your location has correct coordinates."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def classified(scenario,from,to)
|
45
|
+
self.climate_classification[KoeppenGeiger::ClimateClassification.create_column_name(scenario,from,to).to_sym] || "Scenario and/or time period not found"
|
46
|
+
end
|
47
|
+
|
48
|
+
def has_coordinates?
|
49
|
+
!self[:lat].nil? && self[:lat].present? && !self[:lng].nil? && self[:lng].present?
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
# Extend String class
|
55
|
+
String.class_eval do
|
56
|
+
|
57
|
+
def to_words
|
58
|
+
KoeppenGeiger::ClimateClassification.climate_zone_to_words(self)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module KoeppenGeiger
|
2
|
+
|
3
|
+
# This is a tableless model that establishes a connection to PostgreSQL and requests
|
4
|
+
# observed or predicted climate_classifications for a pair of lat/lng coordinates
|
5
|
+
#
|
6
|
+
# See this snippet for more information
|
7
|
+
# http://snipplr.com/view/1849/tableless-model/
|
8
|
+
|
9
|
+
class PgClimateClassification < ActiveRecord::Base
|
10
|
+
establish_connection "koeppen_geiger"
|
11
|
+
|
12
|
+
def self.columns
|
13
|
+
@columns ||= []
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_accessor :scenarios
|
17
|
+
|
18
|
+
##########################
|
19
|
+
# Instance methods
|
20
|
+
##########################
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
get_scenario_tables
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Get all tables from database to see how many different scenarios and timeperiods
|
28
|
+
# have been imported
|
29
|
+
#
|
30
|
+
# Each shapefile imported into the database should create a new table
|
31
|
+
#
|
32
|
+
def get_scenario_tables
|
33
|
+
res = self.connection.execute( "SELECT table_name FROM information_schema.tables
|
34
|
+
WHERE table_schema = 'public'
|
35
|
+
AND table_name != 'geometry_columns'
|
36
|
+
AND table_name != 'spatial_ref_sys'")
|
37
|
+
@scenarios = []
|
38
|
+
if res.num_tuples >= 1
|
39
|
+
res.each do |tuple|
|
40
|
+
@scenarios << tuple["table_name"]
|
41
|
+
end
|
42
|
+
else
|
43
|
+
puts "No data imported yet. Please run rake koeppen_geiger:db:import_data"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_climate_zones(lat,lon)
|
48
|
+
gridcodes = {}
|
49
|
+
@scenarios.each do |scenario|
|
50
|
+
res = self.connection.execute("SELECT gridcode FROM #{scenario} WHERE ST_CONTAINS(the_geom,'POINT(#{lon} #{lat})') LIMIT 1;")
|
51
|
+
if res.num_tuples == 1
|
52
|
+
gridcodes[scenario] = KoeppenGeiger::ClimateClassification::CLIMATE_ZONES[res.getvalue(0,0).to_s]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
return gridcodes
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module KoeppenGeiger
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
require 'zip/zip'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
# Steps
|
8
|
+
#
|
9
|
+
# 1. Add default configuration for koeppen_geiger to database.yml
|
10
|
+
#
|
11
|
+
# 2. Copy migration to create climate classifications table
|
12
|
+
#
|
13
|
+
# 3. run rake db:migrate [RAILS_ENV]
|
14
|
+
#
|
15
|
+
# 4. Create a spatially-enabled database in PostgreSQL
|
16
|
+
# http://postgis.org/documentation/manual-1.5/ch02.html#id2630392
|
17
|
+
#
|
18
|
+
# 5. Load GIS data via shp2pgsql into PostgreSQL database
|
19
|
+
# http://postgis.org/documentation/manual-1.5/ch04.html#shp2pgsql_usage
|
20
|
+
|
21
|
+
class Utils
|
22
|
+
|
23
|
+
@@rails_root = defined?(RAILS_ROOT) ? RAILS_ROOT : ""
|
24
|
+
|
25
|
+
DEFAULT_CONFIG = {"koeppen_geiger" => {
|
26
|
+
"adapter" => "postgresql",
|
27
|
+
"database" => "koeppen_geiger",
|
28
|
+
"username" => 'PLEASE CHANGE ME',
|
29
|
+
"password" => 'PLEASE CHANGE ME',
|
30
|
+
"host" => "localhost",
|
31
|
+
"encoding" => "UTF8",
|
32
|
+
"port" => 5432
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
# Location of database configuration
|
37
|
+
DB_CONFIG = "#{@@rails_root}/config/database.yml"
|
38
|
+
|
39
|
+
# GIS data
|
40
|
+
ARCHIVE = File.dirname(__FILE__) + "/../../data/koeppen-geiger.zip"
|
41
|
+
EXTRACT_DIR = File.dirname(__FILE__) + "/../../data"
|
42
|
+
GIS_DATA_DIR = EXTRACT_DIR + "/koeppen-geiger"
|
43
|
+
|
44
|
+
class << self
|
45
|
+
|
46
|
+
# Open database.yml and add config lines
|
47
|
+
def configure_db
|
48
|
+
yaml = Utils.get_db_config
|
49
|
+
yaml = Hash.new unless yaml
|
50
|
+
|
51
|
+
unless yaml.has_key?("koeppen_geiger")
|
52
|
+
yaml.update(KoeppenGeiger::Utils::DEFAULT_CONFIG)
|
53
|
+
File.open(KoeppenGeiger::Utils::DB_CONFIG, 'w') do |out|
|
54
|
+
YAML::dump(yaml,out)
|
55
|
+
end
|
56
|
+
puts ">> Updated database.yml. Please enter correct username/password combination."
|
57
|
+
else
|
58
|
+
puts ">> Your database.yml has already been updated"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_db_config
|
63
|
+
begin
|
64
|
+
YAML::load_file(KoeppenGeiger::Utils::DB_CONFIG)
|
65
|
+
rescue IOError
|
66
|
+
puts "Could not find database configuration file"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
########
|
71
|
+
|
72
|
+
# Import data
|
73
|
+
def import_gis_data
|
74
|
+
yaml = Utils.get_db_config
|
75
|
+
database = yaml["koeppen_geiger"]["database"]
|
76
|
+
username = yaml["koeppen_geiger"]["username"]
|
77
|
+
password = yaml["koeppen_geiger"]["password"]
|
78
|
+
|
79
|
+
get_shape_files.each {|key,value|
|
80
|
+
Thread.new do
|
81
|
+
Kernel.system("shp2pgsql #{value} public.#{key} | psql -d #{database} -U #{username}")
|
82
|
+
end
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
# Run through subdirectories of data dir
|
87
|
+
# and add shape files and dirname to hash
|
88
|
+
def get_shape_files
|
89
|
+
filehash = {}
|
90
|
+
|
91
|
+
Find.find(KoeppenGeiger::Utils::GIS_DATA_DIR) do |path|
|
92
|
+
if (File.extname(path).eql?(".shp"))
|
93
|
+
dirname = File.dirname(path).split("/")[-1]
|
94
|
+
filehash[dirname] = File.expand_path(path)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
filehash
|
99
|
+
end
|
100
|
+
|
101
|
+
def extract_gis_data
|
102
|
+
if File.exists?(KoeppenGeiger::Utils::ARCHIVE)
|
103
|
+
begin
|
104
|
+
#Open the existing zip file
|
105
|
+
Zip::ZipFile::open(KoeppenGeiger::Utils::ARCHIVE) do |zipfile|
|
106
|
+
zipfile.each do |f|
|
107
|
+
#start extracting each file
|
108
|
+
path = File.join(KoeppenGeiger::Utils::EXTRACT_DIR, f.name)
|
109
|
+
FileUtils.mkdir_p(File.dirname(path))
|
110
|
+
zipfile.extract(f, path)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
rescue Exception => e
|
114
|
+
#If the script blows up, then we should probably be somewhere in this region
|
115
|
+
puts "An error occurred during decompression: \n #{e}."
|
116
|
+
end
|
117
|
+
else
|
118
|
+
puts "\n\nArchive could not be found."
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_record'
|
3
|
+
require 'active_support'
|
4
|
+
require 'i18n'
|
5
|
+
|
6
|
+
I18n.load_path += Dir.glob(File.dirname(__FILE__) + "/locales/*.{rb,yml}")
|
7
|
+
|
8
|
+
require 'yaml'
|
9
|
+
require 'fileutils'
|
10
|
+
require 'koeppen_geiger/climate_classification'
|
11
|
+
require 'koeppen_geiger/has_climate_classification'
|
12
|
+
require 'koeppen_geiger/pg_climate_classification'
|
13
|
+
require 'koeppen_geiger/utils'
|
14
|
+
|
15
|
+
if defined?(ActiveRecord::Base)
|
16
|
+
ActiveRecord::Base.extend KoeppenGeiger::HasClimateClassification
|
17
|
+
end
|
data/lib/locales/de.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
de:
|
2
|
+
climate_zones:
|
3
|
+
af: "Equatorial rainforest, fully humid"
|
4
|
+
am: "Equatorial monsoon"
|
5
|
+
as: "Equatorial savannah with dry summer"
|
6
|
+
aw: "Equatorial savannah with dry winter"
|
7
|
+
bsk: "Cold steppe climate"
|
8
|
+
bsh: "Hot steppe climate"
|
9
|
+
bwk: "Cold desert climate"
|
10
|
+
bwh: "Hot desert climate"
|
11
|
+
csa: "Warm temperature climate, hot and dry summer"
|
12
|
+
csb: "Warm temperature climate, warm and dry summer"
|
13
|
+
csc: "Warm temperature climate, cool and dry summer, cold summer"
|
14
|
+
cfa: "Warm temperature climate, fully humid, hot and dry summer"
|
15
|
+
cfb: "Warm temperature climate, fully humid, warm and dry summer"
|
16
|
+
cfc: "Warm temperature climate, fully humid, cool and dry summer, cold summer"
|
17
|
+
cwa: "Warm temperature climate, hot summer, dry winter"
|
18
|
+
cwb: "Warm temperature climate, warm summer, dry winter"
|
19
|
+
cwc: "Warm temperature climate, cool summer, cold and dry winter"
|
20
|
+
dsa: "Snow climate, hot and dry summer"
|
21
|
+
dsb: "Snow climate, warm and dry summer"
|
22
|
+
dsc: "Snow climate, cool and dry summer, cold winter"
|
23
|
+
dsd: "Snow climate, dry summer, extremely continental"
|
24
|
+
dwa: "Snow climate, hot summer, dry winter"
|
25
|
+
dwb: "Snow climate, warm summer, dry winter"
|
26
|
+
dwc: "Snow climate, cool summer, cold and dry winter"
|
27
|
+
dwd: "Snow climate, dry winter, extremely continental"
|
28
|
+
dfa: "Snow climate, hot summer, fully humid"
|
29
|
+
dfb: "Snow climate, warm summer, fully humid"
|
30
|
+
dfc: "Snow climate, cool summer, cold winter, fully humid"
|
31
|
+
dfd: "Snow climate, extremely continental, fully humid"
|
32
|
+
et: "Tundra climate"
|
33
|
+
ef: "Frost climate"
|
data/lib/locales/en.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
en:
|
2
|
+
climate_zones:
|
3
|
+
af: "Equatorial rainforest, fully humid"
|
4
|
+
am: "Equatorial monsoon"
|
5
|
+
as: "Equatorial savannah with dry summer"
|
6
|
+
aw: "Equatorial savannah with dry winter"
|
7
|
+
bsk: "Cold steppe climate"
|
8
|
+
bsh: "Hot steppe climate"
|
9
|
+
bwk: "Cold desert climate"
|
10
|
+
bwh: "Hot desert climate"
|
11
|
+
csa: "Warm temperature climate, hot and dry summer"
|
12
|
+
csb: "Warm temperature climate, warm and dry summer"
|
13
|
+
csc: "Warm temperature climate, cool and dry summer, cold summer"
|
14
|
+
cfa: "Warm temperature climate, fully humid, hot and dry summer"
|
15
|
+
cfb: "Warm temperature climate, fully humid, warm and dry summer"
|
16
|
+
cfc: "Warm temperature climate, fully humid, cool and dry summer, cold summer"
|
17
|
+
cwa: "Warm temperature climate, hot summer, dry winter"
|
18
|
+
cwb: "Warm temperature climate, warm summer, dry winter"
|
19
|
+
cwc: "Warm temperature climate, cool summer, cold and dry winter"
|
20
|
+
dsa: "Snow climate, hot and dry summer"
|
21
|
+
dsb: "Snow climate, warm and dry summer"
|
22
|
+
dsc: "Snow climate, cool and dry summer, cold winter"
|
23
|
+
dsd: "Snow climate, dry summer, extremely continental"
|
24
|
+
dwa: "Snow climate, hot summer, dry winter"
|
25
|
+
dwb: "Snow climate, warm summer, dry winter"
|
26
|
+
dwc: "Snow climate, cool summer, cold and dry winter"
|
27
|
+
dwd: "Snow climate, dry winter, extremely continental"
|
28
|
+
dfa: "Snow climate, hot summer, fully humid"
|
29
|
+
dfb: "Snow climate, warm summer, fully humid"
|
30
|
+
dfc: "Snow climate, cool summer, cold winter, fully humid"
|
31
|
+
dfd: "Snow climate, extremely continental, fully humid"
|
32
|
+
et: "Tundra climate"
|
33
|
+
ef: "Frost climate"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
namespace :koeppen_geiger do
|
2
|
+
desc "Add new database settings to database.yml"
|
3
|
+
task :configure => :environment do
|
4
|
+
KoeppenGeiger::Utils.configure_db
|
5
|
+
end
|
6
|
+
|
7
|
+
desc "Import gis data into table"
|
8
|
+
task :import_gis_data => :environment do
|
9
|
+
KoeppenGeiger::Utils.import_gis_data
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Extract gis data"
|
13
|
+
task :extract_gis_data => :environment do
|
14
|
+
KoeppenGeiger::Utils.extract_gis_data
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
data.tar.gz.sig
ADDED
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: koeppen_geiger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tobias Weiss
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain:
|
17
|
+
- |
|
18
|
+
-----BEGIN CERTIFICATE-----
|
19
|
+
MIIDOjCCAiKgAwIBAgIBADANBgkqhkiG9w0BAQUFADBDMRUwEwYDVQQDDAx0b2Jp
|
20
|
+
YXMud2Vpc3MxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
|
21
|
+
A2NvbTAeFw0xMTAzMjMxMzQ1NDZaFw0xMjAzMjIxMzQ1NDZaMEMxFTATBgNVBAMM
|
22
|
+
DHRvYmlhcy53ZWlzczEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
|
23
|
+
LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl5YA7OBO
|
24
|
+
/oeOJIdLoGig5D/O2o9vaqizuVisG0W0Br88A5zLCoSC1KAZ6Wdtl3NqqN4CBJ2J
|
25
|
+
zeA82X1b25FjkxHMFBTGhcqBz9ubInX37myHsTq+BzejLakkYlxnpSyAvtYCYJBv
|
26
|
+
nk897vzgNugJUSpQK7p0NfsDA9Utku7ZyuOZ/sQJhZju2GhkNN4h5xMLYiaVdSPu
|
27
|
+
gRPv3d7U/T8ynK01TihhmSMPVjJJXBwxTkgm2pnN4Vt27OgI3qYSNa1LWSMMkste
|
28
|
+
VFKv0vbZmMT1P4WHAGLyIueyMPISwG0RBV2ki3zLd2PkO/8HVKb4MEuZ6ow6GTqf
|
29
|
+
aIgGM+zMvQtpfQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
|
30
|
+
HQ4EFgQUglZplVwHjFDAGwgV1sNwgZvE1sAwDQYJKoZIhvcNAQEFBQADggEBAH/X
|
31
|
+
p6YgH9u+hI5Y6GP4apDwp6/5mTDrHi32URkK4DR+EYev9+7B5UhJirkRr+HwJkZq
|
32
|
+
s2t7bbeCP2Da6Q2fLIzHyapMSpxHXVsiEADDSOZu7a7IwWNie76+8A0bJLoglrI6
|
33
|
+
X5Z0+aLxpj9qLKvhseewhJ8ckUVWViLdIkw56Xco5BSPxI6SEtA9OkEY7hw/Tp7B
|
34
|
+
jzmvl/O54R4hAX2l/2+6TnBNKqk30Rcv4x6bHooTjF0/vs4qvuo9UwVxa+ZQ/xu1
|
35
|
+
RReLEXx35Rm+lRHb5X6nUkC80H2Y3FUBiykkPyJdURmVas5wQ0EwW1l/KEyXDoNY
|
36
|
+
ZHSsbf0Us43IP9I3KVo=
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
|
39
|
+
date: 2011-03-23 00:00:00 +01:00
|
40
|
+
default_executable:
|
41
|
+
dependencies: []
|
42
|
+
|
43
|
+
description: A gem that adds a climate classification parameter based upon the Koeppen-Geiger climate classification system to a point location
|
44
|
+
email: tobias.weiss@gmail.com
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
extra_rdoc_files:
|
50
|
+
- CHANGELOG
|
51
|
+
- LICENSE
|
52
|
+
- README.rdoc
|
53
|
+
- lib/koeppen_geiger.rb
|
54
|
+
- lib/koeppen_geiger/climate_classification.rb
|
55
|
+
- lib/koeppen_geiger/has_climate_classification.rb
|
56
|
+
- lib/koeppen_geiger/pg_climate_classification.rb
|
57
|
+
- lib/koeppen_geiger/utils.rb
|
58
|
+
- lib/locales/de.yml
|
59
|
+
- lib/locales/en.yml
|
60
|
+
- lib/tasks/koeppen_geiger.rake
|
61
|
+
files:
|
62
|
+
- CHANGELOG
|
63
|
+
- LICENSE
|
64
|
+
- Manifest
|
65
|
+
- README.rdoc
|
66
|
+
- Rakefile
|
67
|
+
- VERSION
|
68
|
+
- data/koeppen-geiger.zip
|
69
|
+
- generators/koeppen_geiger_generator.rb
|
70
|
+
- generators/templates/migration.rb
|
71
|
+
- lib/koeppen_geiger.rb
|
72
|
+
- lib/koeppen_geiger/climate_classification.rb
|
73
|
+
- lib/koeppen_geiger/has_climate_classification.rb
|
74
|
+
- lib/koeppen_geiger/pg_climate_classification.rb
|
75
|
+
- lib/koeppen_geiger/utils.rb
|
76
|
+
- lib/locales/de.yml
|
77
|
+
- lib/locales/en.yml
|
78
|
+
- lib/tasks/koeppen_geiger.rake
|
79
|
+
- test/test_helper.rb
|
80
|
+
- test/unit/climate_classification_test.rb
|
81
|
+
- test/unit/pg_climate_classification_test.rb
|
82
|
+
- test/unit/utils_test.rb
|
83
|
+
- koeppen_geiger.gemspec
|
84
|
+
has_rdoc: true
|
85
|
+
homepage: http://github.com/tpunkt/koeppen_geiger
|
86
|
+
licenses: []
|
87
|
+
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options:
|
90
|
+
- --line-numbers
|
91
|
+
- --inline-source
|
92
|
+
- --title
|
93
|
+
- Koeppen_geiger
|
94
|
+
- --main
|
95
|
+
- README.rdoc
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
hash: 3
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
version: "0"
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 11
|
113
|
+
segments:
|
114
|
+
- 1
|
115
|
+
- 2
|
116
|
+
version: "1.2"
|
117
|
+
requirements: []
|
118
|
+
|
119
|
+
rubyforge_project: koeppen_geiger
|
120
|
+
rubygems_version: 1.6.2
|
121
|
+
signing_key:
|
122
|
+
specification_version: 3
|
123
|
+
summary: A Climate Classification Gem for ActiveRecord
|
124
|
+
test_files:
|
125
|
+
- test/test_helper.rb
|
126
|
+
- test/unit/climate_classification_test.rb
|
127
|
+
- test/unit/pg_climate_classification_test.rb
|
128
|
+
- test/unit/utils_test.rb
|
metadata.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
s��n
|