- # -- 4. get version by inserting new row into ways
-
- version=ActiveRecord::Base.connection.insert("INSERT INTO ways (id,user_id,timestamp,visible) VALUES (#{way},#{uid},#{db_now},1)")
-
- # -- 5. compare nodes and update xmin,xmax,ymin,ymax
-
- xmin = ymin = 999999
- xmax = ymax = -999999
- insertsql = ''
- renumberednodes={}
-
- points.each_index do |i|
- xs=coord2long(points[i][0],masterscale,baselong)
- ys=coord2lat(points[i][1],masterscale,basey)
- xmin=[xs,xmin].min; xmax=[xs,xmax].max
- ymin=[ys,ymin].min; ymax=[ys,ymax].max
- node=points[i][2].to_i
- tagstr=array2tag(points[i][4])
- tagstr=tagstr.gsub(/[\000-\037]/,"")
- tagsql="'"+sqlescape(tagstr)+"'"
-
- # compare node
- if node<0
- # new node - create
- newnode=ActiveRecord::Base.connection.insert("INSERT INTO current_nodes ( latitude,longitude,timestamp,user_id,visible,tags) VALUES ( #{ys},#{xs},#{db_now},#{uid},1,#{tagsql})")
- ActiveRecord::Base.connection.insert("INSERT INTO nodes (id,latitude,longitude,timestamp,user_id,visible,tags) VALUES (#{newnode},#{ys},#{xs},#{db_now},#{uid},1,#{tagsql})")
- points[i][2]=newnode
- renumberednodes[node.to_s]=newnode.to_s
-
- elsif xc.has_key?(node)
- # old node from original way - update
- if (xs!=xc[node] or (ys/0.0000001).round!=(yc[node]/0.0000001).round or tagstr!=tagc[node])
- ActiveRecord::Base.connection.insert("INSERT INTO nodes (id,latitude,longitude,timestamp,user_id,visible,tags) VALUES (#{node},#{ys},#{xs},#{db_now},#{uid},1,#{tagsql})")
- ActiveRecord::Base.connection.update("UPDATE current_nodes SET latitude=#{ys},longitude=#{xs},timestamp=#{db_now},user_id=#{uid},tags=#{tagsql},visible=1 WHERE id=#{node}")
- end
- else
- # old node, created in another way and now added to this way
- end
-
- end
-
-
- # -- 6.i compare segments
-
- numberedsegments={}
- seglist='' # list of existing segments that we want to keep
- for i in (0..(points.length-2))
- if (points[i+1][3].to_i==0) then next end
- segid=points[i+1][5].to_i
- from =points[i ][2].to_i
- to =points[i+1][2].to_i
- if seg.has_key?(segid)
- # if segment exists, check it still refers to the same nodes
- if seg[segid]=="#{from}-#{to}" then
- if (seglist!='') then seglist+=',' end; seglist+=segid.to_s
- next
- end
- elsif segid>0
- # not in previous version of way, but supplied, so assume
- # that it's come from makeway (i.e. unwayed segments)
- if (seglist!='') then seglist+=',' end; seglist+=segid.to_s
- next
- end
- segid=ActiveRecord::Base.connection.insert("INSERT INTO current_segments ( node_a,node_b,timestamp,user_id,visible,tags) VALUES ( #{from},#{to},#{db_now},#{uid},1,'')")
- ActiveRecord::Base.connection.insert("INSERT INTO segments (id,node_a,node_b,timestamp,user_id,visible,tags) VALUES (#{segid},#{from},#{to},#{db_now},#{uid},1,'')")
- points[i+1][5]=segid
- numberedsegments[(i+1).to_s]=segid.to_s
- end