使用ruby_kml将CSV转换为KML

时间:2016-01-12 16:13:50

标签: csv kml

我遇到的问题是使用CSV文件中的ruby_kml创建KML,以便我可以使用gmaps4rails提供的addKML()或addKMLLayer()方法。我无法使语法有意义。在api示例中,它明确地列出了这样的点       [ “$ 26A8”,3023.1214,9744.5808],
      [ “$ 26A9”,3023.0842,9744.6805],
      [“$ 26AA”,3022.9717,9744.5025],

我的目标是让它读取CSV的每一行并将该数据用于kml。这是我尝试解决方案。

def kml 
    require 'csv'
    require 'ruby_kml'
    curPoints = CSV.read('/postCSV/cur.csv'); # most recent upload
    kml = KMLFILE.new
    folder = KML::Folder.new(:name => 'ready')
    [
      **curPoints.each do |row|
        [row[0],row[1],row[3]]
      end** #data is in 0,1,3 
      # this shouldn't work because the loop isn't doing anything
      # I just don't see how to get it to match the example code     
        #for loop through row delimitating by name, lat, lng
    ].each do |name, lat, lng|
    folder.features << KML::Placemark.new(
      :name => name,
      :gemoetry => KML::Point.new(:coordinates => {:lat => lat, :lng => lng})
    )
    end
      kml.objects << folder
      @kml = kml.render
      return kml
    end

0 个答案:

没有答案