X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/bbd769304cf29bbd9574fd3c7167feb7d5d0aa17..588a65c2b21185c0f080fafae254d601128c38ea:/app/controllers/amf_controller.rb diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 471e2fada..84e9f4537 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -58,8 +58,8 @@ class AmfController < ApplicationController when 'getway_old'; results[index]=AMF.putdata(index,getway_old(args)) when 'getway_history'; results[index]=AMF.putdata(index,getway_history(args)) when 'putway'; r=putway(args,renumberednodes) - renumberednodes=r[3] - results[index]=AMF.putdata(index,r) + renumberednodes=r[3] + results[index]=AMF.putdata(index,r) when 'deleteway'; results[index]=AMF.putdata(index,deleteway(args)) when 'putpoi'; results[index]=AMF.putdata(index,putpoi(args)) when 'getpoi'; results[index]=AMF.putdata(index,getpoi(args)) @@ -109,18 +109,14 @@ class AmfController < ApplicationController RAILS_DEFAULT_LOGGER.info(" Message: whichways, bbox=#{xmin},#{ymin},#{xmax},#{ymax}") # 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 + 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 - 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] } + 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_potlatch(baselong,masterscale), n.lat_potlatch(basey,masterscale), n.tags_as_hash] } - [ways,points] + [way_ids,points] end # ----- whichways_deleted @@ -171,13 +167,16 @@ class AmfController < ApplicationController RAILS_DEFAULT_LOGGER.info(" Message: getway, id=#{wayid}") - way = Way.find_eager(wayid) + # Ideally we would do ":include => :nodes" here but if we do that + # then rails only seems to return the first copy of a node when a + # way includes a node more than once + way = Way.find(wayid) + long_array = [] lat_array = [] points = [] - way.way_nodes.each do |way_node| - node = way_node.node # get the node record + way.nodes.each do |node| projected_longitude = node.lon_potlatch(baselong,masterscale) # do projection for potlatch projected_latitude = node.lat_potlatch(basey,masterscale) id = node.id @@ -294,11 +293,13 @@ class AmfController < ApplicationController RAILS_DEFAULT_LOGGER.info(" Message: putway, id=#{originalway}") - # -- Temporary check for null IDs + # -- Check for null IDs or short ways points.each do |a| if a[2]==0 or a[2].nil? then return -2,"Server error - node with id 0 found in way #{originalway}." end end + + if points.length<2 then return -2,"Server error - way is only #{points.length} points long." end # -- 3. read original way into memory @@ -559,9 +560,10 @@ class AmfController < ApplicationController ActiveRecord::Base.connection.select_all(sql) end + # Get the latest version id of a way def getlastversion(id,version) #:doc: - row=ActiveRecord::Base.connection.select_one("SELECT version FROM ways WHERE id=#{id} AND visible=1 ORDER BY version DESC LIMIT 1") - row['version'] + old_way = OldWay.find(:first, :conditions => ['visible=1 AND id=?' , id], :order => 'version DESC') + old_way.version end def readwayquery_old(id,version,historic) #:doc: @@ -732,11 +734,11 @@ class AmfController < ApplicationController # Co-ordinate conversion def lat2coord(a,basey,masterscale) #:doc: - -(lat2y(a)-basey)*masterscale+250 + -(lat2y(a)-basey)*masterscale end def long2coord(a,baselong,masterscale) #:doc: - (a-baselong)*masterscale+350 + (a-baselong)*masterscale end def lat2y(a) #:doc: @@ -744,11 +746,11 @@ class AmfController < ApplicationController end def coord2lat(a,masterscale,basey) #:doc: - y2lat((a-250)/-masterscale+basey) + y2lat(a/-masterscale+basey) end def coord2long(a,masterscale,baselong) #:doc: - (a-350)/masterscale+baselong + a/masterscale+baselong end def y2lat(a)