Created
July 7, 2009 23:13
-
-
Save jberkel/142435 to your computer and use it in GitHub Desktop.
shapefile 2 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'kml' | |
require 'shapelib' | |
include ShapeLib | |
raise "#{$0} <filename>" if ARGV.empty? | |
shapes = [] | |
ShapeFile.open(ARGV[0]) do |f| | |
f.each { |s| shapes << s } | |
end | |
kml = KMLFile.new | |
folder = KML::Folder.new(:name=>'test') | |
shapes.each do |s| | |
s.xvals.zip(s.yvals).each_with_index do |(x,y), i| | |
folder.features << KML::Placemark.new( | |
:name => "name:#{i}", | |
:geometry => KML::Point.new(:coordinates => {:lat => y, :lng => x})) | |
end | |
end | |
kml.objects << folder | |
puts kml.render |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment