Ruby: KML Library?

梦想与她 提交于 2019-12-12 08:01:38

问题


I am searching for a ruby library to export location data into KML files. The data to be exported contains mainly simple points with latitude and longitude, but I'd also like to be able to export more complex polygons.

I tried kamelopard, but didn't find it satisfactory as it is missing a tutorial. It wasn't obvious to me where to start using the library. There is another candidate which is called kamel. Unfortunately I couldn't install that one, due to a missing dependency which I couldn't resolve.

So, which library are you using to create a KML file programmatically in Ruby? Or do you use the builder gem and create the XML yourself?


回答1:


I solved my problem by using schleyfox-ruby_kml, which is a fork of kmlr. With this, it is easy to generate a kml for a set of placemarks. See the following example from the README:

require 'kml'

kml = KMLFile.new
folder = KML::Folder.new(:name => 'Melbourne Stations')
[
  ["Flinders St",    -37.818078, 144.966811],
  ["Southern Cross", -37.818358, 144.952417],
].each do |name, lat, lng|
  folder.features << KML::Placemark.new(
    :name => name, 
    :geometry => KML::Point.new(:coordinates => {:lat => lat, :lng => lng})
  )
end
kml.objects << folder
puts kml.render

The gem also provides classes to generate polygons and so forth.



来源:https://stackoverflow.com/questions/8168649/ruby-kml-library

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!