Posted to osm@bynets by andrewsh at Thu Apr 15 07:26:49 GMT 2010view raw
- package require tdom
- if {[catch {package require know}]} {
- proc know {cond body} {
- if {![info complete $body]} {error "incomplete command(s) $body"}
- proc ::unknown {args} [string map [list @c@ $cond @b@ $body] {
- if {![catch {expr {@c@}} res eo] && $res} {
- return [eval {@b@}]
- }
- }][info body ::unknown]
- } ;# RS
- }
- # node:
- # attrs
- # lat
- # lon
- # version
- # ...
- # tags
- # tag value
- # tag value
- # ...
- # way:
- # attrs
- # version
- # changeset
- # ...
- # nodes
- # (list)
- # ref
- # tags
- # tag value
- # tag value
- # ...
- # relation:
- # attrs
- # version
- # changeset
- # ...
- # members
- # (list)
- # ref
- # type
- # role
- # tags
- # tag value
- # tag value
- # ...
- namespace eval osm::parser {
- variable tagstack {}
- variable parser
- variable nodes
- variable ways
- variable relations
- variable changesets
- variable id {}
- set parser [xml::parser]
- proc hs {name attlist} {
- variable tagstack
- variable id
- variable nodes
- variable ways
- variable relations
- # puts "hs: $tagstack"
- switch $name {
- node -
- way -
- relation {
- # puts "id, $name"
- set id [dict get $attlist id]
- set [set name]s($id) [dict create attrs [dict remove $attlist]]
- }
- tag {
- set type [lindex $tagstack end]
- # puts "tag, $type"
- switch $type {
- node -
- way -
- relation {
- # puts "dict set [set type]s($id) tags [dict get $attlist k] [dict get $attlist v]"
- dict set [set type]s($id) tags [dict get $attlist k] [dict get $attlist v]
- }
- default {puts $type}
- }
- }
- }
- lappend tagstack $name
- }
- proc he name {
- variable tagstack
- set tagstack [lreplace $tagstack[set tagstack ""] end end]
- }
- $parser configure -elementstartcommand hs -elementendcommand he
- proc parse xml {
- variable parser
- $parser parse $xml
- }
- proc unknown args {
- puts "unknown called: $args"
- }
- }
- set f [open /media/ntfs/q/minsk.osm r]
- set xml [read $f]
- close $f
- osm::parser::parse $xml
Comments
Posted by andrewsh at Thu Apr 15 07:28:18 GMT 2010 [text] [code]
ehm, why do I need "know"? that's not needed here!