Skip to content

Instantly share code, notes, and snippets.

@hiro88hyo
Created September 8, 2015 02:58
Show Gist options
  • Save hiro88hyo/2e7be3353dc13dfb3d7f to your computer and use it in GitHub Desktop.
Save hiro88hyo/2e7be3353dc13dfb3d7f to your computer and use it in GitHub Desktop.
convert csv to kml
# 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(/[<>&"']/,"<" => "&lt;", ">" => "&gt;", "&" => "&amp;", '"' => "&quot;", "'" => "&apos;)
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(/[<>&"']/,"<" => "&lt;", ">" => "&gt;", "&" => "&amp;", "\"" => "&quot;", "'" => "&apos;")
@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