Skip to content

Instantly share code, notes, and snippets.

@nwjsmith
Created May 4, 2011 19:52
Show Gist options
  • Save nwjsmith/955893 to your computer and use it in GitHub Desktop.
Save nwjsmith/955893 to your computer and use it in GitHub Desktop.
require 'nokogiri'
require 'yaml'
kml_path = File.join(File.dirname(__FILE__), 'FloodLine_x5.kml')
File.open(kml_path) do |f|
kml = Nokogiri::XML(f)
kml.xpath('//ns:MultiGeometry', {'ns' => "http://www.opengis.net/kml/2.2"}).each do |polygon|
escaped_geometry = con.escape_string(polygon.to_s)
con.exec "INSERT INTO flood_zones VALUES( ST_GEOMFROMKML('#{escaped_geometry}') )"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment