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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With