[Openstreetmap-dev] CSV transport encoding scheme
David Sheldon
dave-osm at earth.li
Fri Jan 27 14:53:50 GMT 2006
On Fri, Jan 27, 2006 at 02:05:16PM +0000, SteveC wrote:
> * @ 26/01/06 11:50:51 PM dave-osm at earth.li wrote:
> > I think that this will be the solution to our speed problems for the
> > moment. Almost as fast as print, but with all the benefits of using an
> > XML library. Unfortunatly I don't think I will have time to work on it
> > before next Thursday, but if nobody else has worked on it, I will spend
> > some time towards the end of next week changing the current code to use
> > this.
>
> That'd be useful... actually, roll back imi's changes and update ox.rb
> and everything will use it.
Right, this was simpler than I expect.
I don't have a dev account or write access to the SVN, but attached is a
version that uses libxml. I'm sorry I haven't tested it, but I expect it
to work. Can someone give it a quick test, then apply it? The patch
needs to be applied in ruby/api
David
--
This communication is secured using Rot-26 Encryption Algorithm, Unauthorized
decryption will be subject to laughter.
-------------- next part --------------
Index: map.rb
===================================================================
--- map.rb (revision 823)
+++ map.rb (working copy)
@@ -8,7 +8,6 @@
include Apache
-include REXML
r = Apache.request
cgi = CGI.new
@@ -54,20 +53,10 @@
out = Zlib::GzipWriter.new $stdout
end
-#now send nodes first, segments after
-out.puts "<osm version='0.2'>"
if nodes
nodes.each do |i,n|
- if n.visible == true
- e = Element.new 'node'
- e.attributes['uid'] = n.id
- e.attributes['lat'] = n.latitude
- e.attributes['lon'] = n.longitude
- e.attributes['tags'] = n.tags
- e.write out
- out.puts "\n"
- end
+ ox.add_node(n) unless n.visible == false
end
end
@@ -78,19 +67,13 @@
node_b = nodes[l.node_b_id]
if node_a.visible ==true && node_b.visible == true
- e = Element.new 'segment'
- e.attributes['uid'] = l.id
- e.attributes['from'] = l.node_a_id
- e.attributes['to'] = l.node_b_id
- e.attributes['tags'] = l.tags
- e.write out
- out.puts "\n"
+ ox.add_segment(l)
end
end
end
-out.puts "</osm>"
+ox.dump(out)
GC.start
Index: osm/ox.rb
===================================================================
--- osm/ox.rb (revision 823)
+++ osm/ox.rb (working copy)
@@ -1,49 +1,45 @@
module OSM
- require 'rexml/document'
+require 'xml/libxml'
- #include REXML
-
class Ox # Ox == osm xml ? ugh
- include REXML
+ include XML
def initialize
- @root = Element.new 'osm'
- @root.attributes['version'] = '0.2'
+ @doc = Document.new
+ @root = Node.new 'osm'
+ @root['version'] = '0.2'
+ @doc.root = @root
end
def add_node(node)
- el1 = Element.new 'node'
- el1.attributes['uid'] = node.id
- el1.attributes['lat'] = node.latitude
- el1.attributes['lon'] = node.longitude
- el1.attributes['tags'] = node.tags
- @root.add el1
+ el1 = Node.new 'node'
+ el1['uid'] = node.id
+ el1['lat'] = node.latitude
+ el1['lon'] = node.longitude
+ el1['tags'] = node.tags
+ @root << el1
end
def add_segment(line)
- el1 = Element.new('segment')
+ el1 = Node.new('segment')
- el1.attributes['uid'] = line.id
- el1.attributes['from'] = line.node_a_id
- el1.attributes['to'] = line.node_b_id
- el1.attributes['tags'] = line.tags
+ el1['uid'] = line.id
+ el1['from'] = line.node_a_id
+ el1['to'] = line.node_b_id
+ el1['tags'] = line.tags
- @root.add el1
+ @root << el1
end
def to_s
- return @root.to_s
+ return @doc.to_s
end
- def to_s_pretty
- hum = ''
+ def dump(out)
+ @doc.dump(out)
- @root.write(hum, 0)
- return hum
- end
-
end
More information about the dev
mailing list