Class: Jetel::Modules::Gadm
- Inherits:
-
Module
- Object
- Module
- Jetel::Modules::Gadm
show all
- Defined in:
- lib/jetel/modules/gadm/gadm.rb
Instance Attribute Summary
Attributes inherited from Module
#downloader
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Module
#download_dir, download_dir, #download_source, downloaded_file, #downloaded_file, extract_dir, #extract_dir, extracted_file, #extracted_file, #initialize, #load, #sources, target_dir, #target_dir, #transform_dir, transform_dir, transformed_file, #transformed_file, #unzip
Class Method Details
.sources ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/jetel/modules/gadm/gadm.rb', line 17
def sources
page = Nokogiri::HTML(open('http://www.gadm.org/country'))
options = page.css('select[name="cnt"] > option')
res = options.map do |option|
full_name = option['value']
name = "#{full_name.split('_').first}"
filename = "#{name}_adm_shp.zip"
{
name: name,
url: "http://biogeo.ucdavis.edu/data/gadm2.8/shp/#{filename}",
filename_downloaded: filename,
flat: true,
filename_transformed: "#{name}_adm?.topo.json"
}
end
res
end
|
Instance Method Details
#download(global_options, options, args) ⇒ Object
39
40
41
42
43
|
# File 'lib/jetel/modules/gadm/gadm.rb', line 39
def download(global_options, options, args)
self.class.sources.pmap do |source|
download_source(source, global_options.merge(options))
end
end
|
45
46
47
48
49
|
# File 'lib/jetel/modules/gadm/gadm.rb', line 45
def (global_options, options, args)
self.class.sources.pmap do |source|
unzip(source, global_options.merge(options))
end
end
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/jetel/modules/gadm/gadm.rb', line 51
def transform(global_options, options, args)
self.class.sources.pmap(8) do |source|
= (source, global_options.merge(options))
transformed_file = transformed_file(source, global_options.merge(options))
dest_dir = transform_dir(source, global_options.merge(options))
FileUtils.mkdir_p(dest_dir)
= (source, global_options.merge(options))
Dir.glob("#{}/*.shp") do |shapefile|
puts "Transforming #{shapefile}"
destfile = shapefile.gsub(, dest_dir).gsub('.shp', '.topo.json')
cmd = "topojson --no-stitch-poles --no-force-clockwise #{shapefile} -o #{destfile} -p"
puts cmd
PTY.spawn(cmd) do |stdout, stdin, pid|
begin
stdout.each { |line| print line }
end
end
end
end
end
|