rgeo 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/ext/geos_c_impl/extconf.rb +5 -3
  3. data/ext/geos_c_impl/factory.c +4 -4
  4. data/ext/geos_c_impl/geometry.c +1 -1
  5. data/lib/rgeo.rb +2 -4
  6. data/lib/rgeo/cartesian.rb +6 -16
  7. data/lib/rgeo/cartesian/analysis.rb +22 -20
  8. data/lib/rgeo/cartesian/bounding_box.rb +83 -79
  9. data/lib/rgeo/cartesian/calculations.rb +40 -38
  10. data/lib/rgeo/cartesian/factory.rb +134 -169
  11. data/lib/rgeo/cartesian/feature_classes.rb +2 -18
  12. data/lib/rgeo/cartesian/feature_methods.rb +37 -39
  13. data/lib/rgeo/cartesian/interface.rb +11 -9
  14. data/lib/rgeo/coord_sys.rb +9 -8
  15. data/lib/rgeo/coord_sys/cs/entities.rb +345 -303
  16. data/lib/rgeo/coord_sys/cs/factories.rb +30 -28
  17. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +128 -126
  18. data/lib/rgeo/coord_sys/srs_database/{interface.rb → entry.rb} +26 -32
  19. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +19 -17
  20. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +21 -19
  21. data/lib/rgeo/error.rb +3 -1
  22. data/lib/rgeo/feature.rb +23 -34
  23. data/lib/rgeo/feature/curve.rb +2 -0
  24. data/lib/rgeo/feature/factory.rb +15 -13
  25. data/lib/rgeo/feature/factory_generator.rb +7 -5
  26. data/lib/rgeo/feature/geometry.rb +31 -29
  27. data/lib/rgeo/feature/geometry_collection.rb +6 -4
  28. data/lib/rgeo/feature/line.rb +2 -0
  29. data/lib/rgeo/feature/line_string.rb +3 -1
  30. data/lib/rgeo/feature/linear_ring.rb +2 -0
  31. data/lib/rgeo/feature/multi_curve.rb +2 -0
  32. data/lib/rgeo/feature/multi_line_string.rb +2 -0
  33. data/lib/rgeo/feature/multi_point.rb +2 -0
  34. data/lib/rgeo/feature/multi_polygon.rb +2 -0
  35. data/lib/rgeo/feature/multi_surface.rb +2 -0
  36. data/lib/rgeo/feature/point.rb +2 -0
  37. data/lib/rgeo/feature/polygon.rb +3 -1
  38. data/lib/rgeo/feature/surface.rb +2 -0
  39. data/lib/rgeo/feature/types.rb +107 -103
  40. data/lib/rgeo/geographic.rb +17 -27
  41. data/lib/rgeo/geographic/factory.rb +154 -199
  42. data/lib/rgeo/geographic/interface.rb +141 -137
  43. data/lib/rgeo/geographic/proj4_projector.rb +28 -23
  44. data/lib/rgeo/geographic/projected_feature_classes.rb +2 -18
  45. data/lib/rgeo/geographic/projected_feature_methods.rb +59 -49
  46. data/lib/rgeo/geographic/projected_window.rb +4 -2
  47. data/lib/rgeo/geographic/simple_mercator_projector.rb +41 -39
  48. data/lib/rgeo/geographic/spherical_feature_classes.rb +2 -18
  49. data/lib/rgeo/geographic/spherical_feature_methods.rb +67 -67
  50. data/lib/rgeo/geographic/spherical_math.rb +81 -87
  51. data/lib/rgeo/geos.rb +23 -34
  52. data/lib/rgeo/geos/capi_factory.rb +106 -135
  53. data/lib/rgeo/geos/capi_feature_classes.rb +19 -37
  54. data/lib/rgeo/geos/ffi_factory.rb +276 -297
  55. data/lib/rgeo/geos/ffi_feature_classes.rb +2 -20
  56. data/lib/rgeo/geos/ffi_feature_methods.rb +170 -166
  57. data/lib/rgeo/geos/interface.rb +25 -23
  58. data/lib/rgeo/geos/utils.rb +47 -39
  59. data/lib/rgeo/geos/zm_factory.rb +171 -185
  60. data/lib/rgeo/geos/zm_feature_classes.rb +2 -20
  61. data/lib/rgeo/geos/zm_feature_methods.rb +76 -72
  62. data/lib/rgeo/impl_helper.rb +1 -11
  63. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +72 -75
  64. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +21 -23
  65. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +57 -49
  66. data/lib/rgeo/impl_helper/basic_point_methods.rb +29 -25
  67. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +31 -27
  68. data/lib/rgeo/impl_helper/math.rb +2 -0
  69. data/lib/rgeo/impl_helper/utils.rb +9 -15
  70. data/lib/rgeo/version.rb +3 -1
  71. data/lib/rgeo/wkrep.rb +20 -30
  72. data/lib/rgeo/wkrep/wkb_generator.rb +87 -84
  73. data/lib/rgeo/wkrep/wkb_parser.rb +93 -93
  74. data/lib/rgeo/wkrep/wkt_generator.rb +67 -63
  75. data/lib/rgeo/wkrep/wkt_parser.rb +172 -168
  76. metadata +17 -32
  77. data/lib/rgeo/feature/mixins.rb +0 -143
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # GEOS toplevel interface
@@ -29,30 +31,30 @@ module RGeo
29
31
  # Returns true if the given feature is a CAPI GEOS feature, or if
30
32
  # the given factory is a CAPI GEOS factory.
31
33
 
32
- def is_capi_geos?(object_)
34
+ def is_capi_geos?(object)
33
35
  CAPI_SUPPORTED &&
34
- (CAPIFactory === object_ || CAPIGeometryMethods === object_ ||
35
- ZMFactory === object_ && CAPIFactory === object_.z_factory ||
36
- ZMGeometryMethods === object_ && CAPIGeometryMethods === object_.z_geometry)
36
+ (CAPIFactory === object || CAPIGeometryMethods === object ||
37
+ ZMFactory === object && CAPIFactory === object.z_factory ||
38
+ ZMGeometryMethods === object && CAPIGeometryMethods === object.z_geometry)
37
39
  end
38
40
 
39
41
  # Returns true if the given feature is an FFI GEOS feature, or if
40
42
  # the given factory is an FFI GEOS factory.
41
43
 
42
- def is_ffi_geos?(object_)
44
+ def is_ffi_geos?(object)
43
45
  FFI_SUPPORTED &&
44
- (FFIFactory === object_ || FFIGeometryMethods === object_ ||
45
- ZMFactory === object_ && FFIFactory === object_.z_factory ||
46
- ZMGeometryMethods === object_ && FFIGeometryMethods === object_.z_geometry)
46
+ (FFIFactory === object || FFIGeometryMethods === object ||
47
+ ZMFactory === object && FFIFactory === object.z_factory ||
48
+ ZMGeometryMethods === object && FFIGeometryMethods === object.z_geometry)
47
49
  end
48
50
 
49
51
  # Returns true if the given feature is a GEOS feature, or if the given
50
52
  # factory is a GEOS factory. Does not distinguish between CAPI and FFI.
51
53
 
52
- def is_geos?(object_)
53
- CAPI_SUPPORTED && (CAPIFactory === object_ || CAPIGeometryMethods === object_) ||
54
- FFI_SUPPORTED && (FFIFactory === object_ || FFIGeometryMethods === object_) ||
55
- ZMFactory === object_ || ZMGeometryMethods === object_
54
+ def is_geos?(object)
55
+ CAPI_SUPPORTED && (CAPIFactory === object || CAPIGeometryMethods === object) ||
56
+ FFI_SUPPORTED && (FFIFactory === object || FFIGeometryMethods === object) ||
57
+ ZMFactory === object || ZMGeometryMethods === object
56
58
  end
57
59
 
58
60
  # Returns the GEOS library version as a string of the format "x.y.z".
@@ -126,8 +128,8 @@ module RGeo
126
128
  # CoordSys::CS::CoordinateSystem, or as a string in WKT format.
127
129
  # Optional.
128
130
  # [<tt>:srs_database</tt>]
129
- # Optional. If provided, the value should be an implementation of
130
- # CoordSys::SRSDatabase::Interface. If both this and an SRID are
131
+ # Optional. If provided, the object should respond to #get and
132
+ # #clear_cache. If both this and an SRID are
131
133
  # provided, they are used to look up the proj4 and coord_sys
132
134
  # objects from a spatial reference system database.
133
135
  # [<tt>:has_z_coordinate</tt>]
@@ -173,15 +175,15 @@ module RGeo
173
175
  # never automatically generates a prepared geometry (unless you
174
176
  # generate one explicitly using the <tt>prepare!</tt> method).
175
177
 
176
- def factory(opts_ = {})
178
+ def factory(opts = {})
177
179
  if supported?
178
- native_interface_ = opts_[:native_interface] || Geos.preferred_native_interface
179
- if opts_[:has_z_coordinate] && opts_[:has_m_coordinate]
180
- ZMFactory.new(opts_)
181
- elsif native_interface_ == :ffi
182
- FFIFactory.new(opts_)
180
+ native_interface = opts[:native_interface] || Geos.preferred_native_interface
181
+ if opts[:has_z_coordinate] && opts[:has_m_coordinate]
182
+ ZMFactory.new(opts)
183
+ elsif native_interface == :ffi
184
+ FFIFactory.new(opts)
183
185
  else
184
- CAPIFactory.create(opts_)
186
+ CAPIFactory.create(opts)
185
187
  end
186
188
  end
187
189
  end
@@ -194,8 +196,8 @@ module RGeo
194
196
  # an SRID and it will automatically fetch the appropriate Proj4
195
197
  # and CoordSys objects.
196
198
 
197
- def factory_generator(defaults_ = {})
198
- ::Proc.new { |c_| factory(defaults_.merge(c_)) }
199
+ def factory_generator(defaults = {})
200
+ proc { |c| factory(defaults.merge(c)) }
199
201
  end
200
202
  end
201
203
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # Various Geos-related internal utilities
@@ -8,14 +10,14 @@ module RGeo
8
10
  module Geos
9
11
  module Utils # :nodoc:
10
12
  class << self
11
- def ffi_coord_seqs_equal?(cs1_, cs2_, check_z_)
12
- len1_ = cs1_.length
13
- len2_ = cs2_.length
14
- if len1_ == len2_
15
- (0...len1_).each do |i_|
16
- return false unless cs1_.get_x(i_) == cs2_.get_x(i_) &&
17
- cs1_.get_y(i_) == cs2_.get_y(i_) &&
18
- (!check_z_ || cs1_.get_z(i_) == cs2_.get_z(i_))
13
+ def ffi_coord_seqs_equal?(cs1, cs2, check_z)
14
+ len1 = cs1.length
15
+ len2 = cs2.length
16
+ if len1 == len2
17
+ (0...len1).each do |i|
18
+ return false unless cs1.get_x(i) == cs2.get_x(i) &&
19
+ cs1.get_y(i) == cs2.get_y(i) &&
20
+ (!check_z || cs1.get_z(i) == cs2.get_z(i))
19
21
  end
20
22
  true
21
23
  else
@@ -23,53 +25,59 @@ module RGeo
23
25
  end
24
26
  end
25
27
 
26
- def ffi_compute_dimension(geom_)
27
- result_ = -1
28
- case geom_.type_id
28
+ def ffi_compute_dimension(geom)
29
+ result = -1
30
+ case geom.type_id
29
31
  when ::Geos::GeomTypes::GEOS_POINT
30
- result_ = 0
32
+ result = 0
31
33
  when ::Geos::GeomTypes::GEOS_MULTIPOINT
32
- result_ = 0 unless geom_.empty?
34
+ result = 0 unless geom.empty?
33
35
  when ::Geos::GeomTypes::GEOS_LINESTRING, ::Geos::GeomTypes::GEOS_LINEARRING
34
- result_ = 1
36
+ result = 1
35
37
  when ::Geos::GeomTypes::GEOS_MULTILINESTRING
36
- result_ = 1 unless geom_.empty?
38
+ result = 1 unless geom.empty?
37
39
  when ::Geos::GeomTypes::GEOS_POLYGON
38
- result_ = 2
40
+ result = 2
39
41
  when ::Geos::GeomTypes::GEOS_MULTIPOLYGON
40
- result_ = 2 unless geom_.empty?
42
+ result = 2 unless geom.empty?
41
43
  when ::Geos::GeomTypes::GEOS_GEOMETRYCOLLECTION
42
- geom_.each do |g_|
43
- dim_ = ffi_compute_dimension(g_)
44
- result_ = dim_ if result_ < dim_
44
+ geom.each do |g|
45
+ dim = ffi_compute_dimension(g)
46
+ result = dim if result < dim
45
47
  end
46
48
  end
47
- result_
49
+ result
48
50
  end
49
51
 
50
- def ffi_coord_seq_hash(cs_, hash_ = 0)
51
- (0...cs_.length).inject(hash_) do |_h_, i_|
52
- [hash_, cs_.get_x(i_), cs_.get_y(i_), cs_.get_z(i_)].hash
52
+ def ffi_coord_seq_hash(cs, hash = 0)
53
+ (0...cs.length).inject(hash) do |h, i|
54
+ [hash, cs.get_x(i), cs.get_y(i), cs.get_z(i)].hash
53
55
  end
54
56
  end
55
57
 
56
- def _init
57
- if FFI_SUPPORTED
58
- @ffi_supports_prepared_level_1 = ::Geos::FFIGeos.respond_to?(:GEOSPreparedContains_r)
59
- @ffi_supports_prepared_level_2 = ::Geos::FFIGeos.respond_to?(:GEOSPreparedDisjoint_r)
60
- @ffi_supports_set_output_dimension = ::Geos::FFIGeos.respond_to?(:GEOSWKTWriter_setOutputDimension_r)
61
- @ffi_supports_unary_union = ::Geos::FFIGeos.respond_to?(:GEOSUnaryUnion_r)
62
- end
63
- @psych_wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper)
64
- @marshal_wkb_generator = WKRep::WKBGenerator.new
58
+ def ffi_supports_prepared_level_1
59
+ FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSPreparedContains_r)
60
+ end
61
+
62
+ def ffi_supports_prepared_level_2
63
+ FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSPreparedDisjoint_r)
64
+ end
65
+
66
+ def ffi_supports_set_output_dimension
67
+ FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSWKTWriter_setOutputDimension_r)
65
68
  end
66
69
 
67
- attr_reader :ffi_supports_prepared_level_1
68
- attr_reader :ffi_supports_prepared_level_2
69
- attr_reader :ffi_supports_set_output_dimension
70
- attr_reader :ffi_supports_unary_union
71
- attr_reader :psych_wkt_generator
72
- attr_reader :marshal_wkb_generator
70
+ def ffi_supports_unary_union
71
+ FFI_SUPPORTED && ::Geos::FFIGeos.respond_to?(:GEOSUnaryUnion_r)
72
+ end
73
+
74
+ def psych_wkt_generator
75
+ WKRep::WKTGenerator.new(convert_case: :upper)
76
+ end
77
+
78
+ def marshal_wkb_generator
79
+ WKRep::WKBGenerator.new
80
+ end
73
81
  end
74
82
  end
75
83
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # -----------------------------------------------------------------------------
2
4
  #
3
5
  # GEOS zm factory implementation
@@ -10,6 +12,7 @@ module RGeo
10
12
 
11
13
  class ZMFactory
12
14
  include Feature::Factory::Instance
15
+ include ImplHelper::Utils
13
16
 
14
17
  # :stopdoc:
15
18
 
@@ -31,66 +34,66 @@ module RGeo
31
34
  # Create a new factory. Returns nil if the GEOS implementation is
32
35
  # not supported.
33
36
 
34
- def create(opts_ = {})
35
- return nil unless Geos.supported?
36
- new(opts_)
37
+ def create(opts = {})
38
+ return unless Geos.supported?
39
+ new(opts)
37
40
  end
38
41
  end
39
42
 
40
- def initialize(opts_ = {}) # :nodoc:
41
- proj4_ = opts_[:proj4]
42
- coord_sys_ = opts_[:coord_sys]
43
- srid_ = opts_[:srid]
44
- if (!proj4_ || !coord_sys_) && srid_ && (db_ = opts_[:srs_database])
45
- entry_ = db_.get(srid_.to_i)
46
- if entry_
47
- proj4_ ||= entry_.proj4
48
- coord_sys_ ||= entry_.coord_sys
43
+ def initialize(opts = {}) # :nodoc:
44
+ proj4 = opts[:proj4]
45
+ coord_sys = opts[:coord_sys]
46
+ srid = opts[:srid]
47
+ if (!proj4 || !coord_sys) && srid && (db = opts[:srs_database])
48
+ entry = db.get(srid.to_i)
49
+ if entry
50
+ proj4 ||= entry.proj4
51
+ coord_sys ||= entry.coord_sys
49
52
  end
50
53
  end
51
- srid_ ||= coord_sys_.authority_code if coord_sys_
52
- config_ = {
53
- uses_lenient_multi_polygon_assertions: opts_[:lenient_multi_polygon_assertions] ||
54
- opts_[:uses_lenient_multi_polygon_assertions],
55
- buffer_resolution: opts_[:buffer_resolution], auto_prepare: opts_[:auto_prepare],
56
- wkt_generator: opts_[:wkt_generator], wkt_parser: opts_[:wkt_parser],
57
- wkb_generator: opts_[:wkb_generator], wkb_parser: opts_[:wkb_parser],
58
- srid: srid_.to_i, proj4: proj4_, coord_sys: coord_sys_
54
+ srid ||= coord_sys.authority_code if coord_sys
55
+ config = {
56
+ uses_lenient_multi_polygon_assertions: opts[:lenient_multi_polygon_assertions] ||
57
+ opts[:uses_lenient_multi_polygon_assertions],
58
+ buffer_resolution: opts[:buffer_resolution], auto_prepare: opts[:auto_prepare],
59
+ wkt_generator: opts[:wkt_generator], wkt_parser: opts[:wkt_parser],
60
+ wkb_generator: opts[:wkb_generator], wkb_parser: opts[:wkb_parser],
61
+ srid: srid.to_i, proj4: proj4, coord_sys: coord_sys
59
62
  }
60
- native_interface_ = opts_[:native_interface] || Geos.preferred_native_interface
61
- if native_interface_ == :ffi
62
- @zfactory = FFIFactory.new(config_.merge(has_z_coordinate: true))
63
- @mfactory = FFIFactory.new(config_.merge(has_m_coordinate: true))
63
+ native_interface = opts[:native_interface] || Geos.preferred_native_interface
64
+ if native_interface == :ffi
65
+ @zfactory = FFIFactory.new(config.merge(has_z_coordinate: true))
66
+ @mfactory = FFIFactory.new(config.merge(has_m_coordinate: true))
64
67
  else
65
- @zfactory = CAPIFactory.create(config_.merge(has_z_coordinate: true))
66
- @mfactory = CAPIFactory.create(config_.merge(has_m_coordinate: true))
68
+ @zfactory = CAPIFactory.create(config.merge(has_z_coordinate: true))
69
+ @mfactory = CAPIFactory.create(config.merge(has_m_coordinate: true))
67
70
  end
68
71
 
69
- wkt_generator_ = opts_[:wkt_generator]
70
- case wkt_generator_
71
- when ::Hash
72
- @wkt_generator = WKRep::WKTGenerator.new(wkt_generator_)
72
+ wkt_generator = opts[:wkt_generator]
73
+ case wkt_generator
74
+ when Hash
75
+ @wkt_generator = WKRep::WKTGenerator.new(wkt_generator)
73
76
  else
74
77
  @wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper)
75
78
  end
76
- wkb_generator_ = opts_[:wkb_generator]
77
- case wkb_generator_
78
- when ::Hash
79
- @wkb_generator = WKRep::WKBGenerator.new(wkb_generator_)
79
+ wkb_generator = opts[:wkb_generator]
80
+ case wkb_generator
81
+ when Hash
82
+ @wkb_generator = WKRep::WKBGenerator.new(wkb_generator)
80
83
  else
81
84
  @wkb_generator = WKRep::WKBGenerator.new
82
85
  end
83
- wkt_parser_ = opts_[:wkt_parser]
84
- case wkt_parser_
85
- when ::Hash
86
- @wkt_parser = WKRep::WKTParser.new(self, wkt_parser_)
86
+ wkt_parser = opts[:wkt_parser]
87
+ case wkt_parser
88
+ when Hash
89
+ @wkt_parser = WKRep::WKTParser.new(self, wkt_parser)
87
90
  else
88
91
  @wkt_parser = WKRep::WKTParser.new(self)
89
92
  end
90
- wkb_parser_ = opts_[:wkb_parser]
91
- case wkb_parser_
92
- when ::Hash
93
- @wkb_parser = WKRep::WKBParser.new(self, wkb_parser_)
93
+ wkb_parser = opts[:wkb_parser]
94
+ case wkb_parser
95
+ when Hash
96
+ @wkb_parser = WKRep::WKBParser.new(self, wkb_parser)
94
97
  else
95
98
  @wkb_parser = WKRep::WKBParser.new(self)
96
99
  end
@@ -99,104 +102,104 @@ module RGeo
99
102
  # Marshal support
100
103
 
101
104
  def marshal_dump # :nodoc:
102
- hash_ = {
105
+ hash = {
103
106
  "srid" => @zfactory.srid,
104
107
  "bufr" => @zfactory.buffer_resolution,
105
- "wktg" => @wkt_generator._properties,
106
- "wkbg" => @wkb_generator._properties,
107
- "wktp" => @wkt_parser._properties,
108
- "wkbp" => @wkb_parser._properties,
108
+ "wktg" => @wkt_generator.properties,
109
+ "wkbg" => @wkb_generator.properties,
110
+ "wktp" => @wkt_parser.properties,
111
+ "wkbp" => @wkb_parser.properties,
109
112
  "lmpa" => @zfactory.lenient_multi_polygon_assertions?,
110
113
  "apre" => @zfactory.property(:auto_prepare) == :simple,
111
114
  "nffi" => @zfactory.is_a?(FFIFactory)
112
115
  }
113
- proj4_ = @zfactory.proj4
114
- coord_sys_ = @zfactory.coord_sys
115
- hash_["proj4"] = proj4_.marshal_dump if proj4_
116
- hash_["cs"] = coord_sys_.to_wkt if coord_sys_
117
- hash_
116
+ proj4 = @zfactory.proj4
117
+ coord_sys = @zfactory.coord_sys
118
+ hash["proj4"] = proj4.marshal_dump if proj4
119
+ hash["cs"] = coord_sys.to_wkt if coord_sys
120
+ hash
118
121
  end
119
122
 
120
- def marshal_load(data_) # :nodoc:
121
- if (proj4_data_ = data_["proj4"]) && CoordSys.check!(:proj4)
122
- proj4_ = CoordSys::Proj4.allocate
123
- proj4_.marshal_load(proj4_data_)
123
+ def marshal_load(data) # :nodoc:
124
+ if (proj4_data = data["proj4"]) && CoordSys.check!(:proj4)
125
+ proj4 = CoordSys::Proj4.allocate
126
+ proj4.marshal_load(proj4_data)
124
127
  else
125
- proj4_ = nil
128
+ proj4 = nil
126
129
  end
127
- if (coord_sys_data_ = data_["cs"])
128
- coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_)
130
+ if (coord_sys_data = data["cs"])
131
+ coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data)
129
132
  else
130
- coord_sys_ = nil
133
+ coord_sys = nil
131
134
  end
132
135
  initialize(
133
- native_interface: (data_["nffi"] ? :ffi : :capi),
134
- has_z_coordinate: data_["hasz"],
135
- has_m_coordinate: data_["hasm"],
136
- srid: data_["srid"],
137
- buffer_resolution: data_["bufr"],
138
- wkt_generator: ImplHelper::Utils.symbolize_hash(data_["wktg"]),
139
- wkb_generator: ImplHelper::Utils.symbolize_hash(data_["wkbg"]),
140
- wkt_parser: ImplHelper::Utils.symbolize_hash(data_["wktp"]),
141
- wkb_parser: ImplHelper::Utils.symbolize_hash(data_["wkbp"]),
142
- uses_lenient_multi_polygon_assertions: data_["lmpa"],
143
- auto_prepare: (data_["apre"] ? :simple : :disabled),
144
- proj4: proj4_,
145
- coord_sys: coord_sys_
136
+ native_interface: (data["nffi"] ? :ffi : :capi),
137
+ has_z_coordinate: data["hasz"],
138
+ has_m_coordinate: data["hasm"],
139
+ srid: data["srid"],
140
+ buffer_resolution: data["bufr"],
141
+ wkt_generator: symbolize_hash(data["wktg"]),
142
+ wkb_generator: symbolize_hash(data["wkbg"]),
143
+ wkt_parser: symbolize_hash(data["wktp"]),
144
+ wkb_parser: symbolize_hash(data["wkbp"]),
145
+ uses_lenient_multi_polygon_assertions: data["lmpa"],
146
+ auto_prepare: (data["apre"] ? :simple : :disabled),
147
+ proj4: proj4,
148
+ coord_sys: coord_sys
146
149
  )
147
150
  end
148
151
 
149
152
  # Psych support
150
153
 
151
- def encode_with(coder_) # :nodoc:
152
- coder_["srid"] = @zfactory.srid
153
- coder_["buffer_resolution"] = @zfactory.buffer_resolution
154
- coder_["lenient_multi_polygon_assertions"] = @zfactory.lenient_multi_polygon_assertions?
155
- coder_["wkt_generator"] = @wkt_generator._properties
156
- coder_["wkb_generator"] = @wkb_generator._properties
157
- coder_["wkt_parser"] = @wkt_parser._properties
158
- coder_["wkb_parser"] = @wkb_parser._properties
159
- coder_["auto_prepare"] = @zfactory.property(:auto_prepare).to_s
160
- coder_["native_interface"] = @zfactory.is_a?(FFIFactory) ? "ffi" : "capi"
161
- if (proj4_ = @zfactory.proj4)
162
- str_ = proj4_.original_str || proj4_.canonical_str
163
- coder_["proj4"] = proj4_.radians? ? { "proj4" => str_, "radians" => true } : str_
154
+ def encode_with(coder) # :nodoc:
155
+ coder["srid"] = @zfactory.srid
156
+ coder["buffer_resolution"] = @zfactory.buffer_resolution
157
+ coder["lenient_multi_polygon_assertions"] = @zfactory.lenient_multi_polygon_assertions?
158
+ coder["wkt_generator"] = @wkt_generator.properties
159
+ coder["wkb_generator"] = @wkb_generator.properties
160
+ coder["wkt_parser"] = @wkt_parser.properties
161
+ coder["wkb_parser"] = @wkb_parser.properties
162
+ coder["auto_prepare"] = @zfactory.property(:auto_prepare).to_s
163
+ coder["native_interface"] = @zfactory.is_a?(FFIFactory) ? "ffi" : "capi"
164
+ if (proj4 = @zfactory.proj4)
165
+ str = proj4.original_str || proj4.canonical_str
166
+ coder["proj4"] = proj4.radians? ? { "proj4" => str, "radians" => true } : str
164
167
  end
165
- if (coord_sys_ = @zfactory.coord_sys)
166
- coder_["coord_sys"] = coord_sys_.to_wkt
168
+ if (coord_sys = @zfactory.coord_sys)
169
+ coder["coord_sys"] = coord_sys.to_wkt
167
170
  end
168
171
  end
169
172
 
170
- def init_with(coder_) # :nodoc:
171
- if (proj4_data_ = coder_["proj4"])
173
+ def init_with(coder) # :nodoc:
174
+ if (proj4_data = coder["proj4"])
172
175
  CoordSys.check!(:proj4)
173
- if proj4_data_.is_a?(::Hash)
174
- proj4_ = CoordSys::Proj4.create(proj4_data_["proj4"], radians: proj4_data_["radians"])
176
+ if proj4_data.is_a?(Hash)
177
+ proj4 = CoordSys::Proj4.create(proj4_data["proj4"], radians: proj4_data["radians"])
175
178
  else
176
- proj4_ = CoordSys::Proj4.create(proj4_data_.to_s)
179
+ proj4 = CoordSys::Proj4.create(proj4_data.to_s)
177
180
  end
178
181
  else
179
- proj4_ = nil
182
+ proj4 = nil
180
183
  end
181
- if (coord_sys_data_ = coder_["cs"])
182
- coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_.to_s)
184
+ if (coord_sys_data = coder["cs"])
185
+ coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data.to_s)
183
186
  else
184
- coord_sys_ = nil
187
+ coord_sys = nil
185
188
  end
186
189
  initialize(
187
- native_interface: coder_["native_interface"] == "ffi" ? :ffi : :capi,
188
- has_z_coordinate: coder_["has_z_coordinate"],
189
- has_m_coordinate: coder_["has_m_coordinate"],
190
- srid: coder_["srid"],
191
- buffer_resolution: coder_["buffer_resolution"],
192
- wkt_generator: ImplHelper::Utils.symbolize_hash(coder_["wkt_generator"]),
193
- wkb_generator: ImplHelper::Utils.symbolize_hash(coder_["wkb_generator"]),
194
- wkt_parser: ImplHelper::Utils.symbolize_hash(coder_["wkt_parser"]),
195
- wkb_parser: ImplHelper::Utils.symbolize_hash(coder_["wkb_parser"]),
196
- auto_prepare: coder_["auto_prepare"] == "disabled" ? :disabled : :simple,
197
- uses_lenient_multi_polygon_assertions: coder_["lenient_multi_polygon_assertions"],
198
- proj4: proj4_,
199
- coord_sys: coord_sys_
190
+ native_interface: coder["native_interface"] == "ffi" ? :ffi : :capi,
191
+ has_z_coordinate: coder["has_z_coordinate"],
192
+ has_m_coordinate: coder["has_m_coordinate"],
193
+ srid: coder["srid"],
194
+ buffer_resolution: coder["buffer_resolution"],
195
+ wkt_generator: symbolize_hash(coder["wkt_generator"]),
196
+ wkb_generator: symbolize_hash(coder["wkb_generator"]),
197
+ wkt_parser: symbolize_hash(coder["wkt_parser"]),
198
+ wkb_parser: symbolize_hash(coder["wkb_parser"]),
199
+ auto_prepare: coder["auto_prepare"] == "disabled" ? :disabled : :simple,
200
+ uses_lenient_multi_polygon_assertions: coder["lenient_multi_polygon_assertions"],
201
+ proj4: proj4,
202
+ coord_sys: coord_sys
200
203
  )
201
204
  end
202
205
 
@@ -233,8 +236,8 @@ module RGeo
233
236
 
234
237
  # Factory equivalence test.
235
238
 
236
- def eql?(rhs_)
237
- rhs_.is_a?(ZMFactory) && rhs_.z_factory == @zfactory
239
+ def eql?(rhs)
240
+ rhs.is_a?(ZMFactory) && rhs.z_factory == @zfactory
238
241
  end
239
242
  alias == eql?
240
243
 
@@ -246,8 +249,8 @@ module RGeo
246
249
 
247
250
  # See RGeo::Feature::Factory#property
248
251
 
249
- def property(name_)
250
- case name_
252
+ def property(name)
253
+ case name
251
254
  when :has_z_coordinate, :has_m_coordinate, :is_cartesian
252
255
  true
253
256
  end
@@ -255,68 +258,68 @@ module RGeo
255
258
 
256
259
  # See RGeo::Feature::Factory#parse_wkt
257
260
 
258
- def parse_wkt(str_)
259
- @wkt_parser.parse(str_)
261
+ def parse_wkt(str)
262
+ @wkt_parser.parse(str)
260
263
  end
261
264
 
262
265
  # See RGeo::Feature::Factory#parse_wkb
263
266
 
264
- def parse_wkb(str_)
265
- @wkb_parser.parse(str_)
267
+ def parse_wkb(str)
268
+ @wkb_parser.parse(str)
266
269
  end
267
270
 
268
271
  # See RGeo::Feature::Factory#point
269
272
 
270
- def point(x_, y_, z_ = 0, m_ = 0)
271
- _create_feature(ZMPointImpl, @zfactory.point(x_, y_, z_), @mfactory.point(x_, y_, m_))
273
+ def point(x, y, z = 0, m = 0)
274
+ create_feature(ZMPointImpl, @zfactory.point(x, y, z), @mfactory.point(x, y, m))
272
275
  end
273
276
 
274
277
  # See RGeo::Feature::Factory#line_string
275
278
 
276
- def line_string(points_)
277
- _create_feature(ZMLineStringImpl, @zfactory.line_string(points_), @mfactory.line_string(points_))
279
+ def line_string(points)
280
+ create_feature(ZMLineStringImpl, @zfactory.line_string(points), @mfactory.line_string(points))
278
281
  end
279
282
 
280
283
  # See RGeo::Feature::Factory#line
281
284
 
282
- def line(start_, end_)
283
- _create_feature(ZMLineImpl, @zfactory.line(start_, end_), @mfactory.line(start_, end_))
285
+ def line(start, stop)
286
+ create_feature(ZMLineImpl, @zfactory.line(start, stop), @mfactory.line(start, stop))
284
287
  end
285
288
 
286
289
  # See RGeo::Feature::Factory#linear_ring
287
290
 
288
- def linear_ring(points_)
289
- _create_feature(ZMLinearRingImpl, @zfactory.linear_ring(points_), @mfactory.linear_ring(points_))
291
+ def linear_ring(points)
292
+ create_feature(ZMLinearRingImpl, @zfactory.linear_ring(points), @mfactory.linear_ring(points))
290
293
  end
291
294
 
292
295
  # See RGeo::Feature::Factory#polygon
293
296
 
294
- def polygon(outer_ring_, inner_rings_ = nil)
295
- _create_feature(ZMPolygonImpl, @zfactory.polygon(outer_ring_, inner_rings_), @mfactory.polygon(outer_ring_, inner_rings_))
297
+ def polygon(outer_ring, inner_rings = nil)
298
+ create_feature(ZMPolygonImpl, @zfactory.polygon(outer_ring, inner_rings), @mfactory.polygon(outer_ring, inner_rings))
296
299
  end
297
300
 
298
301
  # See RGeo::Feature::Factory#collection
299
302
 
300
- def collection(elems_)
301
- _create_feature(ZMGeometryCollectionImpl, @zfactory.collection(elems_), @mfactory.collection(elems_))
303
+ def collection(elems)
304
+ create_feature(ZMGeometryCollectionImpl, @zfactory.collection(elems), @mfactory.collection(elems))
302
305
  end
303
306
 
304
307
  # See RGeo::Feature::Factory#multi_point
305
308
 
306
- def multi_point(elems_)
307
- _create_feature(ZMMultiPointImpl, @zfactory.multi_point(elems_), @mfactory.multi_point(elems_))
309
+ def multi_point(elems)
310
+ create_feature(ZMMultiPointImpl, @zfactory.multi_point(elems), @mfactory.multi_point(elems))
308
311
  end
309
312
 
310
313
  # See RGeo::Feature::Factory#multi_line_string
311
314
 
312
- def multi_line_string(elems_)
313
- _create_feature(ZMMultiLineStringImpl, @zfactory.multi_line_string(elems_), @mfactory.multi_line_string(elems_))
315
+ def multi_line_string(elems)
316
+ create_feature(ZMMultiLineStringImpl, @zfactory.multi_line_string(elems), @mfactory.multi_line_string(elems))
314
317
  end
315
318
 
316
319
  # See RGeo::Feature::Factory#multi_polygon
317
320
 
318
- def multi_polygon(elems_)
319
- _create_feature(ZMMultiPolygonImpl, @zfactory.multi_polygon(elems_), @mfactory.multi_polygon(elems_))
321
+ def multi_polygon(elems)
322
+ create_feature(ZMMultiPolygonImpl, @zfactory.multi_polygon(elems), @mfactory.multi_polygon(elems))
320
323
  end
321
324
 
322
325
  # See RGeo::Feature::Factory#proj4
@@ -333,73 +336,56 @@ module RGeo
333
336
 
334
337
  # See RGeo::Feature::Factory#override_cast
335
338
 
336
- def override_cast(original_, ntype_, flags_)
337
- return nil unless Geos.supported?
338
- keep_subtype_ = flags_[:keep_subtype]
339
- # force_new_ = flags_[:force_new]
340
- project_ = flags_[:project]
341
- type_ = original_.geometry_type
342
- ntype_ = type_ if keep_subtype_ && type_.include?(ntype_)
343
- case original_
339
+ def override_cast(original, ntype, flags)
340
+ return unless Geos.supported?
341
+ keep_subtype = flags[:keep_subtype]
342
+ project = flags[:project]
343
+ type = original.geometry_type
344
+ ntype = type if keep_subtype && type.include?(ntype)
345
+ case original
344
346
  when ZMGeometryMethods
345
347
  # Optimization if we're just changing factories, but to
346
348
  # another ZM factory.
347
- if original_.factory != self && ntype_ == type_ &&
348
- (!project_ || original_.factory.proj4 == @proj4)
349
- zresult_ = original_.z_geometry.dup
350
- zresult_._set_factory(@zfactory)
351
- mresult_ = original_.m_geometry.dup
352
- mresult_._set_factory(@mfactory)
353
- return original_.class.create(self, zresult_, mresult_)
349
+ if original.factory != self && ntype == type &&
350
+ (!project || original.factory.proj4 == @proj4)
351
+ zresult = original.z_geometry.dup
352
+ zresult.factory = @zfactory
353
+ mresult = original.m_geometry.dup
354
+ mresult.factory = @mfactory
355
+ return original.class.create(self, zresult, mresult)
354
356
  end
355
357
  # LineString conversion optimization.
356
- if (original_.factory != self || ntype_ != type_) &&
357
- (!project_ || original_.factory.proj4 == @proj4) &&
358
- type_.subtype_of?(Feature::LineString) && ntype_.subtype_of?(Feature::LineString)
359
- klass_ = Factory::IMPL_CLASSES[ntype_]
360
- zresult_ = klass_._copy_from(@zfactory, original_.z_geometry)
361
- mresult_ = klass_._copy_from(@mfactory, original_.m_geometry)
362
- return ZMLineStringImpl.create(self, zresult_, mresult_)
358
+ if (original.factory != self || ntype != type) &&
359
+ (!project || original.factory.proj4 == @proj4) &&
360
+ type.subtypeof?(Feature::LineString) && ntype.subtypeof?(Feature::LineString)
361
+ klass = Factory::IMPL_CLASSES[ntype]
362
+ zresult = klass._copy_from(@zfactory, original.z_geometry)
363
+ mresult = klass._copy_from(@mfactory, original.m_geometry)
364
+ return ZMLineStringImpl.create(self, zresult, mresult)
363
365
  end
364
366
  end
365
367
  false
366
368
  end
367
369
 
368
- def _create_feature(klass_, zgeometry_, mgeometry_) # :nodoc:
369
- klass_ ||= TYPE_KLASSES[zgeometry_.geometry_type] || ZMGeometryImpl
370
- zgeometry_ && mgeometry_ ? klass_.new(self, zgeometry_, mgeometry_) : nil
370
+ def create_feature(klass, zgeometry, mgeometry) # :nodoc:
371
+ klass ||= TYPE_KLASSES[zgeometry.geometry_type] || ZMGeometryImpl
372
+ zgeometry && mgeometry ? klass.new(self, zgeometry, mgeometry) : nil
371
373
  end
372
374
 
373
- def _marshal_wkb_generator # :nodoc:
374
- unless defined?(@marshal_wkb_generator)
375
- @marshal_wkb_generator = RGeo::WKRep::WKBGenerator.new(
376
- type_format: :wkb12)
377
- end
378
- @marshal_wkb_generator
375
+ def marshal_wkb_generator
376
+ @marshal_wkb_generator ||= RGeo::WKRep::WKBGenerator.new(typeformat: :wkb12)
379
377
  end
380
378
 
381
- def _marshal_wkb_parser # :nodoc:
382
- unless defined?(@marshal_wkb_parser)
383
- @marshal_wkb_parser = RGeo::WKRep::WKBParser.new(self,
384
- support_wkb12: true)
385
- end
386
- @marshal_wkb_parser
379
+ def marshal_wkb_parser
380
+ @marshal_wkb_parser ||= RGeo::WKRep::WKBParser.new(self, support_wkb12: true)
387
381
  end
388
382
 
389
- def _psych_wkt_generator # :nodoc:
390
- unless defined?(@psych_wkt_generator)
391
- @psych_wkt_generator = RGeo::WKRep::WKTGenerator.new(
392
- tag_format: :wkt12)
393
- end
394
- @psych_wkt_generator
383
+ def psych_wkt_generator
384
+ @psych_wkt_generator ||= RGeo::WKRep::WKTGenerator.new(tag_format: :wkt12)
395
385
  end
396
386
 
397
- def _psych_wkt_parser # :nodoc:
398
- unless defined?(@psych_wkt_parser)
399
- @psych_wkt_parser = RGeo::WKRep::WKTParser.new(self,
400
- support_wkt12: true, support_ewkt: true)
401
- end
402
- @psych_wkt_parser
387
+ def psych_wkt_parser
388
+ @psych_wkt_parser ||= RGeo::WKRep::WKTParser.new(self, support_wkt12: true, support_ewkt: true)
403
389
  end
404
390
  end
405
391
  end