- # 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) #:doc:
- 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
- tags_hash = node.tags_as_hash
-
- points << [projected_longitude, projected_latitude, id, nil, tags_hash]
- long_array << projected_longitude
- lat_array << projected_latitude
+ # 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