diff --git a/lib/geo_ruby/shp4r/dbf.rb b/lib/geo_ruby/shp4r/dbf.rb
index 976c595..79dd361 100644
--- a/lib/geo_ruby/shp4r/dbf.rb
+++ b/lib/geo_ruby/shp4r/dbf.rb
@@ -20,7 +20,7 @@ def [](v)
end
end
- class Field < Column::Base
+ class Field < ColumnType::Base
def initialize(name, type, length, decimal = 0, version = 1, enc = nil)
super(name, type, length, decimal, version, enc)
end
@@ -33,8 +33,10 @@ def header_length
@columns_count
end
- def self.open(f)
- new(f)
+ # Open DBF with specified encoding (it can also be nil and DBF reader
+ # will use what it finds in header).
+ def self.open(f, memo = nil, encoding)
+ new(f, memo, encoding)
end
def close
diff --git a/lib/geo_ruby/shp4r/shp.rb b/lib/geo_ruby/shp4r/shp.rb
index 1c6042c..27a867e 100644
--- a/lib/geo_ruby/shp4r/shp.rb
+++ b/lib/geo_ruby/shp4r/shp.rb
@@ -31,7 +31,7 @@ class ShpFile
# Opens a SHP file. Both "abc.shp" and "abc" are accepted.
# The files "abc.shp", "abc.shx" and "abc.dbf" must be present
- def initialize(file)
+ def initialize(file, dbf_encoding)
# strip the shp out of the file if present
@file_root = file.gsub(/.shp$/i, '')
# check existence of shp, dbf and shx files
@@ -41,7 +41,7 @@ def initialize(file)
fail MalformedShpException.new("Missing one of shp, dbf or shx for: #{@file}")
end
- @dbf = Dbf::Reader.open(@file_root + '.dbf')
+ @dbf = Dbf::Reader.open(@file_root + '.dbf', nil, dbf_encoding)
@shx = File.open(@file_root + '.shx', 'rb')
@shp = File.open(@file_root + '.shp', 'rb')
read_index
@@ -56,8 +56,10 @@ def reload!
# opens a SHP "file". If a block is given, the ShpFile object
# is yielded to it and is closed upon return.
# Else a call to open is equivalent to ShpFile.new(...).
- def self.open(file)
- shpfile = ShpFile.new(file)
+ # You can specify encoding of the table, by default it is not set, maybe
+ # it should be UTF-8?
+ def self.open(file, dbf_encoding = nil)
+ shpfile = ShpFile.new(file, dbf_encoding)
if block_given?
yield shpfile
shpfile.close