forked from publiclab/mapknitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartagen.rb
67 lines (57 loc) · 2.06 KB
/
cartagen.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
64
65
66
67
class Cartagen
def self.chop_word(string)
word = string.split(' ')[0]
string.slice!(word+' ')
word
end
def self.spherical_mercator_lon_to_x(lon,scale=10000)
(lon*scale)/180
end
def self.spherical_mercator_x_to_lon(x,scale=10000)
(x/scale)*180
end
def self.spherical_mercator_lat_to_y(lat,scale=10000)
#180/Math::PI * Math.log(Math.tan(Math::PI/4+lat*(Math::PI/180)/2)) * scale_factor
y = Math.log(Math.tan((90 + lat) * Math::PI / 360)) / (Math::PI / 180)
y * scale / 180
end
def self.spherical_mercator_y_to_lat(y,scale=10000)
#180/Math::PI * (2 * Math.atan(Math.exp(y/scale_factor*Math::PI/180)) - Math::PI/2)
lat = (y / scale) * 180
180/Math::PI * (2 * Math.atan(Math.exp(lat * Math::PI / 180)) - Math::PI / 2)
end
# collects coastline ways into collected_way relations;
# see http://wiki.openstreetmap.org/wiki/Relations/Proposed/Collected_Ways
def self.collect_ways(features)
# collected_ways variable unused review this function
collected_ways = []
nodes = {}
features['osm']['node'].each do |node|
nodes[node['id']] = node
end
features['osm']['way'].each do |way|
if way['tag']
coastline = false
way['tag'].each do |tag|
if tag['k'] == 'natural' && tag['v'] == 'coastline'
coastline = true
break
end
end
if coastline
relation = {}
relation['way'] = []
relation['way'] << way
# are a way's nodes ordered? yes.
# check each way to see if it has a first or last node in common with 'way'
features['osm']['way'].each do |subway|
if subway['nd'].first['ref'] == nodes[way['nd'].first['ref']] || subway['nd'].first['ref'] == nodes[way['nd'].last['ref']] || subway['nd'].last['ref'] == nodes[way['nd'].first['ref']] || subway['nd'].last['ref'] == nodes[way['nd'].last['ref']]
# we have a match!
break
end
end
end
end
end
end
end