mirror of
https://github.com/publiclab/mapknitter.git
synced 2025-12-14 20:30:00 +01:00
* delete old rails configurations * update pr template * update readme and docker image name * add a mysql setup file * update broken recaptcha link * use File.exist? instead * bump mysql2 * control mysql2 gem * add custom rake test functions to provide option to suppress warnings * small edit to mysql.md * another one * add rake task for total tests * add a require for sass gem * update deprecated URI.encode * undo a comment on Rakefile I made * ensure consistency for rake task names * migrate rake tasks to new branch * update readme * update encoding method
68 lines
2.1 KiB
Ruby
68 lines
2.1 KiB
Ruby
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
|