Created
September 8, 2015 02:58
-
-
Save hiro88hyo/2e7be3353dc13dfb3d7f to your computer and use it in GitHub Desktop.
convert csv to kml
This file contains hidden or 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
# coding: utf-8 | |
require 'rubygems' | |
require 'pr_geohash' | |
require 'kconv' | |
i = 0 | |
puts <<KML | |
<?xml version='1.0' encoding='UTF-8'?> | |
<kml xmlns='http://www.opengis.net/kml/2.2'> | |
<Document> | |
<name></name> | |
KML | |
# gsub(/[<>&"']/,"<" => "<", ">" => ">", "&" => "&", '"' => """, "'" => "') | |
open(ARGV[0],"r:utf-8"){|f| | |
while l = f.gets | |
i = i + 1 | |
row = l.split("\t") | |
# @area = row[0] | |
@name = row[1].gsub(/[<>&"']/,"<" => "<", ">" => ">", "&" => "&", "\"" => """, "'" => "'") | |
@image = row[5] | |
@lon = row[5].to_f | |
@lat = row[3].to_f | |
kml = " <Placemark>" | |
kml += " <styleUrl>#icon-1219</styleUrl>" | |
kml += " <name>#{@name}</name>" | |
kml += " <Point>" | |
kml +=" <coordinates>#{@lon},#{@lat},0.0</coordinates>" | |
kml += " </Point>" | |
kml += " </Placemark>" | |
puts kml | |
end | |
} | |
puts <<KML | |
<Style id='icon-1219'> | |
<IconStyle> | |
<scale>1.1</scale> | |
<Icon> | |
<href>.png</href> | |
</Icon> | |
</IconStyle> | |
</Style> | |
</Document> | |
</kml> | |
KML |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment