-
- def whichways(xmin,ymin,xmax,ymax) #:doc:
- xmin-=0.01; ymin-=0.01
- xmax+=0.01; ymax+=0.01
-
- if POTLATCH_USE_SQL then
- way_ids=sql_find_way_ids_in_area(xmin,ymin,xmax,ymax)
- points=sql_find_pois_in_area(xmin,ymin,xmax,ymax)
- relation_ids=sql_find_relations_in_area_and_ways(xmin,ymin,xmax,ymax,way_ids)
- else
- # find the way ids in an area
- nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax, :conditions => "current_nodes.visible = 1", :include => :ways)
- way_ids = nodes_in_area.collect { |node| node.way_ids }.flatten.uniq
-
- # find the node ids in an area that aren't part of ways
- nodes_not_used_in_area = nodes_in_area.select { |node| node.ways.empty? }
- points = nodes_not_used_in_area.collect { |n| [n.id, n.lon, n.lat, n.tags_as_hash] }
-
- # find the relations used by those nodes and ways
- relations = nodes_in_area.collect { |node| node.containing_relations.visible }.flatten +
- way_ids.collect { |id| Way.find(id).containing_relations.visible }.flatten
- relation_ids = relations.collect { |relation| relation.id }.uniq
- end
-
- [way_ids,points,relation_ids]
+ #
+ # return is of the form:
+ # [error_code,
+ # [[way_id, way_version], ...],
+ # [[node_id, lat, lon, [tags, ...], node_version], ...],
+ # [[rel_id, rel_version], ...]]
+ # where the ways are any visible ways which refer to any visible
+ # nodes in the bbox, nodes are any visible nodes in the bbox but not
+ # used in any way, rel is any relation which refers to either a way
+ # or node that we're returning.
+ def whichways(xmin, ymin, xmax, ymax) #:doc:
+ xmin -= 0.01; ymin -= 0.01
+ xmax += 0.01; ymax += 0.01
+
+ # check boundary is sane and area within defined
+ # see /config/application.yml
+ check_boundaries(xmin, ymin, xmax, ymax)
+
+ if POTLATCH_USE_SQL then
+ ways = sql_find_ways_in_area(xmin, ymin, xmax, ymax)
+ points = sql_find_pois_in_area(xmin, ymin, xmax, ymax)
+ relations = sql_find_relations_in_area_and_ways(xmin, ymin, xmax, ymax, ways.collect {|x| x[0]})
+ else
+ # find the way ids in an area
+ nodes_in_area = Node.find_by_area(ymin, xmin, ymax, xmax, :conditions => ["current_nodes.visible = ?", true], :include => :ways)
+ ways = nodes_in_area.inject([]) { |sum, node|
+ visible_ways = node.ways.select { |w| w.visible? }
+ sum + visible_ways.collect { |w| [w.id,w.version] }
+ }.uniq
+ ways.delete([])
+
+ # find the node ids in an area that aren't part of ways
+ nodes_not_used_in_area = nodes_in_area.select { |node| node.ways.empty? }
+ points = nodes_not_used_in_area.collect { |n| [n.id, n.lon, n.lat, n.tags, n.version] }
+
+ # find the relations used by those nodes and ways
+ relations = Relation.find_for_nodes(nodes_in_area.collect { |n| n.id }, :conditions => {:visible => true}) +
+ Relation.find_for_ways(ways.collect { |w| w[0] }, :conditions => {:visible => true})
+ relations = relations.collect { |relation| [relation.id,relation.version] }.uniq
+ end
+
+ [0,ways, points, relations]
+
+ rescue Exception => err
+ [-2,"Sorry - I can't get the map for that area."]