Sha256: bbad05463d3cdca915a9add9628c5af2c9b89f6a8d3139c36a7b1a51c87b873f
Contents?: true
Size: 806 Bytes
Versions: 25
Compression:
Stored size: 806 Bytes
Contents
require 'ostruct' module SpatialFeatures module Importers class KML < Base private def each_record(&block) Nokogiri::XML(@data).css('Placemark').each do |placemark| name = placemark.css('name').text metadata = {:description => placemark.css('description').text} {'Polygon' => 'POLYGON', 'LineString' => 'LINE', 'Point' => 'POINT'}.each do |kml_type, sql_type| placemark.css(kml_type).each do |placemark| yield OpenStruct.new(:feature_type => sql_type, :geog => geom_from_kml(placemark), :name => name, :metadata => metadata) end end end end def geom_from_kml(kml) ActiveRecord::Base.connection.select_value("SELECT ST_GeomFromKML('#{kml}')") end end end end
Version data entries
25 entries across 25 versions & 1 rubygems