#!/usr/bin/ruby require 'OSM/StreamParser' PI = 3.14159265358979323846; $waynodes={} $lat={} $lon={} $count={} $ways=[] def lon_to_m(lon) return 20037508.34 * lon.to_f / 180; end def lat_to_m(lat) xlat = Math.log(Math.tan( (90 + lat.to_f) * PI / 360)) / (PI / 180); return 20037508.34 * xlat / 180; #/ end class NodeCallbacks < OSM::Callbacks def node(obj) #puts obj.religion if obj.religion if $waynodes[obj.id.to_s] #puts obj.id $lon[$waynodes[obj.id.to_s].to_s]+=obj.lon.to_f $lat[$waynodes[obj.id.to_s].to_s]+=obj.lat.to_f $count[$waynodes[obj.id.to_s].to_s]+=1 elsif obj.man_made == "surveillance" puts lat_to_m(obj.lat).to_i.to_s+","+lon_to_m(obj.lon).to_i.to_s+"\tCCTV\tSurveillance Camera\tcctv.png\t16,16\t-8,-8" $stdout.flush elsif obj.natural_protection == "natural_monument" puts lat_to_m(obj.lat).to_i.to_s+","+lon_to_m(obj.lon).to_i.to_s+"\tNaturdenkmal\tNaturdenkmal\tnaturdenkmal.png\t16,16\t-8,-8" $stdout.flush end end end class WayCallbacks < OSM::Callbacks def way(obj) if obj.natural_protection == "natural_monument" $lon[obj.id.to_s]=0 $lat[obj.id.to_s]=0 $count[obj.id.to_s]=0 $ways+=[obj.id] obj.nodes.each { |nodeid| $waynodes[nodeid] = obj.id } # lon/=i # lat/=i # puts lat_to_m(lat).to_i.to_s+","+lon_to_m(lon).to_i.to_s+"\tNaturdenkmal\tNaturdenkmal\tnaturdenkmal.png\t16,16\t-8,-8" # $stdout.flush end end # def relation(obj) # end end if !ARGV[0] puts("Need osm file as commandline argument.") exit(1) end #db = OSM::Database.new wcb = WayCallbacks.new wayparser = OSM::StreamParser.new(:filename => ARGV[0], :callbacks => wcb) wayparser.parse ncb = NodeCallbacks.new nodeparser = OSM::StreamParser.new(:filename => ARGV[0], :callbacks => ncb) nodeparser.parse $ways.each { |wayid| mlon=lon_to_m($lon[wayid.to_s]/$count[wayid.to_s]) mlat=lat_to_m($lat[wayid.to_s]/$count[wayid.to_s]) puts mlat.to_i.to_s+","+mlon.to_i.to_s+"\tNaturdenkmal\tNaturdenkmal\tnaturdenkmal.png\t16,16\t-8,-8" } #puts $waynodes