From a5d2b1e93d12f6f9e0a7562406735aec5e9e637f Mon Sep 17 00:00:00 2001 From: Tomasz Pajor Date: Thu, 11 May 2017 11:29:28 +0200 Subject: [PATCH] provide access to prj file --- lib/rgeo/shapefile/reader.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/rgeo/shapefile/reader.rb b/lib/rgeo/shapefile/reader.rb index fedb579..0c34e23 100644 --- a/lib/rgeo/shapefile/reader.rb +++ b/lib/rgeo/shapefile/reader.rb @@ -181,6 +181,9 @@ def initialize(path_, opts_ = {}) # :nodoc: @attr_dbf = if ::File.file?(path_ + ".dbf") && ::File.readable?(path_ + ".dbf") ::DBF::Table.new(path_ + ".dbf") end + @prj_file = if ::File.file?(path_+'.prj') && ::File.readable?(path_ + '.prj') + ::File.open(path_+'.prj', 'rb:ascii-8bit') + end @main_length, @shape_type_code, @xmin, @ymin, @xmax, @ymax, @zmin, @zmax, @mmin, @mmax = @main_file.read(100).unpack("x24Nx4VE8") @main_length *= 2 index_length_ = @index_file.read(100).unpack("x24Nx72").first @@ -232,6 +235,7 @@ def close @main_file.close @index_file.close @attr_dbf.close if @attr_dbf + @prj_file.close if @prj_file @opened = false end @@ -370,6 +374,10 @@ def get(index_) end alias [] get + def prj + @opened && @prj_file ? @prj_file.read : nil + end + def _read_next_record # :nodoc: length_ = @main_file.read(8).unpack("NN")[1] data_ = @main_file.read(length_ * 2)