]> git.openstreetmap.org Git - rails.git/blob - app/controllers/amf_controller.rb
Merge potlatch_010 branch to head.
[rails.git] / app / controllers / amf_controller.rb
1 # AMF Controller is a semi-standalone API for Flash clients, particularly Potlatch.
2 # All interaction between Potlatch (as a .SWF application) and the 
3 # OSM database takes place using this controller. Messages are 
4 # encoded in the Actionscript Message Format (AMF).
5 #
6 # See Also Potlatch::Potlatch and Potlatch::AMF
7 #
8 # Public domain.
9 # editions Systeme D / Richard Fairhurst 2004-2008
10 #
11 # All in/out parameters are floats unless explicitly stated.
12
13 # to trap errors (getway_old,putway,putpoi,deleteway only):
14 #   return(-1,"message")                <-- just puts up a dialogue
15 #   return(-2,"message")                <-- also asks the user to e-mail me
16 # to log:
17 #   RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")
18 class AmfController < ApplicationController
19   require 'stringio'
20
21   include Potlatch
22
23   session :off
24   before_filter :check_write_availability
25
26   # Main AMF handler. Tha talk method takes in AMF, figures out what to do and dispatched to the appropriate private method
27   def talk
28     req=StringIO.new(request.raw_post+0.chr)    # Get POST data as request
29     # (cf http://www.ruby-forum.com/topic/122163)
30     req.read(2)                                                                 # Skip version indicator and client ID
31     results={}                                                                  # Results of each body
32     renumberednodes={}                                                  # Shared across repeated putways
33     renumberedways={}                                                   # Shared across repeated putways
34
35     # -------------
36     # Parse request
37
38     headers=AMF.getint(req)                                     # Read number of headers
39
40     headers.times do                                # Read each header
41       name=AMF.getstring(req)                           #  |
42       req.getc                                  #  | skip boolean
43       value=AMF.getvalue(req)                           #  |
44       header["name"]=value                              #  |
45     end
46
47     bodies=AMF.getint(req)                                      # Read number of bodies
48     bodies.times do                                     # Read each body
49       message=AMF.getstring(req)                        #  | get message name
50       index=AMF.getstring(req)                          #  | get index in response sequence
51       bytes=AMF.getlong(req)                            #  | get total size in bytes
52       args=AMF.getvalue(req)                            #  | get response (probably an array)
53
54       case message
55       when 'getpresets';                results[index]=AMF.putdata(index,getpresets)
56       when 'whichways';                 results[index]=AMF.putdata(index,whichways(args))
57       when 'whichways_deleted'; results[index]=AMF.putdata(index,whichways_deleted(args))
58       when 'getway';                    results[index]=AMF.putdata(index,getway(args))
59       when 'getrelation';               results[index]=AMF.putdata(index,getrelation(args))
60       when 'getway_old';                results[index]=AMF.putdata(index,getway_old(args))
61       when 'getway_history';    results[index]=AMF.putdata(index,getway_history(args))
62       when 'putway';                    r=putway(args,renumberednodes)
63                                                                 renumberednodes=r[3]
64                                                                 if r[1] != r[2]
65                                                                         renumberedways[r[1]] = r[2]
66                                                                 end
67                                                                 results[index]=AMF.putdata(index,r)
68       when 'putrelation';               results[index]=AMF.putdata(index,putrelation(args, renumberednodes, renumberedways))
69       when 'deleteway';                 results[index]=AMF.putdata(index,deleteway(args))
70       when 'putpoi';                    results[index]=AMF.putdata(index,putpoi(args))
71       when 'getpoi';                    results[index]=AMF.putdata(index,getpoi(args))
72       end
73     end
74
75     # ------------------
76     # Write out response
77
78     RAILS_DEFAULT_LOGGER.info("  Response: start")
79     a,b=results.length.divmod(256)
80     render :content_type => "application/x-amf", :text => proc { |response, output| 
81       output.write 0.chr+0.chr+0.chr+0.chr+a.chr+b.chr
82       results.each do |k,v|
83         output.write(v)
84       end
85     }
86     RAILS_DEFAULT_LOGGER.info("  Response: end")
87   end
88
89   private
90
91   # Return presets (default tags and crap) to potlatch.
92   # Uses POTLATCH_PRESETS global, set up in OSM::Potlatch
93   def getpresets #:doc:
94     return POTLATCH_PRESETS
95   end
96
97   # ----- whichways
98   # Find all the way ids and nodes (including tags and projected lat/lng) which aren't part of those ways in an are
99   # 
100   # The argument is an array containing the following, in order:
101   # 0. minimum longitude
102   # 1. minimum latitude
103   # 2. maximum longitude
104   # 3. maximum latitude
105   # 4. baselong, 5. basey, 6. masterscale as above
106   def whichways(args) #:doc:
107     xmin = args[0].to_f-0.01
108     ymin = args[1].to_f-0.01
109     xmax = args[2].to_f+0.01
110     ymax = args[3].to_f+0.01
111     baselong    = args[4]
112     basey       = args[5]
113     masterscale = args[6]
114
115   def whichways(xmin, ymin, xmax, ymax) #:doc:
116         xmin -= 0.01; ymin -= 0.01
117         xmax += 0.01; ymax += 0.01
118
119         if POTLATCH_USE_SQL then
120           way_ids = sql_find_way_ids_in_area(xmin, ymin, xmax, ymax)
121           points = sql_find_pois_in_area(xmin, ymin, xmax, ymax)
122           relation_ids = sql_find_relations_in_area_and_ways(xmin, ymin, xmax, ymax, way_ids)
123         else
124           # find the way ids in an area
125           nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax, :conditions => "current_nodes.visible = 1", :include => :ways)
126           way_ids = nodes_in_area.collect { |node| node.way_ids }.flatten.uniq
127
128     # find the node ids in an area that aren't part of ways
129     nodes_not_used_in_area = nodes_in_area.select { |node| node.ways.empty? }
130     points = nodes_not_used_in_area.collect { |n| [n.id, n.lon_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash] }
131
132           # find the relations used by those nodes and ways
133           relations = Relation.find_for_nodes(nodes_in_area.collect { |n| n.id }, :conditions => "visible = 1") +
134                   Relation.find_for_ways(way_ids, :conditions => "visible = 1")
135           relation_ids = relations.collect { |relation| relation.id }.uniq
136         end
137
138         [way_ids, points, relation_ids]
139   end
140
141   # ----- whichways_deleted
142   #               return array of deleted ways in current bounding box
143   #               in:   as whichways
144   #               does: finds all deleted ways with a deleted node in bounding box
145   #               out:  [0] array of way ids
146   def whichways_deleted(args) #:doc:
147     xmin = args[0].to_f-0.01
148     ymin = args[1].to_f-0.01
149     xmax = args[2].to_f+0.01
150     ymax = args[3].to_f+0.01
151     baselong    = args[4]
152     basey       = args[5]
153     masterscale = args[6]
154
155   def whichways_deleted(xmin, ymin, xmax, ymax) #:doc:
156         xmin -= 0.01; ymin -= 0.01
157         xmax += 0.01; ymax += 0.01
158
159         nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax, :conditions => "current_nodes.visible = 0 AND current_ways.visible = 0", :include => :ways_via_history)
160         way_ids = nodes_in_area.collect { |node| node.ways_via_history_ids }.flatten.uniq
161
162         [way_ids]
163   end
164
165   # ----- getway
166   # Get a way with all of it's nodes and tags
167   # The input is an array with the following components, in order:
168   # 0. wayid - the ID of the way to get
169   # 1. baselong - origin of SWF map (longitude)
170   # 2. basey - origin of SWF map (latitude)
171   # 3. masterscale - SWF map scale
172   #
173   # The output is an array which contains all the nodes (with projected 
174   # latitude and longitude) and tags for a way (and all the nodes tags). 
175   # It also has the way's unprojected (WGS84) bbox.
176   #
177   # FIXME: The server really shouldn't be figuring out a ways bounding box and doing projection for potlatch
178   # FIXME: the argument splitting should be done in the 'talk' method, not here
179   def getway(args) #:doc:
180     wayid,baselong,basey,masterscale = args
181     wayid = wayid.to_i
182
183   def getway(wayid) #:doc:
184         if POTLATCH_USE_SQL then
185           points = sql_get_nodes_in_way(wayid)
186           tags = sql_get_tags_in_way(wayid)
187         else
188           # Ideally we would do ":include => :nodes" here but if we do that
189           # then rails only seems to return the first copy of a node when a
190           # way includes a node more than once
191           way = Way.find(wayid)
192           points = way.nodes.collect do |node|
193                 [node.lon, node.lat, node.id, nil, node.tags_as_hash]
194           end
195           tags = way.tags
196         end
197
198         [wayid, points, tags]
199   end
200
201   # ----- getway_old
202   #               returns old version of way
203   #               in:   [0] way id,
204   #                             [1] way version to get (or -1 for "last deleted version")
205   #                             [2] baselong, [3] basey, [4] masterscale
206   #               does: gets old version of way and all constituent nodes
207   #                             for undelete, always uses the most recent version of each node
208   #                               (even if it's moved)
209   #                             for revert, uses the historic version of each node, but if that node is
210   #                               still visible and has been changed since, generates a new node id
211   #               out:  [0] 0 (code for success), [1] SWF object name,
212   #                             [2] array of points (as getway _except_ [3] is node.visible?, 0 or 1),
213   #                             [4] xmin, [5] xmax, [6] ymin, [7] ymax (unprojected bbox),
214   #                             [8] way version
215   def getway_old(args) #:doc:
216     RAILS_DEFAULT_LOGGER.info("  Message: getway_old (server is #{SERVER_URL})")
217     #   if SERVER_URL=="www.openstreetmap.org" then return -1,"Revert is not currently enabled on the OpenStreetMap server." end
218
219   def getway_old(id, version) #:doc:
220         if version < 0
221           old_way = OldWay.find(:first, :conditions => ['visible = 1 AND id = ?', id], :order => 'version DESC')
222           points = old_way.get_nodes_undelete
223         else
224           old_way = OldWay.find(:first, :conditions => ['id = ? AND version = ?', id, version])
225           points = old_way.get_nodes_revert
226         end
227
228         old_way.tags['history'] = "Retrieved from v#{old_way.version}"
229
230         [0, id, points, old_way.tags, old_way.version]
231   end
232
233   def getway_history(wayid) #:doc:
234         history = Way.find(wayid).old_ways.collect do |old_way|
235           user = old_way.user.data_public? ? old_way.user.display_name : 'anonymous'
236           [old_way.version, old_way.timestamp.strftime("%d %b %Y, %H:%M"), old_way.visible ? 1 : 0, user]
237         end
238
239         [history]
240   end
241
242   # Get a relation with all tags and members.
243   # Returns:
244   # 0. relation id,
245   # 1. hash of tags,
246   # 2. list of members.
247   
248   def getrelation(relid) #:doc:
249         rel = Relation.find(relid)
250
251         [relid, rel.tags, rel.members]
252   end
253
254   # ----- getrelation
255   #               save relation to the database
256   #               in:   [0] user token (string),
257   #                             [1] original relation id (may be negative),
258   #                             [2] hash of tags, [3] list of members,
259   #                             [4] visible
260   #               out:  [0] 0 (success), [1] original relation id (unchanged),
261   #                             [2] new relation id
262   def putrelation(args, renumberednodes, renumberedways) #:doc:
263     usertoken,relid,tags,members,visible=args
264     uid=getuserid(usertoken)
265     if !uid then return -1,"You are not logged in, so the point could not be saved." end
266
267   def putrelation(renumberednodes, renumberedways, usertoken, relid, tags, members, visible) #:doc:
268         uid = getuserid(usertoken)
269         if !uid then return -1,"You are not logged in, so the relation could not be saved." end
270
271         relid = relid.to_i
272         visible = visible.to_i
273
274         # create a new relation, or find the existing one
275     if relid <= 0
276       rel = Relation.new
277     else
278       rel = Relation.find(relid)
279     end
280
281     # check the members are all positive, and correctly type
282     typedmembers = []
283     members.each do |m|
284       mid = m[1].to_i
285       if mid < 0
286         mid = renumberednodes[mid] if m[0] == 'node'
287         mid = renumberedways[mid] if m[0] == 'way'
288         if mid < 0
289           return -2, "Negative ID unresolved"
290         end
291       end
292       typedmembers << [m[0], mid, m[2]]
293     end
294
295         # assign new contents
296         rel.members = typedmembers
297         rel.tags = tags
298         rel.visible = visible
299         rel.user_id = uid
300
301     # check it then save it
302     # BUG: the following is commented out because it always fails on my
303     #  install. I think it's a Rails bug.
304
305     #if !rel.preconditions_ok?
306     #  return -2, "Relation preconditions failed"
307     #else
308       rel.save_with_history!
309     #end
310
311         [0, relid, rel.id]
312   end
313
314   # ----- putway
315   #               saves a way to the database
316   #               in:   [0] user token (string),
317   #                             [1] original way id (may be negative), 
318   #                             [2] array of points (as getway/getway_old),
319   #                             [3] hash of way tags,
320   #                             [4] original way version (0 if not a reverted/undeleted way),
321   #                             [5] baselong, [6] basey, [7] masterscale
322   #               does: saves way to the database
323   #                             all constituent nodes are created/updated as necessary
324   #                             (or deleted if they were in the old version and are otherwise unused)
325   #               out:  [0] 0 (code for success), [1] original way id (unchanged),
326   #                             [2] new way id, [3] hash of renumbered nodes (old id=>new id),
327   #                             [4] xmin, [5] xmax, [6] ymin, [7] ymax (unprojected bbox)
328   def putway(args,renumberednodes) #:doc:
329     RAILS_DEFAULT_LOGGER.info("  putway started")
330     usertoken,originalway,points,attributes,oldversion,baselong,basey,masterscale=args
331     uid=getuserid(usertoken)
332     if !uid then return -1,"You are not logged in, so the way could not be saved." end
333
334   def putway(renumberednodes, usertoken, originalway, points, attributes) #:doc:
335
336         # -- Initialise and carry out checks
337         
338         uid = getuserid(usertoken)
339         if !uid then return -1,"You are not logged in, so the way could not be saved." end
340
341         originalway = originalway.to_i
342
343         points.each do |a|
344           if a[2] == 0 or a[2].nil? then return -2,"Server error - node with id 0 found in way #{originalway}." end
345           if a[1] == 90 then return -2,"Server error - node with lat -90 found in way #{originalway}." end
346         end
347
348         if points.length < 2 then return -2,"Server error - way is only #{points.length} points long." end
349
350     # -- 3.     read original way into memory
351
352         if originalway < 0
353           way = Way.new
354           uniques = []
355         else
356           way = Way.find(originalway)
357           uniques = way.unshared_node_ids
358         end
359
360     # -- 4.     get version by inserting new row into ways
361
362         nodes = []
363
364         points.each do |n|
365           lon = n[0].to_f
366           lat = n[1].to_f
367           id = n[2].to_i
368           savenode = false
369
370           if renumberednodes[id]
371             id = renumberednodes[id]
372           elsif id < 0
373                 # Create new node
374                 node = Node.new
375                 savenode = true
376           else
377                 node = Node.find(id)
378                 if !fpcomp(lat, node.lat) or !fpcomp(lon, node.lon) or
379                    Tags.join(n[4]) != node.tags or !node.visible?
380                   savenode = true
381                 end
382           end
383
384           if savenode
385                 node.user_id = uid
386             node.lat = lat
387         node.lon = lon
388             node.tags = Tags.join(n[4])
389             node.visible = true
390             node.save_with_history!
391
392                 if id != node.id
393                   renumberednodes[id] = node.id
394                   id = node.id
395             end
396           end
397
398           uniques = uniques - [id]
399           nodes.push(id)
400         end
401
402         # -- Delete any unique nodes
403         
404         uniques.each do |n|
405           deleteitemrelations(n, 'node')
406
407           node = Node.find(n)
408           node.user_id = uid
409           node.visible = false
410           node.save_with_history!
411         end
412
413     points.each_index do |i|
414       xs=coord2long(points[i][0],masterscale,baselong)
415       ys=coord2lat(points[i][1],masterscale,basey)
416       xmin=[xs,xmin].min; xmax=[xs,xmax].max
417       ymin=[ys,ymin].min; ymax=[ys,ymax].max
418       node=points[i][2].to_i
419       tagstr=array2tag(points[i][4])
420       tagsql="'"+sqlescape(tagstr)+"'"
421       lat=(ys * 10000000).round
422       long=(xs * 10000000).round
423       tile=QuadTile.tile_for_point(ys, xs)
424
425         way.tags = attributes
426         way.nds = nodes
427         way.user_id = uid
428         way.visible = true
429         way.save_with_history!
430
431         [0, originalway, way.id, renumberednodes]
432   end
433
434   # ----- putpoi
435   #               save POI to the database
436   #               in:   [0] user token (string),
437   #                             [1] original node id (may be negative),
438   #                             [2] projected longitude, [3] projected latitude,
439   #                             [4] hash of tags, [5] visible (0 to delete, 1 otherwise), 
440   #                             [6] baselong, [7] basey, [8] masterscale
441   #               does: saves POI node to the database
442   #                             refuses save if the node has since become part of a way
443   #               out:  [0] 0 (success), [1] original node id (unchanged),
444   #                             [2] new node id
445   def putpoi(args) #:doc:
446     usertoken,id,x,y,tags,visible,baselong,basey,masterscale=args
447     uid=getuserid(usertoken)
448     if !uid then return -1,"You are not logged in, so the point could not be saved." end
449
450   def putpoi(usertoken, id, lon, lat, tags, visible) #:doc:
451         uid = getuserid(usertoken)
452         if !uid then return -1,"You are not logged in, so the point could not be saved." end
453
454         id = id.to_i
455         visible = (visible.to_i == 1)
456
457         if id > 0 then
458           node = Node.find(id)
459
460           if !visible then
461             unless node.ways.empty? then return -1,"The point has since become part of a way, so you cannot save it as a POI." end
462             deleteitemrelations(id, 'node')
463           end
464         else
465           node = Node.new
466         end
467
468         node.user_id = uid
469         node.lat = lat
470         node.lon = lon
471         node.tags = Tags.join(tags)
472         node.visible = visible
473         node.save_with_history!
474
475         [0, id, node.id]
476   end
477
478   # ----- getpoi
479   # read POI from database
480   #               (only called on revert: POIs are usually read by whichways)
481   #               in:   [0] node id, [1] baselong, [2] basey, [3] masterscale
482   #               does: reads POI
483   #               out:  [0] id (unchanged), [1] projected long, [2] projected lat,
484   #                             [3] hash of tags
485   def getpoi(args) #:doc:
486     id,baselong,basey,masterscale = args
487     
488     n = Node.find(id.to_i)
489     if n
490       return [n.id, n.lon_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash]
491     else
492       return [nil,nil,nil,'']
493     end
494   end
495
496   def getpoi(id) #:doc:
497         n = Node.find(id)
498
499         if n
500           return [n.id, n.lon, n.lat, n.tags_as_hash]
501         else
502           return [nil, nil, nil, '']
503         end
504   end
505
506
507   def deleteway(usertoken, way_id) #:doc:
508         uid = getuserid(usertoken)
509         if !uid then return -1,"You are not logged in, so the way could not be deleted." end
510
511         # FIXME: would be good not to make two history entries when removing
512         #                two nodes from the same relation
513         user = User.find(uid)
514         way = Way.find(way_id)
515         way.unshared_node_ids.each do |n|
516           deleteitemrelations(n, 'node')
517         end
518
519         way.delete_with_relations_and_nodes_and_history(user)  
520
521         [0, way_id]
522   end
523
524   def createuniquenodes(way,uqn_name,nodelist) #:doc:
525     # Find nodes which appear in this way but no others
526     sql=<<-EOF
527   CREATE TEMPORARY TABLE #{uqn_name}
528           SELECT a.node_id
529             FROM (SELECT DISTINCT node_id FROM current_way_nodes
530               WHERE id=#{way}) a
531          LEFT JOIN current_way_nodes b
532             ON b.node_id=a.node_id
533              AND b.id!=#{way}
534            WHERE b.node_id IS NULL
535   EOF
536     unless nodelist.empty? then
537       sql+="AND a.node_id NOT IN ("+nodelist.join(',')+")"
538     end
539     ActiveRecord::Base.connection.execute(sql)
540   end
541
542
543
544   # ====================================================================
545   # Relations handling
546   # deleteuniquenoderelations(uqn_name,uid,db_now)
547   # deleteitemrelations(way|node,'way'|'node',uid,db_now)
548
549   def deleteuniquenoderelations(uqn_name,uid,db_now) #:doc:
550     sql=<<-EOF
551   SELECT node_id,cr.id FROM #{uqn_name},current_relation_members crm,current_relations cr 
552    WHERE crm.member_id=node_id 
553      AND crm.member_type='node' 
554      AND crm.id=cr.id 
555      AND cr.visible=1
556   EOF
557
558   def deleteitemrelations(objid, type) #:doc:
559         relations = RelationMember.find(:all, 
560                                                                         :conditions => ['member_type = ? and member_id = ?', type, objid], 
561                                                                         :include => :relation).collect { |rm| rm.relation }.uniq
562
563         relations.each do |rel|
564           rel.members.delete_if { |x| x[0] == type and x[1] == objid }
565           rel.save_with_history!
566         end
567   end
568
569   def deleteitemrelations(objid,type,uid,db_now) #:doc:
570     sql=<<-EOF
571   SELECT cr.id FROM current_relation_members crm,current_relations cr 
572    WHERE crm.member_id=#{objid} 
573      AND crm.member_type='#{type}' 
574      AND crm.id=cr.id 
575      AND cr.visible=1
576   EOF
577
578     relways=ActiveRecord::Base.connection.select_all(sql)
579     relways.each do |a|
580       removefromrelation(objid,type,a['id'],uid,db_now)
581     end
582   end
583
584   def removefromrelation(objid,type,relation,uid,db_now) #:doc:
585     rver=ActiveRecord::Base.connection.insert("INSERT INTO relations (id,user_id,timestamp,visible) VALUES (#{relation},#{uid},#{db_now},1)")
586
587     tagsql=<<-EOF
588   INSERT INTO relation_tags (id,k,v,version) 
589   SELECT id,k,v,#{rver} FROM current_relation_tags 
590    WHERE id=#{relation} 
591   EOF
592     ActiveRecord::Base.connection.insert(tagsql)
593
594     membersql=<<-EOF
595   INSERT INTO relation_members (id,member_type,member_id,member_role,version) 
596   SELECT id,member_type,member_id,member_role,#{rver} FROM current_relation_members 
597    WHERE id=#{relation} 
598      AND (member_id!=#{objid} OR member_type!='#{type}')
599   EOF
600     ActiveRecord::Base.connection.insert(membersql)
601
602     ActiveRecord::Base.connection.update("UPDATE current_relations SET user_id=#{uid},timestamp=#{db_now} WHERE id=#{relation}")
603     ActiveRecord::Base.connection.execute("DELETE FROM current_relation_members WHERE id=#{relation} AND member_type='#{type}' AND member_id=#{objid}")
604   end
605
606   def sqlescape(a) #:doc:
607     a.gsub(/[\000-\037]/,"").gsub("'","''").gsub(92.chr) {92.chr+92.chr}
608   end
609
610   def tag2array(a) #:doc:
611     tags={}
612     Tags.split(a) do |k, v|
613       tags[k.gsub(':','|')]=v
614     end
615     tags
616   end
617
618   def array2tag(a) #:doc:
619     tags = []
620     a.each do |k,v|
621       if v=='' then next end
622       if v[0,6]=='(type ' then next end
623       tags << [k.gsub('|',':'), v]
624     end
625     return Tags.join(tags)
626   end
627
628   def getuserid(token) #:doc:
629     if (token =~ /^(.+)\+(.+)$/) then
630       user = User.authenticate(:username => $1, :password => $2)
631     else
632       user = User.authenticate(:token => token)
633     end
634
635     return user ? user.id : nil;
636   end
637
638   # ====================================================================
639   # Co-ordinate conversion
640
641   def lat2coord(a,basey,masterscale) #:doc:
642     -(lat2y(a)-basey)*masterscale
643   end
644
645   def long2coord(a,baselong,masterscale) #:doc:
646     (a-baselong)*masterscale
647   end
648
649   def lat2y(a) #:doc:
650     180/Math::PI * Math.log(Math.tan(Math::PI/4+a*(Math::PI/180)/2))
651   end
652
653   def coord2lat(a,masterscale,basey) #:doc:
654     y2lat(a/-masterscale+basey)
655   end
656
657   def coord2long(a,masterscale,baselong) #:doc:
658     a/masterscale+baselong
659   end
660
661   def y2lat(a)
662     180/Math::PI * (2*Math.atan(Math.exp(a*Math::PI/180))-Math::PI/2)
663   end
664
665 end
666
667 # Local Variables:
668 # indent-tabs-mode: t
669 # tab-width: 4
670 # End: