# editions Systeme D / Richard Fairhurst 2004-2008
#
# All in/out parameters are floats unless explicitly stated.
- # Note that in getway/getway_old, SWF object name and way id are
- #ĂŠidentical and one could probably be eliminated.
#
# to trap errors (getway_old,putway,putpoi,deleteway only):
# return(-1,"message") <-- just puts up a dialogue
when 'getway_old'; results[index]=putdata(index,getway_old(args))
when 'getway_history'; results[index]=putdata(index,getway_history(args))
when 'putway'; r=putway(args,renumberednodes)
- renumberednodes=r[3]
- results[index]=putdata(index,r)
+ renumberednodes=r[3]
+ results[index]=putdata(index,r)
when 'deleteway'; results[index]=putdata(index,deleteway(args))
when 'putpoi'; results[index]=putdata(index,putpoi(args))
when 'getpoi'; results[index]=putdata(index,getpoi(args))
[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)
+
+ # Find all the way ids and nodes (including tags and projected lat/lng) which aren't part of those ways in an are
+ #
+ # The argument is an array containing the following, in order:
+ # 0. minimum longitude
+ # 1. minimum latitude
+ # 2. maximum longitude
+ # 3. maximum latitude
+ # 4. baselong, 5. basey, 6. masterscale as above
def whichways(args)
xmin = args[0].to_f-0.01
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
+ # find the way ids in an area
+ nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax,:conditions => "visible = 1", :include => :way_nodes)
+ waynodes_in_area = nodes_in_area.collect {|node| node.way_nodes }.flatten
+ ways = waynodes_in_area.collect {|way_node| way_node.id[0]}.uniq
- 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
+ # find the node ids in an area that aren't part of ways
+ node_ids_in_area = nodes_in_area.collect {|node| node.id}.uniq
+ node_ids_used_in_ways = waynodes_in_area.collect {|way_node| way_node.node_id}.uniq
+ node_ids_not_used_in_area = node_ids_in_area - node_ids_used_in_ways
+ nodes_not_used_in_area = Node.find(node_ids_not_used_in_area)
+ points = nodes_not_used_in_area.collect {|n| [n.id, n.lon_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash] }
[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
[ways]
end
+
+ # ----- getway
+
# 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
+ # 0. wayid - the ID of the way to get
+ # 1. baselong - origin of SWF map (longitude)
+ # 2. basey - origin of SWF map (latitude)
+ # 3. masterscale - SWF map scale
#
- # 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.
+ # 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,baselong,basey,masterscale = args
wayid = wayid.to_i
RAILS_DEFAULT_LOGGER.info(" Message: getway, id=#{wayid}")
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
+ id = node.id
+ tags_hash = node.tags_as_hash
- points << [projected_longitude, projected_latitude, id, nil, tags_hash] # FIXME remove the nil in potlatch. performance matters y'know!
+ points << [projected_longitude, projected_latitude, id, nil, tags_hash]
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]
+ [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] SWF object name, [1] way id,
- # [2] way version to get (or -1 for "last deleted version")
- # [3] baselong, [4] basey, [5] masterscale
+ # 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)
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,version,baselong,basey,masterscale=args
wayid = wayid.to_i
version = version.to_i
xmin = ymin = 999999
attrlist.each {|a| attributes[a['k'].gsub(':','|')]=a['v'] }
attributes['history']="Retrieved from v"+version.to_s
- [0,objname,points,attributes,xmin,xmax,ymin,ymax,version]
+ [0,wayid,points,attributes,xmin,xmax,ymin,ymax,version]
end
# ----- getway_history