+
+ def sql_find_pois_in_area(xmin,ymin,xmax,ymax)
+ pois=[]
+ sql=<<-EOF
+ SELECT current_nodes.id,current_nodes.latitude*0.0000001 AS lat,current_nodes.longitude*0.0000001 AS lon,current_nodes.version
+ FROM current_nodes
+ LEFT OUTER JOIN current_way_nodes cwn ON cwn.node_id=current_nodes.id
+ WHERE current_nodes.visible=TRUE
+ AND cwn.id IS NULL
+ AND #{OSM.sql_for_area(ymin, xmin, ymax, xmax, "current_nodes.")}
+ EOF
+ ActiveRecord::Base.connection.select_all(sql).each do |row|
+ poitags={}
+ ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
+ poitags[n['k']]=n['v']
+ end
+ pois << [row['id'].to_i, row['lon'].to_f, row['lat'].to_f, poitags, row['version'].to_i]
+ end
+ pois
+ end
+
+ def sql_find_relations_in_area_and_ways(xmin,ymin,xmax,ymax,way_ids)
+ # ** It would be more Potlatchy to get relations for nodes within ways
+ # during 'getway', not here
+ sql=<<-EOF
+ SELECT DISTINCT cr.id AS relid,cr.version AS version
+ FROM current_relations cr
+ INNER JOIN current_relation_members crm ON crm.id=cr.id
+ INNER JOIN current_nodes cn ON crm.member_id=cn.id AND crm.member_type='node'
+ WHERE #{OSM.sql_for_area(ymin, xmin, ymax, xmax, "cn.")}
+ EOF
+ unless way_ids.empty?
+ sql+=<<-EOF
+ UNION
+ SELECT DISTINCT cr.id AS relid,cr.version AS version
+ FROM current_relations cr
+ INNER JOIN current_relation_members crm ON crm.id=cr.id
+ WHERE crm.member_type='way'
+ AND crm.member_id IN (#{way_ids.join(',')})
+ EOF
+ end
+ return ActiveRecord::Base.connection.select_all(sql).collect { |a| [a['relid'].to_i,a['version'].to_i] }
+ end
+
+ def sql_get_nodes_in_way(wayid)
+ points=[]
+ sql=<<-EOF
+ SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lon,current_nodes.id
+ FROM current_way_nodes,current_nodes
+ WHERE current_way_nodes.id=#{wayid.to_i}
+ AND current_way_nodes.node_id=current_nodes.id
+ AND current_nodes.visible=TRUE
+ ORDER BY sequence_id
+ EOF
+ ActiveRecord::Base.connection.select_all(sql).each do |row|
+ nodetags={}
+ ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
+ nodetags[n['k']]=n['v']
+ end
+ nodetags.delete('created_by')
+ points << [row['lon'].to_f,row['lat'].to_f,row['id'].to_i,nodetags]
+ end
+ points
+ end
+
+ def sql_get_tags_in_way(wayid)
+ tags={}
+ ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_way_tags WHERE id=#{wayid.to_i}").each do |row|
+ tags[row['k']]=row['v']
+ end
+ tags