class Ogrinfo2Migration
Constants
- RESERVED
- TYPES
Attributes
attributes[R]
info[R]
wkt[R]
Public Class Methods
new(file, outdir)
click to toggle source
# File lib/ogrinfo2migration.rb, line 21 def initialize(file, outdir) @outdir = outdir @info = %x(ogrinfo -so -al #{file}).split("\n") @info.shift(3) @attributes = @info.reduce(Hash.new(0)) do |memo, it| if it =~ /:/ && it !~ Regexp.new("(#{RESERVED.join("|")})") name, type = it.split(":") name = name.downcase.gsub(/ /,"_") type = type.gsub(/\([\d\.]+\)/,"").strip.downcase type = TYPES[type] ? TYPES[type] : type memo[name] = type end memo end end
Public Instance Methods
get_epsg()
click to toggle source
# File lib/ogrinfo2migration.rb, line 43 def get_epsg if wkt == "(unknown)" @epsg = nil return end j = JSON.parse(RestClient.get("http://prj2epsg.org/search.json?mode=wkt&terms=#{URI.encode(wkt)}")) if !j || (j['codes'] && j['codes'].length < 1) @epsg = nil return end @epsg = j['codes'][0]['code'] end
to_migration()
click to toggle source
# File lib/ogrinfo2migration.rb, line 56 def to_migration get_epsg migration = ERB.new(File.open("#{File.expand_path(File.dirname(__FILE__))}/tmpl.erb",'r').read).result(binding) File.open("#{@outdir}#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_add_#{@attributes["layer_name"]}.rb", "w") do |f| f.write migration end end