esri_shapefile 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/lib/esri_shapefile/byte_model/field.rb +48 -0
- data/lib/esri_shapefile/byte_model.rb +43 -0
- data/lib/esri_shapefile/models/main_file_header.rb +47 -0
- data/lib/esri_shapefile/models/record_header.rb +28 -0
- data/lib/esri_shapefile/models/shapes/multi_patch.rb +33 -0
- data/lib/esri_shapefile/models/shapes/multi_point.rb +21 -0
- data/lib/esri_shapefile/models/shapes/multi_point_m.rb +25 -0
- data/lib/esri_shapefile/models/shapes/multi_point_z.rb +29 -0
- data/lib/esri_shapefile/models/shapes/null.rb +19 -0
- data/lib/esri_shapefile/models/shapes/point.rb +19 -0
- data/lib/esri_shapefile/models/shapes/point_m.rb +20 -0
- data/lib/esri_shapefile/models/shapes/point_z.rb +21 -0
- data/lib/esri_shapefile/models/shapes/poly_line.rb +43 -0
- data/lib/esri_shapefile/models/shapes/poly_line_m.rb +50 -0
- data/lib/esri_shapefile/models/shapes/poly_line_z.rb +63 -0
- data/lib/esri_shapefile/models/shapes/polygon.rb +38 -0
- data/lib/esri_shapefile/models/shapes/polygon_m.rb +52 -0
- data/lib/esri_shapefile/models/shapes/polygon_z.rb +65 -0
- data/lib/esri_shapefile/models/shapes.rb +33 -0
- data/lib/esri_shapefile/reader.rb +44 -0
- data/lib/esri_shapefile/version.rb +3 -0
- data/lib/esri_shapefile.rb +29 -0
- data/spec/esri_shapefile/field_spec.rb +95 -0
- data/spec/esri_shapefile/model_spec.rb +26 -0
- data/spec/esri_shapefile/models/main_file_header_spec.rb +72 -0
- data/spec/esri_shapefile/models/record_header_spec.rb +26 -0
- data/spec/esri_shapefile/models/shapes/point_spec.rb +24 -0
- data/spec/spec_helper.rb +105 -0
- metadata +123 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'esri_shapefile/byte_model'
|
2
|
+
|
3
|
+
module EsriShapefile
|
4
|
+
module Shapes
|
5
|
+
#
|
6
|
+
# A PolygonM consists of a number of rings. A ring is a closed,
|
7
|
+
# non-self-intersecting loop. A PolygonZ may contain multiple outer rings.
|
8
|
+
# The rings of a PolygonZ are referred to as its parts.
|
9
|
+
#
|
10
|
+
# The PolygonM structure is identical to the PolyLineM structure
|
11
|
+
#
|
12
|
+
class PolygonM
|
13
|
+
extend EsriShapefile::ByteModel
|
14
|
+
|
15
|
+
field :shape_type, position: 0, type: :integer, byte_order: :little
|
16
|
+
field :x_min, position: 4, type: :double, byte_order: :little
|
17
|
+
field :y_min, position: 12, type: :double, byte_order: :little
|
18
|
+
field :x_max, position: 20, type: :double, byte_order: :little
|
19
|
+
field :y_max, position: 28, type: :double, byte_order: :little
|
20
|
+
|
21
|
+
# The number of parts in the PolyLine
|
22
|
+
field :num_parts, position: 36, type: :integer, byte_order: :little
|
23
|
+
|
24
|
+
# The total number of points for all parts.
|
25
|
+
field :num_points, position: 40, type: :integer, byte_order: :little
|
26
|
+
|
27
|
+
# An array of length num_parts. Stores, for each PolyLine, the index of
|
28
|
+
# its first point in the points array. Array indexes are with respect to 0.
|
29
|
+
field :parts, position: 44, type: :integer, byte_order: :little, number: :num_parts
|
30
|
+
|
31
|
+
# An array of length NumPoints. The points for each part in the PolyLine
|
32
|
+
# are stored end to end. The points for Part 2 follow the points for
|
33
|
+
# Part 1, and so on. The parts array holds the array index of the starting
|
34
|
+
# point for each part. There is no delimiter in the points array between parts.
|
35
|
+
field :points, position: :x, type: :point, byte_order: :little, number: :num_points
|
36
|
+
|
37
|
+
# The minimum measure for the PolyLineZ
|
38
|
+
field :m_min, position: :z, type: :double, byte_order: :little
|
39
|
+
|
40
|
+
# The maximum measure for the PolyLineZ
|
41
|
+
field :m_max, position: :z_plus_8, type: :double, byte_order: :little
|
42
|
+
|
43
|
+
# An array of length num_points. The measures for each part in the
|
44
|
+
# PolyLineZ are stored end to end. The measures for Part 2 follow the
|
45
|
+
# measures for Part 1, and so on. The parts array holds the array index of
|
46
|
+
# the starting measure for each part. There is no delimited in the measure
|
47
|
+
# array between parts.
|
48
|
+
field :m_array, position: :z_plus_16, type: :double, byte_order: :little, number: :num_points
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'esri_shapefile/byte_model'
|
2
|
+
|
3
|
+
module EsriShapefile
|
4
|
+
module Shapes
|
5
|
+
#
|
6
|
+
# A PolygonZ consists of a number of rings. A ring is a closed,
|
7
|
+
# non-self-intersecting loop. A PolygonZ may contain multiple outer rings.
|
8
|
+
# The rings of a PolygonZ are referred to as its parts.
|
9
|
+
#
|
10
|
+
# The PolygonZ structure is identical to the PolyLineZ structure
|
11
|
+
#
|
12
|
+
class PolygonZ
|
13
|
+
extend EsriShapefile::ByteModel
|
14
|
+
|
15
|
+
field :shape_type, position: 0, type: :integer, byte_order: :little
|
16
|
+
field :x_min, position: 4, type: :double, byte_order: :little
|
17
|
+
field :y_min, position: 12, type: :double, byte_order: :little
|
18
|
+
field :x_max, position: 20, type: :double, byte_order: :little
|
19
|
+
field :y_max, position: 28, type: :double, byte_order: :little
|
20
|
+
|
21
|
+
# The number of parts in the PolyLine
|
22
|
+
field :num_parts, position: 36, type: :integer, byte_order: :little
|
23
|
+
|
24
|
+
# The total number of points for all parts.
|
25
|
+
field :num_points, position: 40, type: :integer, byte_order: :little
|
26
|
+
|
27
|
+
# An array of length num_parts. Stores, for each PolyLine, the index of
|
28
|
+
# its first point in the points array. Array indexes are with respect to 0.
|
29
|
+
field :parts, position: 44, type: :integer, byte_order: :little, number: :num_parts
|
30
|
+
|
31
|
+
# An array of length NumPoints. The points for each part in the PolyLine
|
32
|
+
# are stored end to end. The points for Part 2 follow the points for
|
33
|
+
# Part 1, and so on. The parts array holds the array index of the starting
|
34
|
+
# point for each part. There is no delimiter in the points array between parts.
|
35
|
+
field :points, position: :x, type: :point, byte_order: :little, number: :num_points
|
36
|
+
|
37
|
+
# The minimum Z value for the PolyLineZ
|
38
|
+
field :z_min, position: :y, type: :double, byte_order: :little
|
39
|
+
|
40
|
+
# The maximum Z value for the PoliyLineZ
|
41
|
+
field :z_max, position: :y_plus_8, type: :double, byte_order: :little
|
42
|
+
|
43
|
+
# An array of length num_points. the Z values for each part in the
|
44
|
+
# PolyLineZ are stored end to end. The Z values for Part 2 follow the Z
|
45
|
+
# values for Part 1, and so on. The parts array holds the array index of
|
46
|
+
# the starting point for each part. There is no delimited in the Z array
|
47
|
+
# between parts.
|
48
|
+
field :z_array, position: :y_plus_16, type: :double, byte_order: :little, number: :num_points
|
49
|
+
|
50
|
+
# The minimum measure for the PolyLineZ
|
51
|
+
field :m_min, position: :z, type: :double, byte_order: :little
|
52
|
+
|
53
|
+
# The maximum measure for the PolyLineZ
|
54
|
+
field :m_max, position: :z_plus_8, type: :double, byte_order: :little
|
55
|
+
|
56
|
+
# An array of length num_points. The measures for each part in the
|
57
|
+
# PolyLineZ are stored end to end. The measures for Part 2 follow the
|
58
|
+
# measures for Part 1, and so on. The parts array holds the array index of
|
59
|
+
# the starting measure for each part. There is no delimited in the measure
|
60
|
+
# array between parts.
|
61
|
+
field :m_array, position: :z_plus_16, type: :double, byte_order: :little, number: :num_points
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module EsriShapefile
|
2
|
+
module Shapes
|
3
|
+
|
4
|
+
# Shape types not specified below (2, 4, 6, etc., and up to 33) are
|
5
|
+
# reserved for future use
|
6
|
+
SHAPES = {
|
7
|
+
0 => Shapes::Null,
|
8
|
+
1 => Shapes::Point,
|
9
|
+
3 => Shapes::PolyLine,
|
10
|
+
5 => Shapes::Polygon,
|
11
|
+
8 => Shapes::MultiPoint,
|
12
|
+
11 => Shapes::PointZ,
|
13
|
+
13 => Shapes::PolyLineZ,
|
14
|
+
15 => Shapes::PolygonZ,
|
15
|
+
18 => Shapes::MultiPointZ,
|
16
|
+
21 => Shapes::PointM,
|
17
|
+
23 => Shapes::PolyLineM,
|
18
|
+
25 => Shapes::PolygonM,
|
19
|
+
28 => Shapes::MultiPointM,
|
20
|
+
31 => Shapes::MultiPatch,
|
21
|
+
}
|
22
|
+
|
23
|
+
def self.find_by_type(shape_type)
|
24
|
+
SHAPES.fetch(shape_type)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.find_by_bytes(bytes)
|
28
|
+
shape_type = bytes.unpack('l<').first
|
29
|
+
find_by_type(shape_type)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module EsriShapefile
|
2
|
+
class Reader
|
3
|
+
|
4
|
+
MAIN_FILE_HEADER_BYTESIZE = 100
|
5
|
+
RECORD_HEADER_BYTESIZE = 8
|
6
|
+
|
7
|
+
attr_reader :main_file_header
|
8
|
+
|
9
|
+
def initialize(path_to_shapefile)
|
10
|
+
@path_to_shapefile = path_to_shapefile
|
11
|
+
@main_file_header = parse_main_file_header
|
12
|
+
end
|
13
|
+
|
14
|
+
def each_record
|
15
|
+
File.open(@path_to_shapefile) do |file|
|
16
|
+
file.pos = MAIN_FILE_HEADER_BYTESIZE
|
17
|
+
|
18
|
+
(0..Float::INFINITY).lazy.reduce(file.pos) do |current_offset, number|
|
19
|
+
break if current_offset >= main_file_header.file_length_bytes
|
20
|
+
|
21
|
+
record_header_bytes = file.read(RECORD_HEADER_BYTESIZE)
|
22
|
+
record_header = RecordHeader.from_bytes(record_header_bytes)
|
23
|
+
|
24
|
+
shape_bytes = file.read(record_header.content_length_bytes)
|
25
|
+
shape_class = Shapes.find_by_bytes(shape_bytes)
|
26
|
+
shape = shape_class.from_bytes(shape_bytes)
|
27
|
+
|
28
|
+
yield record_header, shape
|
29
|
+
|
30
|
+
file.pos
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def parse_main_file_header
|
38
|
+
main_file_header_bytes = File.binread(@path_to_shapefile, 100, 0)
|
39
|
+
MainFileHeader.from_bytes(main_file_header_bytes)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "esri_shapefile/version"
|
2
|
+
require "esri_shapefile/byte_model"
|
3
|
+
require "esri_shapefile/byte_model/field"
|
4
|
+
|
5
|
+
require "esri_shapefile/models/shapes/null"
|
6
|
+
require "esri_shapefile/models/shapes/point"
|
7
|
+
require "esri_shapefile/models/shapes/point_m"
|
8
|
+
require "esri_shapefile/models/shapes/point_z"
|
9
|
+
require "esri_shapefile/models/shapes/multi_point"
|
10
|
+
require "esri_shapefile/models/shapes/multi_point_m"
|
11
|
+
require "esri_shapefile/models/shapes/multi_point_z"
|
12
|
+
require "esri_shapefile/models/shapes/poly_line"
|
13
|
+
require "esri_shapefile/models/shapes/poly_line_m"
|
14
|
+
require "esri_shapefile/models/shapes/poly_line_z"
|
15
|
+
require "esri_shapefile/models/shapes/polygon"
|
16
|
+
require "esri_shapefile/models/shapes/polygon_m"
|
17
|
+
require "esri_shapefile/models/shapes/polygon_z"
|
18
|
+
require "esri_shapefile/models/shapes/multi_patch"
|
19
|
+
require "esri_shapefile/models/shapes"
|
20
|
+
|
21
|
+
require "esri_shapefile/models/main_file_header"
|
22
|
+
require "esri_shapefile/models/record_header"
|
23
|
+
|
24
|
+
require "esri_shapefile/reader"
|
25
|
+
|
26
|
+
module EsriShapefile
|
27
|
+
# Your code goes here...
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module EsriShapefile
|
4
|
+
module ByteModel
|
5
|
+
describe Field do
|
6
|
+
|
7
|
+
describe "type" do
|
8
|
+
describe "integer" do
|
9
|
+
it "has a bytesize of 4" do
|
10
|
+
integer_field = Field.new(:integer_field, type: :integer, byte_order: :little, position: 0)
|
11
|
+
expect(integer_field.bytesize).to eql(4)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "correctly identifies the unpack format for the little byte order" do
|
15
|
+
integer_field = Field.new(:integer_field, type: :integer, byte_order: :little, position: 0)
|
16
|
+
expect(integer_field.unpack_format).to eql('l<1')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "correctly identifies the unpack format for the big byte order" do
|
20
|
+
integer_field = Field.new(:integer_field, type: :integer, byte_order: :big, position: 0)
|
21
|
+
expect(integer_field.unpack_format).to eql('l>1')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "double" do
|
26
|
+
it "has a bytesize of 8" do
|
27
|
+
integer_field = Field.new(:integer_field, type: :double, byte_order: :little, position: 0)
|
28
|
+
expect(integer_field.bytesize).to eql(8)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "correctly identifies the unpack format for the little byte order" do
|
32
|
+
integer_field = Field.new(:integer_field, type: :double, byte_order: :little, position: 0)
|
33
|
+
expect(integer_field.unpack_format).to eql('E1')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "correctly identifies the unpack format for the big byte order" do
|
37
|
+
integer_field = Field.new(:integer_field, type: :double, byte_order: :big, position: 0)
|
38
|
+
expect(integer_field.unpack_format).to eql('G1')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "point" do
|
43
|
+
it "has a bytesize of 16" do
|
44
|
+
integer_field = Field.new(:integer_field, type: :point, byte_order: :little, position: 0)
|
45
|
+
expect(integer_field.bytesize).to eql(16)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "correctly identifies the unpack format for the little byte order" do
|
49
|
+
integer_field = Field.new(:integer_field, type: :point, byte_order: :little, position: 0)
|
50
|
+
expect(integer_field.unpack_format).to eql('E2')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "correctly identifies the unpack format for the big byte order" do
|
54
|
+
integer_field = Field.new(:integer_field, type: :point, byte_order: :big, position: 0)
|
55
|
+
expect(integer_field.unpack_format).to eql('G2')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "list" do
|
61
|
+
it "is a list when a number is provided" do
|
62
|
+
field = Field.new(:field, number: 0, type: :point, byte_order: :big, position: 0)
|
63
|
+
expect(field).to be_a_list
|
64
|
+
end
|
65
|
+
|
66
|
+
it "is NOT a list when a number is NOT provided" do
|
67
|
+
field = Field.new(:field, type: :point, byte_order: :big, position: 0)
|
68
|
+
expect(field).to_not be_a_list
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "number attribute" do
|
73
|
+
it "is optional" do
|
74
|
+
field = Field.new(:field_without_number, type: :double, byte_order: :little, position: 0)
|
75
|
+
expect(field.number).to eql(1)
|
76
|
+
expect(field).to_not be_number_depends_on_field
|
77
|
+
end
|
78
|
+
|
79
|
+
it "can be an integer" do
|
80
|
+
field = Field.new(:field_with_number, number: 42, type: :double, byte_order: :little, position: 0)
|
81
|
+
expect(field.number).to eql(42)
|
82
|
+
expect(field).to_not be_number_depends_on_field
|
83
|
+
end
|
84
|
+
|
85
|
+
it "can depend upon the value of another field" do
|
86
|
+
field = Field.new(:field_with_depended_number, number: :num_foo, type: :double, byte_order: :little, position: 0)
|
87
|
+
expect(field.number).to eql(:num_foo)
|
88
|
+
expect(field).to be_number_depends_on_field
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EsriShapefile::ByteModel do
|
4
|
+
|
5
|
+
describe "declaring fields" do
|
6
|
+
let(:example_model) do
|
7
|
+
Class.new do
|
8
|
+
extend EsriShapefile::ByteModel
|
9
|
+
field :foo, position: 0, type: :integer, byte_order: :little
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "allows them to be accessed" do
|
14
|
+
model = example_model.new
|
15
|
+
model.foo = "Bar"
|
16
|
+
|
17
|
+
expect(model.foo).to eql("Bar")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "adds them to the list of fields" do
|
21
|
+
expect(example_model.fields.size).to eql(1)
|
22
|
+
expect(example_model.fields.first.name).to eql(:foo)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module EsriShapefile
|
4
|
+
describe MainFileHeader do
|
5
|
+
|
6
|
+
let(:main_file_header_bytes) do
|
7
|
+
bytes = "\x00\x00'\n\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
8
|
+
bytes << "\x00\x00\x00\x00\x00\x00\x00\x01|\xD2t\xE8\x03\x00\x00\x05\x00"
|
9
|
+
bytes << "\x00\x00\xFA\xD6`\x02\xB7df\xC0\x80\xEC\xBCA?\xE92@\x12\x9A\xE3N"
|
10
|
+
bytes << "\xE9xf@\xF2\xB4\x02\xD3\xE8\xD8Q@\x00\x00\x00\x00\x00\x00\x00\x00"
|
11
|
+
bytes << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
12
|
+
bytes << "\x00\x00\x00\x00\x00\x00\x00\x00"
|
13
|
+
bytes
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "from_bytes" do
|
17
|
+
let(:main_file_header) do
|
18
|
+
MainFileHeader.from_bytes(main_file_header_bytes)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets the file code" do
|
22
|
+
expect(main_file_header.file_code).to eql(9994)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets the file length" do
|
26
|
+
expect(main_file_header.file_length).to eql(24957556)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets the version" do
|
30
|
+
expect(main_file_header.version).to eql(1000)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "sets the shape type" do
|
34
|
+
expect(main_file_header.shape_type).to eql(5)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "sets the x_min" do
|
38
|
+
expect(main_file_header.x_min).to eql(-179.1473400012399)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "sets the y_min" do
|
42
|
+
expect(main_file_header.y_min).to eql(18.911121472000104)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "sets the x_max" do
|
46
|
+
expect(main_file_header.x_max).to eql(179.7784800000523)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "sets the y_max" do
|
50
|
+
expect(main_file_header.y_max).to eql(71.38921046509111)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "sets the z_min" do
|
54
|
+
expect(main_file_header.z_min).to eql(0.0)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "sets the z_max" do
|
58
|
+
expect(main_file_header.z_min).to eql(0.0)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "sets the m_min" do
|
62
|
+
expect(main_file_header.m_min).to eql(0.0)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "sets the m_max" do
|
66
|
+
expect(main_file_header.m_max).to eql(0.0)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module EsriShapefile
|
4
|
+
describe RecordHeader do
|
5
|
+
|
6
|
+
let(:record_header_bytes) do
|
7
|
+
"\x00\x00\x00\x01\x00\x00\x00\x04"
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "from_bytes" do
|
11
|
+
let(:record_header) do
|
12
|
+
RecordHeader.from_bytes(record_header_bytes)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "sets the record number" do
|
16
|
+
expect(record_header.record_number).to eql(1)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets the content length" do
|
20
|
+
expect(record_header.content_length).to eql(4)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EsriShapefile
|
2
|
+
module Shapes
|
3
|
+
describe Point do
|
4
|
+
|
5
|
+
describe "from_bytes" do
|
6
|
+
let(:point_bytes) { [1, 42, 57].pack('l<EE') }
|
7
|
+
let(:point) { Point.from_bytes(point_bytes) }
|
8
|
+
|
9
|
+
it "sets the shape_type" do
|
10
|
+
expect(point.shape_type).to eql(1)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets the x coordinate" do
|
14
|
+
expect(point.x).to eql(42.0)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets the y coordinate" do
|
18
|
+
expect(point.y).to eql(57.0)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'esri_shapefile'
|
2
|
+
|
3
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
6
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
7
|
+
# files.
|
8
|
+
#
|
9
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
+
# a separate helper file that requires the additional dependencies and performs
|
14
|
+
# the additional setup, and require it from the spec files that actually need
|
15
|
+
# it.
|
16
|
+
#
|
17
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
18
|
+
# users commonly want.
|
19
|
+
#
|
20
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
21
|
+
RSpec.configure do |config|
|
22
|
+
# rspec-expectations config goes here. You can use an alternate
|
23
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
24
|
+
# assertions if you prefer.
|
25
|
+
config.expect_with :rspec do |expectations|
|
26
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
27
|
+
# and `failure_message` of custom matchers include text for helper methods
|
28
|
+
# defined using `chain`, e.g.:
|
29
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
30
|
+
# # => "be bigger than 2 and smaller than 4"
|
31
|
+
# ...rather than:
|
32
|
+
# # => "be bigger than 2"
|
33
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
34
|
+
end
|
35
|
+
|
36
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
37
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
38
|
+
config.mock_with :rspec do |mocks|
|
39
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
40
|
+
# a real object. This is generally recommended, and will default to
|
41
|
+
# `true` in RSpec 4.
|
42
|
+
mocks.verify_partial_doubles = true
|
43
|
+
end
|
44
|
+
|
45
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
46
|
+
# have no way to turn it off -- the option exists only for backwards
|
47
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
48
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
49
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
50
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
51
|
+
|
52
|
+
# The settings below are suggested to provide a good initial experience
|
53
|
+
# with RSpec, but feel free to customize to your heart's content.
|
54
|
+
=begin
|
55
|
+
# This allows you to limit a spec run to individual examples or groups
|
56
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
57
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
58
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
59
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
60
|
+
config.filter_run_when_matching :focus
|
61
|
+
|
62
|
+
# Allows RSpec to persist some state between runs in order to support
|
63
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
64
|
+
# you configure your source control system to ignore this file.
|
65
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
66
|
+
|
67
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
68
|
+
# recommended. For more details, see:
|
69
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
70
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
71
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
72
|
+
config.disable_monkey_patching!
|
73
|
+
|
74
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
75
|
+
# be too noisy due to issues in dependencies.
|
76
|
+
config.warnings = true
|
77
|
+
|
78
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
79
|
+
# file, and it's useful to allow more verbose output when running an
|
80
|
+
# individual spec file.
|
81
|
+
if config.files_to_run.one?
|
82
|
+
# Use the documentation formatter for detailed output,
|
83
|
+
# unless a formatter has already been configured
|
84
|
+
# (e.g. via a command-line flag).
|
85
|
+
config.default_formatter = 'doc'
|
86
|
+
end
|
87
|
+
|
88
|
+
# Print the 10 slowest examples and example groups at the
|
89
|
+
# end of the spec run, to help surface which specs are running
|
90
|
+
# particularly slow.
|
91
|
+
config.profile_examples = 10
|
92
|
+
|
93
|
+
# Run specs in random order to surface order dependencies. If you find an
|
94
|
+
# order dependency and want to debug it, you can fix the order by providing
|
95
|
+
# the seed, which is printed after each run.
|
96
|
+
# --seed 1234
|
97
|
+
config.order = :random
|
98
|
+
|
99
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
100
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
101
|
+
# test failures related to randomization by passing the same `--seed` value
|
102
|
+
# as the one that triggered the failure.
|
103
|
+
Kernel.srand config.seed
|
104
|
+
=end
|
105
|
+
end
|