rgeo-shapefile 3.0.0 → 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: b6e5256b3e85525a1eaf405a0d77df1e4f5e607a36164cad539b07f0f8008ad2
4
- data.tar.gz: 69c7b87747813c5ae3bbb76a8dd9b635b8c3d6c96dcf86a3a6b50b311e126038
3
+ metadata.gz: e5e8a29dc9ce093542c32fb72317a7db94e5f48b6126b5df177a4d3add375d2b
4
+ data.tar.gz: b92fed106be710057adcd3ad0e0047b7341466c80ab3f3b66e920a180549c115
5
5
  SHA512:
6
- metadata.gz: 302a221acc3cac6842143dedaff74380d5dce58959b8b7381c00cce52401fa0e4343b31a999340f40ba08947c4245b15f2f1962e66f2422bab937b71de5bdd3e
7
- data.tar.gz: 56c09783ed155a8fcb95ad9596bae125a4b0a54cedd655fff07cfb4d1786c1011738c1a4768dff4e023b025ce75bee788c22f368a1b5c6ea4d5d3f1237fe1bd1
6
+ metadata.gz: e63fb61c0a948d75491810b6869f1955a1ef6bc6b66a71491dc0051b0ed2a558553b5eee072a9691aeba94a469b674e1a3ffa91eb8ef008498b92c8e78d26611
7
+ data.tar.gz: ccbec1961217d64f10931299f77a9aff64956ccc7d425dde97fd7b2a85fb34189fe873e2296c8966d1e2f534af3384934c1ead5ba68dc561983d18f524588b19
data/History.md CHANGED
@@ -1,40 +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
+
1
11
  ### 3.0.0 / 2020-08-02
2
12
 
3
- * Handle invalid DBF file (#37, rywall)
4
- * Update DBF gem to version 4.x, bump minimum Ruby version to 2.4 (#38, alvir)
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)
5
15
 
6
16
  ### 2.0.1 / 2019-04-01
7
17
 
8
- * 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)
9
19
 
10
20
 
11
21
  ### 2.0.0 / 2019-02-23
12
22
 
13
- * 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)
14
24
  * Remove :dbf_encoding option introduced in 1.2.0
15
25
 
16
26
 
17
27
  ### 1.2.0 / 2019-02-21
18
28
 
19
- * 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)
20
30
 
21
31
 
22
32
  ### 1.1.0 / 2018-11-30
23
33
 
24
- * Allow rgeo 2.0 (#29, sunpoet)
34
+ * Allow rgeo 2.0 ([#29](https://github.com/rgeo/rgeo-shapefile/pull/29), sunpoet)
25
35
  * Require ruby 2.3+
26
36
 
27
37
 
28
38
  ### 1.0.0 / 2018-3-6
29
39
 
30
- * Require rgeo 1.0 (#27)
40
+ * Require rgeo 1.0 ([#27](https://github.com/rgeo/rgeo-shapefile/pull/27))
31
41
  * Freeze strings
32
42
 
33
43
 
34
44
  ### 0.4.2 / 2017-1-31
35
45
 
36
46
  * Require ruby 2.1+
37
- * 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)
38
48
 
39
49
  ### 0.4.1 / 2015-2-8
40
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,12 +32,21 @@ 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:
@@ -46,7 +55,7 @@ end
46
55
  * rgeo 1.0.0 or later.
47
56
  * dbf 4.0 or later.
48
57
 
49
- If you need support for older Rubies, please use 2.x version
58
+ If you need support for older Rubies, please use 2.x version
50
59
 
51
60
  Include in your bundle:
52
61
 
@@ -98,4 +107,4 @@ ESRI shapefiles, we did borrow a bunch of their test cases.
98
107
 
99
108
  Copyright Daniel Azuma, Tee Parham
100
109
 
101
- 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.
@@ -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 = "3.0.0"
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: 3.0.0
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: 2020-09-02 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
@@ -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:
@@ -103,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
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.