Created
October 4, 2012 12:36
-
-
Save stuartc/3833296 to your computer and use it in GitHub Desktop.
Convert CSV to KML file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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