LoginSignup
2
2

More than 5 years have passed since last update.

基盤地図情報(数値標高モデル)(5mメッシュ(標高))の変換にXML処理を使うのは間違っている感じ

Posted at

基盤地図情報(数値標高モデル)(5mメッシュ(標高))の変換にSAX(nokogiri)を使ってみたが、作ってみて分かったのだが、非本質的な処理になっている感じがあって、メリットがない。

SAXの設計もRubyの大クラス主義に合わない感じがするし、結局、ファイル名とtupleListのカンマ区切り値くらいしか取るべき情報はない。gml:Envelope の数値の打ち切りがおかしくて、これを取らずメッシュ名を取る方がよいと思ったことが、メリットがないと考えた一番の引き金である。

なので、単純なテキスト処理でコンバータを作るのが正しいと思った。nokogiri で作りかけたスクリプトを、記録のためにここにおいておく。

require 'nokogiri'

class DEM5A2CSV < Nokogiri::XML::SAX::Document
  def start_element(name, attrs)
    @buf = ''
  end

  def characters(s)
    @buf += s
  end

  def end_element(name)
    if name == 'gml:tupleList'
      @tupleList = @buf
    end
    @buf = ''
  end

  def end_document
    print <<-EOS
tupleList: #{@tupleList}
    EOS
  end
end

parser = Nokogiri::XML::SAX::Parser.new(DEM5A2CSV.new)
ARGV.each{|fn|
  parser.parse(File.open(ARGV[0]))
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2