rgeo-shapefile 2.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1d28553b385637b13dfb5bdc863afb809a3d097b99002b961971280e7f62c30
4
- data.tar.gz: e6ce78340ba93f106f67159f56f98346a76b6a43190a8c4df2256809df669218
3
+ metadata.gz: e5e8a29dc9ce093542c32fb72317a7db94e5f48b6126b5df177a4d3add375d2b
4
+ data.tar.gz: b92fed106be710057adcd3ad0e0047b7341466c80ab3f3b66e920a180549c115
5
5
  SHA512:
6
- metadata.gz: 718db69169feda3abdfe4c7c483b6f346e5a276a3537f449e4eb95f971c908e9e192ff0c9f816842cafe0969da97428a4766f877aba4955462b12f29d08590a5
7
- data.tar.gz: ed9c29623ce7186c3f1da9699064deb7e468b8cc8996236eab0182ec991df0c7b8a647bb18a257450e428e2f5c64e345970752f3696289afe1840379238afc35
6
+ metadata.gz: e63fb61c0a948d75491810b6869f1955a1ef6bc6b66a71491dc0051b0ed2a558553b5eee072a9691aeba94a469b674e1a3ffa91eb8ef008498b92c8e78d26611
7
+ data.tar.gz: ccbec1961217d64f10931299f77a9aff64956ccc7d425dde97fd7b2a85fb34189fe873e2296c8966d1e2f534af3384934c1ead5ba68dc561983d18f524588b19
data/History.md CHANGED
@@ -1,35 +1,50 @@
1
+ ### Current
2
+
3
+ ### 3.1.0 / 2023-09-30
4
+
5
+ * Rubocop updates and execution ([#51](https://github.com/rgeo/rgeo-shapefile/pull/51), ObiWanKeoni)
6
+ * Add option to allow unsafe parsing of shapefiles ([#50](https://github.com/rgeo/rgeo-shapefile/pull/50), ObiWanKeoni)
7
+ * Fix issue reading polylines without m values ([#44](https://github.com/rgeo/rgeo-shapefile/pull/44), rywall)
8
+ * Don't pass invalid encodings to DBF ([#43](https://github.com/rgeo/rgeo-shapefile/pull/43), rywall)
9
+ * Add Enumerable to the Reader ([#40](https://github.com/rgeo/rgeo-shapefile/pull/40), x4d3)
10
+
11
+ ### 3.0.0 / 2020-08-02
12
+
13
+ * Handle invalid DBF file ([#37](https://github.com/rgeo/rgeo-shapefile/pull/37), rywall)
14
+ * Update DBF gem to version 4.x, bump minimum Ruby version to 2.4 ([#38](https://github.com/rgeo/rgeo-shapefile/pull/38), alvir)
15
+
1
16
  ### 2.0.1 / 2019-04-01
2
17
 
3
- * Check dbf record attributes / allow DBF file to have fewer records than SHX (#34, womanonrails / #28, marcisv)
18
+ * Check dbf record attributes / allow DBF file to have fewer records than SHX ([#34](https://github.com/rgeo/rgeo-shapefile/pull/34), womanonrails / [#28](https://github.com/rgeo/rgeo-shapefile/pull/28), marcisv)
4
19
 
5
20
 
6
21
  ### 2.0.0 / 2019-02-23
7
22
 
8
- * Use .cpg file to specify the DBF encoding (#32, rywall)
23
+ * Use .cpg file to specify the DBF encoding ([#32](https://github.com/rgeo/rgeo-shapefile/pull/32), rywall)
9
24
  * Remove :dbf_encoding option introduced in 1.2.0
10
25
 
11
26
 
12
27
  ### 1.2.0 / 2019-02-21
13
28
 
14
- * Add ability to specify the DBF encoding (#30, rywall)
29
+ * Add ability to specify the DBF encoding ([#30](https://github.com/rgeo/rgeo-shapefile/pull/30), rywall)
15
30
 
16
31
 
17
32
  ### 1.1.0 / 2018-11-30
18
33
 
19
- * Allow rgeo 2.0 (#29, sunpoet)
34
+ * Allow rgeo 2.0 ([#29](https://github.com/rgeo/rgeo-shapefile/pull/29), sunpoet)
20
35
  * Require ruby 2.3+
21
36
 
22
37
 
23
38
  ### 1.0.0 / 2018-3-6
24
39
 
25
- * Require rgeo 1.0 (#27)
40
+ * Require rgeo 1.0 ([#27](https://github.com/rgeo/rgeo-shapefile/pull/27))
26
41
  * Freeze strings
27
42
 
28
43
 
29
44
  ### 0.4.2 / 2017-1-31
30
45
 
31
46
  * Require ruby 2.1+
32
- * Handle non-string path objects in Reader (#20, msimonborg)
47
+ * Handle non-string path objects in Reader ([#20](https://github.com/rgeo/rgeo-shapefile/pull/20), msimonborg)
33
48
 
34
49
  ### 0.4.1 / 2015-2-8
35
50
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # RGeo::Shapefile
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/rgeo-shapefile.svg)](http://badge.fury.io/rb/rgeo-shapefile)
4
- [![Build Status](https://travis-ci.org/rgeo/rgeo-shapefile.svg?branch=master)](https://travis-ci.org/rgeo/rgeo-shapefile)
4
+ [![CI](https://github.com/rgeo/rgeo-shapefile/workflows/CI/badge.svg)](https://github.com/rgeo/rgeo-shapefile/actions?query=workflow%3ACI+branch%3Amain+event%3Apush)
5
5
 
6
6
  `RGeo::Shapefile` is an optional module for [RGeo](https://github.com/rgeo/rgeo)
7
7
  for reading geospatial data from ESRI shapefiles.
@@ -32,19 +32,30 @@ RGeo::Shapefile::Reader.open('myshpfil.shp') do |file|
32
32
  puts " Geometry: #{record.geometry.as_text}"
33
33
  puts " Attributes: #{record.attributes.inspect}"
34
34
  end
35
- file.rewind
35
+ # If using version 3.0.0 or earlier, rewind is necessary to return to the beginning of the file.
36
+ # file.rewind
36
37
  record = file.next
37
38
  puts "First record geometry was: #{record.geometry.as_text}"
38
39
  end
39
40
  ```
41
+ ### Skipping validity checks
40
42
 
43
+ If you have shapefiles that are failing [rgeo validity checks](https://github.com/rgeo/rgeo/blob/main/doc/Geometry-Validity.md) you can skip validity checks by passing `allow_unsafe: true` to the `RGeo::Shapefile::Reader#open` method:
44
+
45
+ ```ruby
46
+ RGeo::Shapefile::Reader.open('myshpfil.shp', allow_unsafe: true) do |file|
47
+ # ...
48
+ end
49
+ ```
41
50
  ## Install
42
51
 
43
52
  `RGeo::Shapefile` has the following requirements:
44
53
 
45
- * Ruby 2.3.0 or later
54
+ * Ruby 2.4.0 or later
46
55
  * rgeo 1.0.0 or later.
47
- * dbf 3.0 or later.
56
+ * dbf 4.0 or later.
57
+
58
+ If you need support for older Rubies, please use 2.x version
48
59
 
49
60
  Include in your bundle:
50
61
 
@@ -61,6 +72,8 @@ gem install rgeo-shapefile
61
72
  See the [`rgeo`](https://github.com/rgeo/rgeo) gem, a required dependency,
62
73
  for further installation information.
63
74
 
75
+ If you are using Ruby 2.3, use version `2.0.x` of this gem.
76
+
64
77
  If you are using Ruby 2.0-2.2, use version `1.0.x` of this gem.
65
78
 
66
79
  If you are using Ruby 1.9, use version `0.3.x` of this gem.
@@ -94,4 +107,4 @@ ESRI shapefiles, we did borrow a bunch of their test cases.
94
107
 
95
108
  Copyright Daniel Azuma, Tee Parham
96
109
 
97
- https://github.com/rgeo/rgeo-shapefile/blob/master/LICENSE.txt
110
+ https://github.com/rgeo/rgeo-shapefile/blob/main/LICENSE.txt
@@ -92,6 +92,7 @@ module RGeo
92
92
  # a GeometryCollection instead of a MultiPolygon.
93
93
 
94
94
  class Reader
95
+ include Enumerable
95
96
  # Values less than this value are considered "no value" in the
96
97
  # shapefile format specification.
97
98
  NODATA_LIMIT = -1e38
@@ -175,18 +176,31 @@ module RGeo
175
176
  # block. You should use Reader::open instead.
176
177
 
177
178
  def initialize(path_, opts_ = {}) # :nodoc:
179
+ @allow_unsafe = false
180
+ if opts_[:allow_unsafe]
181
+ if Gem::Version.new(RGeo::VERSION) < Gem::Version.new("3.0.0")
182
+ warn "RGeo v#{RGeo::VERSION} does not support unsafe methods. Unsafe methods were added in RGeo v3.0.0."
183
+ else
184
+ @allow_unsafe = opts_[:allow_unsafe]
185
+ end
186
+ end
178
187
  path_ = path_.to_s.sub(/\.shp$/, "")
179
188
  @base_path = path_
180
189
  @opened = true
181
- @main_file = ::File.open(path_ + ".shp", "rb:ascii-8bit")
182
- @index_file = ::File.open(path_ + ".shx", "rb:ascii-8bit")
190
+ @main_file = ::File.open("#{path_}.shp", "rb:ascii-8bit")
191
+ @index_file = ::File.open("#{path_}.shx", "rb:ascii-8bit")
183
192
  @attr_dbf =
184
- if ::File.file?(path_ + ".dbf") && ::File.readable?(path_ + ".dbf")
185
- if ::File.file?(path_ + ".cpg") && ::File.readable?(path_ + ".cpg")
186
- dbf_encoding_ = ::File.read(path_ + ".cpg")
193
+ if ::File.file?("#{path_}.dbf") && ::File.readable?("#{path_}.dbf")
194
+ if ::File.file?("#{path_}.cpg") && ::File.readable?("#{path_}.cpg")
195
+ dbf_encoding_ = ::File.read("#{path_}.cpg")
196
+ dbf_encoding_ = begin
197
+ Encoding.find(dbf_encoding_.to_s.strip)
198
+ rescue StandardError
199
+ nil
200
+ end
187
201
  end
188
202
 
189
- ::DBF::Table.new(path_ + ".dbf", nil, dbf_encoding_)
203
+ ::DBF::Table.new("#{path_}.dbf", nil, dbf_encoding_)
190
204
  end
191
205
  @main_length, @shape_type_code, @xmin, @ymin, @xmax, @ymax, @zmin, @zmax, @mmin, @mmax = @main_file.read(100).unpack("x24Nx4VE8")
192
206
  @main_length *= 2
@@ -268,6 +282,7 @@ module RGeo
268
282
  def num_records
269
283
  @opened ? @num_records : nil
270
284
  end
285
+
271
286
  alias size num_records
272
287
 
273
288
  # Returns the shape type code.
@@ -342,8 +357,17 @@ module RGeo
342
357
  # and yield the Reader::Record for each one.
343
358
 
344
359
  def each
345
- return unless @opened
346
- yield _read_next_record while @cur_record_index < @num_records
360
+ return to_enum(:each) { @num_records } unless block_given?
361
+ raise IOError, "File was not open" unless @opened
362
+ # Each needs to be idempotent, therefore we reset all the internal indexes to their original value
363
+ current_record_index = @cur_record_index
364
+ begin
365
+ rewind
366
+ yield _read_next_record while @cur_record_index < @num_records
367
+ ensure
368
+ seek_index(current_record_index)
369
+ end
370
+ self
347
371
  end
348
372
 
349
373
  # Seek to the given record index.
@@ -398,7 +422,7 @@ module RGeo
398
422
  when 31 then _read_multipatch(data_)
399
423
  end
400
424
  attrs_ = {}
401
- if @attr_dbf && @attr_dbf.record(@cur_record_index)
425
+ if @attr_dbf && !@attr_dbf.columns.empty? && @attr_dbf.record(@cur_record_index)
402
426
  dbf_record_attrs_ = @attr_dbf.record(@cur_record_index).attributes
403
427
  @attr_dbf.columns.each do |col_|
404
428
  name_ = col_.name
@@ -485,7 +509,7 @@ module RGeo
485
509
  if opt_ == :z
486
510
  zs_ = ms_
487
511
  ms_ = values_.slice!(4, num_points_)
488
- ms_.map! { |val_| val_ < NODATA_LIMIT ? 0 : val_ }
512
+ ms_.map! { |val_| val_ < NODATA_LIMIT ? 0 : val_ } if ms_
489
513
  end
490
514
  end
491
515
 
@@ -613,14 +637,16 @@ module RGeo
613
637
  # The initial guess. It could be -1 if this inner ring
614
638
  # appeared before any outer rings had appeared.
615
639
  first_try_ = part_data_[3]
616
- if first_try_ >= 0 && part_data_[2].within?(polygons_[first_try_].first[2])
640
+
641
+ within_method_ = @allow_unsafe ? :unsafe_within? : :within?
642
+ if first_try_ >= 0 && part_data_[2].public_send(within_method_, polygons_[first_try_].first[2])
617
643
  parent_index_ = first_try_
618
644
  end
619
645
  # If the initial guess didn't work, go through the
620
646
  # remaining polygons and check their outer rings.
621
647
  unless parent_index_
622
648
  polygons_.each_with_index do |poly_data_, index_|
623
- if index_ != first_try_ && part_data_[2].within?(poly_data_.first[2])
649
+ if index_ != first_try_ && part_data_[2].public_send(within_method_, poly_data_.first[2])
624
650
  parent_index_ = index_
625
651
  break
626
652
  end
@@ -639,7 +665,7 @@ module RGeo
639
665
  # Generate the actual polygons from the collected polygon data
640
666
  polygons_.map! do |poly_data_|
641
667
  outer_ = poly_data_[0][0]
642
- inner_ = poly_data_[1..-1].map { |part_data_| part_data_[0] }
668
+ inner_ = poly_data_[1..].map { |part_data_| part_data_[0] }
643
669
  @factory.polygon(outer_, inner_)
644
670
  end
645
671
 
@@ -730,7 +756,7 @@ module RGeo
730
756
  else
731
757
  # End of an outer-led sequence.
732
758
  # Add the polygon and reset the state.
733
- polygons_ << @factory.polygon(sequence_[0], sequence_[1..-1])
759
+ polygons_ << @factory.polygon(sequence_[0], sequence_[1..])
734
760
  state_ = :empty
735
761
  sequence_ = []
736
762
  end
@@ -750,9 +776,10 @@ module RGeo
750
776
  geos_polygons_ = sequence_.map { |ring_| geos_factory_.polygon(ring_) }
751
777
  outer_poly_ = nil
752
778
  outer_index_ = 0
779
+ contains_method_ = @allow_unsafe ? :unsafe_contains? : :contains?
753
780
  geos_polygons_.each_with_index do |poly_, idx_|
754
781
  if outer_poly_
755
- if poly_.contains?(outer_poly_)
782
+ if poly_.public_send(contains_method_, outer_poly_)
756
783
  outer_poly_ = poly_
757
784
  outer_index_ = idx_
758
785
  break
@@ -764,7 +791,7 @@ module RGeo
764
791
  sequence_.slice!(outer_index_)
765
792
  sequence_.unshift(outer_poly_)
766
793
  end
767
- polygons_ << @factory.polygon(sequence_[0], sequence_[1..-1])
794
+ polygons_ << @factory.polygon(sequence_[0], sequence_[1..])
768
795
  state_ = :empty
769
796
  sequence_ = []
770
797
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RGeo
4
4
  module Shapefile
5
- VERSION = "2.0.1"
5
+ VERSION = "3.1.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgeo-shapefile
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-04-01 00:00:00.000000000 Z
12
+ date: 2023-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgeo
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '3.0'
34
+ version: '4.0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '3.0'
41
+ version: '4.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: minitest
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '5.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.36.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.36.0
56
70
  - !ruby/object:Gem::Dependency
57
71
  name: rake
58
72
  requirement: !ruby/object:Gem::Requirement
@@ -86,8 +100,9 @@ files:
86
100
  - lib/rgeo/shapefile/version.rb
87
101
  homepage: http://github.com/rgeo/rgeo-shapefile
88
102
  licenses:
89
- - BSD
90
- metadata: {}
103
+ - BSD-3-Clause
104
+ metadata:
105
+ rubygems_mfa_required: 'true'
91
106
  post_install_message:
92
107
  rdoc_options: []
93
108
  require_paths:
@@ -96,14 +111,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
111
  requirements:
97
112
  - - ">="
98
113
  - !ruby/object:Gem::Version
99
- version: 2.3.0
114
+ version: 2.4.0
100
115
  required_rubygems_version: !ruby/object:Gem::Requirement
101
116
  requirements:
102
117
  - - ">="
103
118
  - !ruby/object:Gem::Version
104
119
  version: '0'
105
120
  requirements: []
106
- rubygems_version: 3.0.3
121
+ rubygems_version: 3.2.33
107
122
  signing_key:
108
123
  specification_version: 4
109
124
  summary: An RGeo module for reading ESRI shapefiles.