Skip to content

Instantly share code, notes, and snippets.

@jberkel
Created July 7, 2009 23:13
Show Gist options
  • Save jberkel/142435 to your computer and use it in GitHub Desktop.
Save jberkel/142435 to your computer and use it in GitHub Desktop.
shapefile 2 kml
#!/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