Skip to content

Instantly share code, notes, and snippets.

@stuartc
Created October 4, 2012 12:36
Show Gist options
  • Save stuartc/3833296 to your computer and use it in GitHub Desktop.
Save stuartc/3833296 to your computer and use it in GitHub Desktop.
Convert CSV to KML file
file = File.open(File.expand_path("~/Desktop/output.kml"), "w")
file.write <<-EOL
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
EOL
CSV.foreach(File.expand_path('~/Desktop/***.csv'), col_sep: ";", headers: true) do |row|
file.write <<-EOL
<Placemark>
<name>#{row["Name"]}</name>
<Point>
<coordinates>#{row["Longitude"]},#{row["Latitude"]},0</coordinates>
</Point>
</Placemark>
EOL
end
file.write <<-EOL
</Document>
</kml>
EOL
file.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment