- [wayid,points,way.tags,long_array.min,long_array.max,lat_array.min,lat_array.max]
- end
-
- # ----- getway_old
- # returns old version of way
- # in: [0] way id,
- # [1] way version to get (or -1 for "last deleted version")
- # [2] baselong, [3] basey, [4] masterscale
- # does: gets old version of way and all constituent nodes
- # for undelete, always uses the most recent version of each node
- # (even if it's moved)
- # for revert, uses the historic version of each node, but if that node is
- # still visible and has been changed since, generates a new node id
- # out: [0] 0 (code for success), [1] SWF object name,
- # [2] array of points (as getway _except_ [3] is node.visible?, 0 or 1),
- # [4] xmin, [5] xmax, [6] ymin, [7] ymax (unprojected bbox),
- # [8] way version
- def getway_old(args) #:doc:
- RAILS_DEFAULT_LOGGER.info(" Message: getway_old (server is #{SERVER_URL})")
- # if SERVER_URL=="www.openstreetmap.org" then return -1,"Revert is not currently enabled on the OpenStreetMap server." end
-
- wayid,version,baselong,basey,masterscale=args
- wayid = wayid.to_i
- version = version.to_i
- xmin = ymin = 999999
- xmax = ymax = -999999
- points=[]
- if version<0
- historic=false
- version=getlastversion(wayid,version)
- else
- historic=true
- end
- readwayquery_old(wayid,version,historic).each { |row|
- points<<[long2coord(row['longitude'].to_f,baselong,masterscale),lat2coord(row['latitude'].to_f,basey,masterscale),row['id'].to_i,row['visible'].to_i,tag2array(row['tags'].to_s)]
- xmin=[xmin,row['longitude'].to_f].min
- xmax=[xmax,row['longitude'].to_f].max
- ymin=[ymin,row['latitude' ].to_f].min
- ymax=[ymax,row['latitude' ].to_f].max
- }
-
- # get tags from this version
- attributes={}
- attrlist=ActiveRecord::Base.connection.select_all "SELECT k,v FROM way_tags WHERE id=#{wayid} AND version=#{version}"
- attrlist.each {|a| attributes[a['k'].gsub(':','|')]=a['v'] }
- attributes['history']="Retrieved from v"+version.to_s
-
- [0,wayid,points,attributes,xmin,xmax,ymin,ymax,version]
- end
-
- # ----- getway_history
- # find history of a way
- # in: [0] way id
- # does: finds history of a way
- # out: [0] array of previous versions (where each is
- # [0] version, [1] db timestamp (string),
- # [2] visible 0 or 1,
- # [3] username or 'anonymous' (string))
- def getway_history(args) #:doc:
- wayid=args[0]
- history=[]
- sql=<<-EOF
- SELECT version,timestamp,visible,display_name,data_public
- FROM ways,users
- WHERE ways.id=#{wayid}
- AND ways.user_id=users.id
- AND ways.visible=1
- ORDER BY version DESC
- EOF
- histlist=ActiveRecord::Base.connection.select_all(sql)
- histlist.each { |row|
- if row['data_public'].to_i==1 then user=row['display_name'] else user='anonymous' end
- history<<[row['version'],row['timestamp'],row['visible'],user]
- }
- [history]
- end
-
- # ----- getrelation
- # Get a relation with all of it's tags, and member IDs
- # The input is an array with the following components, in order:
- # 0. relid - the ID of the relation to get
- #
- # The output is an array which contains:
- # [0] relation id, [1] hash of tags, [2] list of members
- def getrelation(args) #:doc:
- relid = args[0]
- relid = relid.to_i
-
- RAILS_DEFAULT_LOGGER.info(" Message: getrel, id=#{relid}")
-
- rel = Relation.find(relid)
-
- [relid,rel.tags,rel.members]#nodes,ways]
- end
-
- # ----- getrelation
- # save relation to the database
- # in: [0] user token (string),
- # [1] original relation id (may be negative),
- # [2] hash of tags, [3] list of members,
- # [4] visible
- # out: [0] 0 (success), [1] original relation id (unchanged),
- # [2] new relation id
- def putrelation(args, renumberednodes, renumberedways) #:doc:
- usertoken,relid,tags,members,visible=args
- uid=getuserid(usertoken)
- if !uid then return -1,"You are not logged in, so the point could not be saved." end
-
- relid = relid.to_i
- visible = visible.to_i
-
- # create a new relation, or find the existing one
- if relid <= 0
- rel = Relation.new
- else
- rel = Relation.find(relid)
- end