-
Notifications
You must be signed in to change notification settings - Fork 0
/
poi_explode.rb
63 lines (55 loc) · 1.6 KB
/
poi_explode.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'json'
require 'pathname'
require 'fileutils'
require 'turf_ruby'
path = Pathname.new(ARGV[0])
pois = {}
categories = Hash.new{ |h, k| h[k] = [] }
JSON.parse(File.read(ARGV[0]))['features'].each{ |poi|
id = poi['properties']['metadata']['id']
poi['geometry'] = Turf.centroid(poi)[:geometry]
pois[id] = poi
poi['properties']['metadata']['category_ids'].each{ |category_id|
categories[category_id] << poi
}
}
FileUtils.mkdir_p("#{path.dirname}/poi")
pois.each{ |id, poi|
File.write(
"#{path.dirname}/poi/#{id}.geojson",
JSON.pretty_generate(poi, indent: ' ')
)
deps_pois = "#{path.dirname}/poi/#{id}/deps_pois.json"
deps_poi_ids = if File.exist?(deps_pois)
JSON.parse(File.read(deps_pois), symbolize_names: true)
else
[]
end
route_point_type = "#{path.dirname}/poi/#{id}/route:point:type.geojson"
deps = if File.exist?(route_point_type)
JSON.parse(File.read(route_point_type), symbolize_names: true)
else
{
type: 'FeatureCollection',
features: []
}
end
deps[:features] = [poi] + deps_poi_ids.map{ |id| pois[id] } + deps[:features]
FileUtils.mkdir_p("#{path.dirname}/poi/#{id}")
File.write(
"#{path.dirname}/poi/#{id}/deps.geojson",
JSON.pretty_generate(deps, indent: ' ')
)
}
FileUtils.mkdir_p("#{path.dirname}/pois/category")
categories.each{ |id, pois|
json = {
type: 'FeatureCollection',
features: pois
}
File.write(
# "#{path.dirname}/pois.geojson?idmenu=#{id}&geometry_as=point&short_description=true",
"#{path.dirname}/pois/category/#{id}.geojson",
JSON.pretty_generate(json, indent: ' ')
)
}