- end
-
- [presets,presetmenus,presetnames,colours,casing,areas,autotags]
- end
-
- # ----- whichways
- # return array of ways in current bounding box
-
- # in: [0] xmin, [1] ymin, [2] xmax, [3] ymax (bbox in degrees)
- # [4] baselong (longitude of SWF map origin),
- # [5] basey (projected latitude of SWF map origin),
- # [6] masterscale (SWF map scale)
- # does: finds all ways and POI nodes in bounding box
- # at present, instead of using correct (=more complex) SQL to find
- # corner-crossing ways, it simply enlarges the bounding box
- # out: [0] array of way ids,
- # [1] array of POIs
- # (where each POI is an array containing:
- # [0] id, [1] projected long, [2] projected lat, [3] hash of tags)
-
- def whichways(args)
- xmin = args[0].to_f-0.01
- ymin = args[1].to_f-0.01
- xmax = args[2].to_f+0.01
- ymax = args[3].to_f+0.01
- baselong = args[4]
- basey = args[5]
- masterscale = args[6]
-
- RAILS_DEFAULT_LOGGER.info(" Message: whichways, bbox=#{xmin},#{ymin},#{xmax},#{ymax}")
-
- waylist = ActiveRecord::Base.connection.select_all("SELECT DISTINCT current_way_nodes.id AS wayid"+
- " FROM current_way_nodes,current_nodes,current_ways "+
- " WHERE current_nodes.id=current_way_nodes.node_id "+
- " AND current_nodes.visible=1 "+
- " AND current_ways.id=current_way_nodes.id "+
- " AND current_ways.visible=1 "+
- " AND "+OSM.sql_for_area(ymin, xmin, ymax, xmax, "current_nodes."))
-
- ways = waylist.collect {|a| a['wayid'].to_i } # get an array of way IDs
-
- pointlist = ActiveRecord::Base.connection.select_all("SELECT current_nodes.id,current_nodes.latitude*0.0000001 AS lat,current_nodes.longitude*0.0000001 AS lng,current_nodes.tags "+
- " FROM current_nodes "+
- " LEFT OUTER JOIN current_way_nodes cwn ON cwn.node_id=current_nodes.id "+
- " WHERE "+OSM.sql_for_area(ymin, xmin, ymax, xmax, "current_nodes.")+
- " AND cwn.id IS NULL "+
- " AND current_nodes.visible=1")
-
- points = pointlist.collect {|a| [a['id'],long2coord(a['lng'].to_f,baselong,masterscale),lat2coord(a['lat'].to_f,basey,masterscale),tag2array(a['tags'])] } # get a list of node ids and their tags
-
- [ways,points]
- end
-
- # ----- whichways_deleted
- # return array of deleted ways in current bounding box
-
- # in: as whichways
- # does: finds all deleted ways with a deleted node in bounding box
- # out: [0] array of way ids
-
- def whichways_deleted(args)
- xmin = args[0].to_f-0.01
- ymin = args[1].to_f-0.01
- xmax = args[2].to_f+0.01
- ymax = args[3].to_f+0.01
- baselong = args[4]
- basey = args[5]
- masterscale = args[6]
-
- sql=<<-EOF
- SELECT DISTINCT current_ways.id
- FROM current_nodes,way_nodes,current_ways
- WHERE #{OSM.sql_for_area(ymin, xmin, ymax, xmax, "current_nodes.")}
- AND way_nodes.node_id=current_nodes.id
- AND way_nodes.id=current_ways.id
- AND current_nodes.visible=0
- AND current_ways.visible=0
- EOF
- waylist = ActiveRecord::Base.connection.select_all(sql)
- ways = waylist.collect {|a| a['id'].to_i }
- [ways]
- end
-
- # Get a way with all of it's nodes and tags
- # The input is an array with the following components, in order:
- # 0. SWF object name (String?) - fuck knows
- # 1. wayid (String?) - the ID of the way to get
- # 2. baselong - fuck knows
- # 3. basey - fuck knows
- # 4. masterscale - fuck knows
- #
- # The output is an array which contains all the nodes (with projected latitude and longitude) and tags for a way (and all the nodes tags). It also has the way's unprojected (WGS84) bbox.
- #
- # FIXME: The server really shouldn't be figuring out a ways bounding box and doing projection for potlatch
- # FIXME: the argument splitting should be done in the 'talk' method, not here
- #
- def getway(args)
- objname,wayid,baselong,basey,masterscale = args
- wayid = wayid.to_i
-
- RAILS_DEFAULT_LOGGER.info(" Message: getway, id=#{wayid}")
-
- way = Way.find_eager(wayid)
- long_array = []
- lat_array = []
- points = []
-
- way.way_nodes.each do |way_node|
- node = way_node.node # get the node record
- projected_longitude = node.lon_potlatch(baselong,masterscale) # do projection for potlatch
- projected_latitude = node.lat_potlatch(basey,masterscale)
- id = node.id # node ide
- tags_hash = node.tags_as_hash # hash of tags
-
- points << [projected_longitude, projected_latitude, id, nil, tags_hash] # FIXME remove the nil in potlatch. performance matters y'know!
- long_array << projected_longitude
- lat_array << projected_latitude
- end
-
- [objname,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] SWF object name, [1] way id,
- # [2] way version to get (or -1 for "last deleted version")
- # [3] baselong, [4] basey, [5] 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)
- 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
-
- objname,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)