Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide access to prj file #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/rgeo/shapefile/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down