rgeo 2.3.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +6 -0
  3. data/README.md +23 -14
  4. data/ext/geos_c_impl/analysis.c +30 -25
  5. data/ext/geos_c_impl/analysis.h +8 -7
  6. data/ext/geos_c_impl/coordinates.c +27 -21
  7. data/ext/geos_c_impl/coordinates.h +5 -2
  8. data/ext/geos_c_impl/errors.c +19 -10
  9. data/ext/geos_c_impl/errors.h +11 -4
  10. data/ext/geos_c_impl/extconf.rb +42 -28
  11. data/ext/geos_c_impl/factory.c +540 -451
  12. data/ext/geos_c_impl/factory.h +105 -95
  13. data/ext/geos_c_impl/geometry.c +593 -387
  14. data/ext/geos_c_impl/geometry.h +10 -5
  15. data/ext/geos_c_impl/geometry_collection.c +306 -339
  16. data/ext/geos_c_impl/geometry_collection.h +6 -20
  17. data/ext/geos_c_impl/globals.c +169 -0
  18. data/ext/geos_c_impl/globals.h +46 -0
  19. data/ext/geos_c_impl/line_string.c +271 -231
  20. data/ext/geos_c_impl/line_string.h +5 -8
  21. data/ext/geos_c_impl/main.c +16 -16
  22. data/ext/geos_c_impl/point.c +65 -67
  23. data/ext/geos_c_impl/point.h +4 -7
  24. data/ext/geos_c_impl/polygon.c +137 -135
  25. data/ext/geos_c_impl/polygon.h +11 -11
  26. data/ext/geos_c_impl/preface.h +16 -10
  27. data/ext/geos_c_impl/ruby_more.c +67 -0
  28. data/ext/geos_c_impl/ruby_more.h +25 -0
  29. data/lib/rgeo/cartesian/analysis.rb +5 -3
  30. data/lib/rgeo/cartesian/bounding_box.rb +74 -79
  31. data/lib/rgeo/cartesian/calculations.rb +64 -33
  32. data/lib/rgeo/cartesian/factory.rb +57 -102
  33. data/lib/rgeo/cartesian/feature_classes.rb +68 -46
  34. data/lib/rgeo/cartesian/feature_methods.rb +67 -25
  35. data/lib/rgeo/cartesian/interface.rb +6 -41
  36. data/lib/rgeo/cartesian/planar_graph.rb +373 -0
  37. data/lib/rgeo/cartesian/sweepline_intersector.rb +147 -0
  38. data/lib/rgeo/cartesian/valid_op.rb +69 -0
  39. data/lib/rgeo/cartesian.rb +3 -0
  40. data/lib/rgeo/coord_sys/cs/entities.rb +303 -99
  41. data/lib/rgeo/coord_sys/cs/factories.rb +0 -2
  42. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +90 -42
  43. data/lib/rgeo/coord_sys.rb +1 -20
  44. data/lib/rgeo/error.rb +15 -0
  45. data/lib/rgeo/feature/curve.rb +0 -11
  46. data/lib/rgeo/feature/factory.rb +26 -36
  47. data/lib/rgeo/feature/factory_generator.rb +6 -14
  48. data/lib/rgeo/feature/geometry.rb +146 -66
  49. data/lib/rgeo/feature/geometry_collection.rb +16 -9
  50. data/lib/rgeo/feature/line_string.rb +4 -5
  51. data/lib/rgeo/feature/linear_ring.rb +0 -1
  52. data/lib/rgeo/feature/multi_curve.rb +0 -6
  53. data/lib/rgeo/feature/multi_surface.rb +3 -4
  54. data/lib/rgeo/feature/point.rb +4 -5
  55. data/lib/rgeo/feature/polygon.rb +1 -2
  56. data/lib/rgeo/feature/surface.rb +3 -4
  57. data/lib/rgeo/feature/types.rb +69 -85
  58. data/lib/rgeo/geographic/factory.rb +98 -125
  59. data/lib/rgeo/geographic/interface.rb +69 -166
  60. data/lib/rgeo/geographic/projected_feature_classes.rb +21 -9
  61. data/lib/rgeo/geographic/projected_feature_methods.rb +67 -42
  62. data/lib/rgeo/geographic/projected_window.rb +36 -22
  63. data/lib/rgeo/geographic/{proj4_projector.rb → projector.rb} +3 -5
  64. data/lib/rgeo/geographic/simple_mercator_projector.rb +26 -25
  65. data/lib/rgeo/geographic/spherical_feature_classes.rb +29 -9
  66. data/lib/rgeo/geographic/spherical_feature_methods.rb +86 -9
  67. data/lib/rgeo/geographic/spherical_math.rb +17 -20
  68. data/lib/rgeo/geographic.rb +1 -1
  69. data/lib/rgeo/geos/capi_factory.rb +87 -158
  70. data/lib/rgeo/geos/capi_feature_classes.rb +50 -36
  71. data/lib/rgeo/geos/ffi_factory.rb +105 -173
  72. data/lib/rgeo/geos/ffi_feature_classes.rb +34 -10
  73. data/lib/rgeo/geos/ffi_feature_methods.rb +105 -127
  74. data/lib/rgeo/geos/interface.rb +20 -59
  75. data/lib/rgeo/geos/utils.rb +5 -5
  76. data/lib/rgeo/geos/zm_factory.rb +53 -95
  77. data/lib/rgeo/geos/zm_feature_methods.rb +30 -33
  78. data/lib/rgeo/geos.rb +8 -8
  79. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +9 -22
  80. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +1 -2
  81. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +28 -56
  82. data/lib/rgeo/impl_helper/basic_point_methods.rb +2 -14
  83. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +17 -26
  84. data/lib/rgeo/impl_helper/utils.rb +21 -0
  85. data/lib/rgeo/impl_helper/valid_op.rb +350 -0
  86. data/lib/rgeo/impl_helper/validity_check.rb +139 -0
  87. data/lib/rgeo/impl_helper.rb +1 -0
  88. data/lib/rgeo/version.rb +1 -1
  89. data/lib/rgeo/wkrep/wkb_generator.rb +73 -63
  90. data/lib/rgeo/wkrep/wkb_parser.rb +33 -31
  91. data/lib/rgeo/wkrep/wkt_generator.rb +52 -45
  92. data/lib/rgeo/wkrep/wkt_parser.rb +48 -35
  93. data/lib/rgeo.rb +1 -3
  94. metadata +50 -13
  95. data/lib/rgeo/coord_sys/srs_database/entry.rb +0 -107
  96. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +0 -64
  97. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +0 -65
@@ -34,7 +34,6 @@ module RGeo
34
34
  # class method (or === operator) defined in the Type module.
35
35
  #
36
36
  # Some implementations may support higher dimensional points.
37
-
38
37
  module Surface
39
38
  include Geometry
40
39
  extend Type
@@ -49,7 +48,7 @@ module RGeo
49
48
  # Returns a floating-point scalar value.
50
49
 
51
50
  def area
52
- raise Error::UnsupportedOperation, "Method Surface#area not defined."
51
+ raise Error::UnsupportedOperation, "Method #{self.class.name}#area not defined."
53
52
  end
54
53
 
55
54
  # === SFS 1.1 Description
@@ -62,7 +61,7 @@ module RGeo
62
61
  # Returns an object that supports the Point interface.
63
62
 
64
63
  def centroid
65
- raise Error::UnsupportedOperation, "Method Surface#centroid not defined."
64
+ raise Error::UnsupportedOperation, "Method #{self.class.name}#centroid not defined."
66
65
  end
67
66
 
68
67
  # === SFS 1.1 Description
@@ -74,7 +73,7 @@ module RGeo
74
73
  # Returns an object that supports the Point interface.
75
74
 
76
75
  def point_on_surface
77
- raise Error::UnsupportedOperation, "Method Surface#point_on_surface not defined."
76
+ raise Error::UnsupportedOperation, "Method #{self.class.name}#point_on_surface not defined."
78
77
  end
79
78
  end
80
79
  end
@@ -11,7 +11,6 @@ module RGeo
11
11
  # All geometry implementations MUST include this submodule.
12
12
  # This serves as a marker that may be used to test an object for
13
13
  # feature-ness.
14
-
15
14
  module Instance
16
15
  end
17
16
 
@@ -49,7 +48,6 @@ module RGeo
49
48
  # a particular object is a feature type:
50
49
  #
51
50
  # RGeo::Feature::Type === object.geometry_type # true
52
-
53
51
  module Type
54
52
  # Returns true if the given object is this type or a subtype
55
53
  # thereof, or if it is a feature object whose geometry_type is
@@ -192,92 +190,78 @@ module RGeo
192
190
  # Types are the same
193
191
  if nfactory == factory
194
192
  force_new ? obj.dup : obj
195
- else
196
- if type == Point
197
- proj = nproj = nil
198
- if project
199
- proj = factory.proj4
200
- nproj = nfactory.proj4
201
- end
202
- hasz = factory.property(:has_z_coordinate)
203
- nhasz = nfactory.property(:has_z_coordinate)
204
- if proj && nproj && CoordSys.check!(:proj4)
205
- coords = CoordSys::Proj4.transform_coords(proj, nproj, obj.x, obj.y, hasz ? obj.z : nil)
206
- coords << (hasz ? obj.z : 0.0) if nhasz && coords.size < 3
207
- else
208
- coords = [obj.x, obj.y]
209
- coords << (hasz ? obj.z : 0.0) if nhasz
210
- end
211
- coords << (factory.property(:has_m_coordinate) ? obj.m : 0.0) if nfactory.property(:has_m_coordinate)
212
- nfactory.point(*coords)
213
- elsif type == Line
214
- nfactory.line(cast(obj.start_point, nfactory, opts), cast(obj.end_point, nfactory, opts))
215
- elsif type == LinearRing
216
- nfactory.linear_ring(obj.points.map { |p| cast(p, nfactory, opts) })
217
- elsif type == LineString
218
- nfactory.line_string(obj.points.map { |p| cast(p, nfactory, opts) })
219
- elsif type == Polygon
220
- nfactory.polygon(cast(obj.exterior_ring, nfactory, opts),
221
- obj.interior_rings.map { |r| cast(r, nfactory, opts) })
222
- elsif type == MultiPoint
223
- nfactory.multi_point(obj.map { |g| cast(g, nfactory, opts) })
224
- elsif type == MultiLineString
225
- nfactory.multi_line_string(obj.map { |g| cast(g, nfactory, opts) })
226
- elsif type == MultiPolygon
227
- nfactory.multi_polygon(obj.map { |g| cast(g, nfactory, opts) })
228
- elsif type == GeometryCollection
229
- nfactory.collection(obj.map { |g| cast(g, nfactory, opts) })
230
- end
193
+ elsif type == Point
194
+ z = factory.property(:has_z_coordinate) ? obj.z : nil
195
+ coords = if project && (cs = factory.coord_sys) && (ncs = nfactory.coord_sys)
196
+ cs.transform_coords(ncs, obj.x, obj.y, z)
197
+ else
198
+ [obj.x, obj.y]
199
+ end
200
+ coords << (z || 0.0) if nfactory.property(:has_z_coordinate) && coords.size < 3
201
+ m = factory.property(:has_m_coordinate) ? obj.m : nil
202
+ coords << (m || 0.0) if nfactory.property(:has_m_coordinate)
203
+ nfactory.point(*coords)
204
+ elsif type == Line
205
+ nfactory.line(cast(obj.start_point, nfactory, opts), cast(obj.end_point, nfactory, opts))
206
+ elsif type == LinearRing
207
+ nfactory.linear_ring(obj.points.map { |p| cast(p, nfactory, opts) })
208
+ elsif type == LineString
209
+ nfactory.line_string(obj.points.map { |p| cast(p, nfactory, opts) })
210
+ elsif type == Polygon
211
+ nfactory.polygon(
212
+ cast(obj.exterior_ring, nfactory, opts),
213
+ obj.interior_rings.map { |r| cast(r, nfactory, opts) }
214
+ )
215
+ elsif type == MultiPoint
216
+ nfactory.multi_point(obj.map { |g| cast(g, nfactory, opts) })
217
+ elsif type == MultiLineString
218
+ nfactory.multi_line_string(obj.map { |g| cast(g, nfactory, opts) })
219
+ elsif type == MultiPolygon
220
+ nfactory.multi_polygon(obj.map { |g| cast(g, nfactory, opts) })
221
+ elsif type == GeometryCollection
222
+ nfactory.collection(obj.map { |g| cast(g, nfactory, opts) })
231
223
  end
232
- else
233
- # Types are different
234
- if ntype == Point && (type == MultiPoint || type == GeometryCollection) ||
235
- (ntype == Line || ntype == LineString || ntype == LinearRing) && (type == MultiLineString || type == GeometryCollection) ||
236
- ntype == Polygon && (type == MultiPolygon || type == GeometryCollection)
237
- if obj.num_geometries == 1
238
- cast(obj.geometry_n(0), nfactory, ntype, opts)
239
- end
240
- elsif ntype == Point
241
- raise(Error::InvalidGeometry, "Cannot cast to Point")
242
- elsif ntype == Line
243
- if type == LineString && obj.num_points == 2
244
- nfactory.line(cast(obj.point_n(0), nfactory, opts), cast(obj.point_n(1), nfactory, opts))
245
- end
246
- elsif ntype == LinearRing
247
- if type == LineString
248
- nfactory.linear_ring(obj.points.map { |p| cast(p, nfactory, opts) })
249
- end
250
- elsif ntype == LineString
251
- if type == Line || type == LinearRing
252
- nfactory.line_string(obj.points.map { |p| cast(p, nfactory, opts) })
253
- end
254
- elsif ntype == MultiPoint
255
- if type == Point
256
- nfactory.multi_point([cast(obj, nfactory, opts)])
257
- elsif type == GeometryCollection
258
- nfactory.multi_point(obj.map { |p| cast(p, nfactory, opts) })
259
- end
260
- elsif ntype == MultiLineString
261
- if type == Line || type == LinearRing || type == LineString
262
- nfactory.multi_line_string([cast(obj, nfactory, opts)])
263
- elsif type == GeometryCollection
264
- nfactory.multi_line_string(obj.map { |p| cast(p, nfactory, opts) })
265
- end
266
- elsif ntype == MultiPolygon
267
- if type == Polygon
268
- nfactory.multi_polygon([cast(obj, nfactory, opts)])
269
- elsif type == GeometryCollection
270
- nfactory.multi_polygon(obj.map { |p| cast(p, nfactory, opts) })
271
- end
272
- elsif ntype == GeometryCollection
273
- if type == MultiPoint || type == MultiLineString || type == MultiPolygon
274
- nfactory.collection(obj.map { |p| cast(p, nfactory, opts) })
275
- else
276
- nfactory.collection([cast(obj, nfactory, opts)])
277
- end
224
+ # Types are different
225
+ elsif ntype == Point && [MultiPoint, GeometryCollection].include?(type) ||
226
+ [Line, LineString, LinearRing].include?(ntype) && [MultiLineString, GeometryCollection].include?(type) ||
227
+ ntype == Polygon && [MultiPolygon, GeometryCollection].include?(type)
228
+ cast(obj.geometry_n(0), nfactory, ntype, opts) if obj.num_geometries == 1
229
+ elsif ntype == Point
230
+ raise(Error::InvalidGeometry, "Cannot cast to Point")
231
+ elsif ntype == Line
232
+ if type == LineString && obj.num_points == 2
233
+ nfactory.line(cast(obj.point_n(0), nfactory, opts), cast(obj.point_n(1), nfactory, opts))
234
+ end
235
+ elsif ntype == LinearRing
236
+ nfactory.linear_ring(obj.points.map { |p| cast(p, nfactory, opts) }) if type == LineString
237
+ elsif ntype == LineString
238
+ nfactory.line_string(obj.points.map { |p| cast(p, nfactory, opts) }) if [Line, LinearRing].include?(type)
239
+ elsif ntype == MultiPoint
240
+ if type == Point
241
+ nfactory.multi_point([cast(obj, nfactory, opts)])
242
+ elsif type == GeometryCollection
243
+ nfactory.multi_point(obj.map { |p| cast(p, nfactory, opts) })
244
+ end
245
+ elsif ntype == MultiLineString
246
+ if [Line, LinearRing, LineString].include?(type)
247
+ nfactory.multi_line_string([cast(obj, nfactory, opts)])
248
+ elsif type == GeometryCollection
249
+ nfactory.multi_line_string(obj.map { |p| cast(p, nfactory, opts) })
250
+ end
251
+ elsif ntype == MultiPolygon
252
+ if type == Polygon
253
+ nfactory.multi_polygon([cast(obj, nfactory, opts)])
254
+ elsif type == GeometryCollection
255
+ nfactory.multi_polygon(obj.map { |p| cast(p, nfactory, opts) })
256
+ end
257
+ elsif ntype == GeometryCollection
258
+ if [MultiPoint, MultiLineString, MultiPolygon].include?(type)
259
+ nfactory.collection(obj.map { |p| cast(p, nfactory, opts) })
278
260
  else
279
- raise(RGeo::Error::InvalidGeometry, "Undefined type cast from #{type.name} to #{ntype.name}")
261
+ nfactory.collection([cast(obj, nfactory, opts)])
280
262
  end
263
+ else
264
+ raise(RGeo::Error::InvalidGeometry, "Undefined type cast from #{type.name} to #{ntype.name}")
281
265
  end
282
266
  end
283
267
  end
@@ -11,13 +11,20 @@ module RGeo
11
11
  # This class implements the various factories for geography features.
12
12
  # See methods of the RGeo::Geographic module for the API for creating
13
13
  # geography factories.
14
-
15
14
  class Factory
16
15
  include Feature::Factory::Instance
17
16
  include ImplHelper::Utils
18
17
 
19
18
  attr_writer :projector
20
19
 
20
+ attr_reader :coordinate_dimension, :spatial_dimension
21
+
22
+ # Returns the srid reported by this factory.
23
+ attr_reader :srid
24
+
25
+ # See RGeo::Feature::Factory#coord_sys
26
+ attr_reader :coord_sys
27
+
21
28
  def initialize(impl_prefix, opts = {}) # :nodoc:
22
29
  @impl_prefix = impl_prefix
23
30
  @point_class = Geographic.const_get("#{impl_prefix}PointImpl")
@@ -31,67 +38,69 @@ module RGeo
31
38
  @multi_polygon_class = Geographic.const_get("#{impl_prefix}MultiPolygonImpl")
32
39
  @support_z = opts[:has_z_coordinate] ? true : false
33
40
  @support_m = opts[:has_m_coordinate] ? true : false
34
- @srid = (opts[:srid] || 4326).to_i
35
- @proj4 = opts[:proj4]
36
- if @proj4 && CoordSys.check!(:proj4)
37
- if @proj4.is_a?(String) || @proj4.is_a?(Hash)
38
- @proj4 = CoordSys::Proj4.create(@proj4)
39
- end
40
- end
41
- @coord_sys = opts[:coord_sys]
42
- if @coord_sys.is_a?(String)
43
- @coord_sys = CoordSys::CS.create_from_wkt(@coord_sys)
44
- end
45
- @lenient_assertions = opts[:uses_lenient_assertions] ? true : false
41
+ @coordinate_dimension = 2
42
+ @coordinate_dimension += 1 if @support_z
43
+ @coordinate_dimension += 1 if @support_m
44
+ @spatial_dimension = @support_z ? 3 : 2
45
+
46
+ srid = opts.fetch(:srid, 4326).to_i
47
+ coord_sys_info = ImplHelper::Utils.setup_coord_sys(srid, opts[:coord_sys], opts[:coord_sys_class])
48
+ @coord_sys = coord_sys_info[:coord_sys]
49
+ @srid = coord_sys_info[:srid]
50
+
46
51
  @buffer_resolution = opts[:buffer_resolution].to_i
47
52
  @buffer_resolution = 1 if @buffer_resolution < 1
48
53
 
49
54
  wkt_generator = opts[:wkt_generator]
50
- case wkt_generator
51
- when Hash
52
- @wkt_generator = WKRep::WKTGenerator.new(wkt_generator)
53
- else
54
- @wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper)
55
- end
55
+ @wkt_generator =
56
+ case wkt_generator
57
+ when Hash
58
+ WKRep::WKTGenerator.new(wkt_generator)
59
+ else
60
+ WKRep::WKTGenerator.new(convert_case: :upper)
61
+ end
56
62
  wkb_generator = opts[:wkb_generator]
57
- case wkb_generator
58
- when Hash
59
- @wkb_generator = WKRep::WKBGenerator.new(wkb_generator)
60
- else
61
- @wkb_generator = WKRep::WKBGenerator.new
62
- end
63
+ @wkb_generator =
64
+ case wkb_generator
65
+ when Hash
66
+ WKRep::WKBGenerator.new(wkb_generator)
67
+ else
68
+ WKRep::WKBGenerator.new
69
+ end
63
70
  wkt_parser = opts[:wkt_parser]
64
- case wkt_parser
65
- when Hash
66
- @wkt_parser = WKRep::WKTParser.new(self, wkt_parser)
67
- else
68
- @wkt_parser = WKRep::WKTParser.new(self)
69
- end
71
+ @wkt_parser =
72
+ case wkt_parser
73
+ when Hash
74
+ WKRep::WKTParser.new(self, wkt_parser)
75
+ else
76
+ WKRep::WKTParser.new(self)
77
+ end
70
78
  wkb_parser = opts[:wkb_parser]
71
- case wkb_parser
72
- when Hash
73
- @wkb_parser = WKRep::WKBParser.new(self, wkb_parser)
74
- else
75
- @wkb_parser = WKRep::WKBParser.new(self)
76
- end
79
+ @wkb_parser =
80
+ case wkb_parser
81
+ when Hash
82
+ WKRep::WKBParser.new(self, wkb_parser)
83
+ else
84
+ WKRep::WKBParser.new(self)
85
+ end
77
86
  @projector = nil
78
87
  end
79
88
 
80
89
  # Equivalence test.
81
90
 
82
- def eql?(rhs_)
83
- rhs_.is_a?(Geographic::Factory) &&
84
- @impl_prefix == rhs_.instance_variable_get(:@impl_prefix) &&
85
- @support_z == rhs_.instance_variable_get(:@support_z) &&
86
- @support_m == rhs_.instance_variable_get(:@support_m) &&
87
- @proj4 == rhs_.instance_variable_get(:@proj4)
91
+ def eql?(other)
92
+ other.is_a?(Geographic::Factory) &&
93
+ @impl_prefix == other.instance_variable_get(:@impl_prefix) &&
94
+ @support_z == other.instance_variable_get(:@support_z) &&
95
+ @support_m == other.instance_variable_get(:@support_m) &&
96
+ @coord_sys == other.instance_variable_get(:@coord_sys)
88
97
  end
89
98
  alias == eql?
90
99
 
91
100
  # Standard hash code
92
101
 
93
102
  def hash
94
- @hash ||= [@impl_prefix, @support_z, @support_m, @proj4].hash
103
+ @hash ||= [@impl_prefix, @support_z, @support_m, @coord_sys].hash
95
104
  end
96
105
 
97
106
  # Marshal support
@@ -106,10 +115,8 @@ module RGeo
106
115
  "wkbg" => @wkb_generator.properties,
107
116
  "wktp" => @wkt_parser.properties,
108
117
  "wkbp" => @wkb_parser.properties,
109
- "lena" => @lenient_assertions,
110
118
  "bufr" => @buffer_resolution
111
119
  }
112
- hash_["proj4"] = @proj4.marshal_dump if @proj4
113
120
  hash_["cs"] = @coord_sys.to_wkt if @coord_sys
114
121
  if @projector
115
122
  hash_["prjc"] = @projector.class.name.sub(/.*::/, "")
@@ -119,18 +126,11 @@ module RGeo
119
126
  end
120
127
 
121
128
  def marshal_load(data_) # :nodoc:
122
- if (proj4_data = data_["proj4"]) && CoordSys.check!(:proj4)
123
- proj4 = CoordSys::Proj4.allocate
124
- proj4.marshal_load(proj4_data)
125
- else
126
- proj4 = nil
127
- end
128
- if (coord_sys_data = data_["cs"])
129
- coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data)
130
- else
131
- coord_sys = nil
132
- end
133
- initialize(data_["pref"],
129
+ cs_class = CoordSys::CONFIG.default_coord_sys_class
130
+ coord_sys = data_["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
131
+
132
+ initialize(
133
+ data_["pref"],
134
134
  has_z_coordinate: data_["hasz"],
135
135
  has_m_coordinate: data_["hasm"],
136
136
  srid: data_["srid"],
@@ -138,19 +138,21 @@ module RGeo
138
138
  wkb_generator: symbolize_hash(data_["wkbg"]),
139
139
  wkt_parser: symbolize_hash(data_["wktp"]),
140
140
  wkb_parser: symbolize_hash(data_["wkbp"]),
141
- uses_lenient_assertions: data_["lena"],
142
141
  buffer_resolution: data_["bufr"],
143
- proj4: proj4,
144
142
  coord_sys: coord_sys
145
143
  )
146
- if (proj_klass = data_["prjc"]) && (proj_factory = data_["prjf"])
147
- klass_ = RGeo::Geographic.const_get(proj_klass)
148
- if klass_
149
- projector = klass_.allocate
150
- projector.set_factories(self, proj_factory)
151
- @projector = projector
152
- end
153
- end
144
+ proj_klass = data_["prjc"]
145
+ proj_factory = data_["prjf"]
146
+
147
+ return unless proj_klass && proj_factory
148
+
149
+ klass_ = RGeo::Geographic.const_get(proj_klass)
150
+
151
+ return unless klass_
152
+
153
+ projector = klass_.allocate
154
+ projector.set_factories(self, proj_factory)
155
+ @projector = projector
154
156
  end
155
157
 
156
158
  # Psych support
@@ -164,36 +166,21 @@ module RGeo
164
166
  coder["wkb_generator"] = @wkb_generator.properties
165
167
  coder["wkt_parser"] = @wkt_parser.properties
166
168
  coder["wkb_parser"] = @wkb_parser.properties
167
- coder["lenient_assertions"] = @lenient_assertions
168
169
  coder["buffer_resolution"] = @buffer_resolution
169
- if @proj4
170
- str = @proj4.original_str || @proj4.canonical_str
171
- coder["proj4"] = @proj4.radians? ? { "proj4" => str, "radians" => true } : str
172
- end
173
170
  coder["coord_sys"] = @coord_sys.to_wkt if @coord_sys
174
- if @projector
175
- coder["projectorclass"] = @projector.class.name.sub(/.*::/, "")
176
- coder["projection_factory"] = @projector.projection_factory
177
- end
171
+
172
+ return unless @projector
173
+
174
+ coder["projectorclass"] = @projector.class.name.sub(/.*::/, "")
175
+ coder["projection_factory"] = @projector.projection_factory
178
176
  end
179
177
 
180
178
  def init_with(coder) # :nodoc:
181
- if (proj4_data = coder["proj4"])
182
- CoordSys.check!(:proj4)
183
- if proj4_data.is_a?(Hash)
184
- proj4 = CoordSys::Proj4.create(proj4_data["proj4"], radians: proj4_data["radians"])
185
- else
186
- proj4 = CoordSys::Proj4.create(proj4_data.to_s)
187
- end
188
- else
189
- proj4 = nil
190
- end
191
- if (coord_sys_data = coder["cs"])
192
- coord_sys = CoordSys::CS.create_from_wkt(coord_sys_data.to_s)
193
- else
194
- coord_sys = nil
195
- end
196
- initialize(coder["impl_prefix"],
179
+ cs_class = CoordSys::CONFIG.default_coord_sys_class
180
+ coord_sys = coder["cs"]&.then { |cs| cs_class.create_from_wkt(cs) }
181
+
182
+ initialize(
183
+ coder["impl_prefix"],
197
184
  has_z_coordinate: coder["has_z_coordinate"],
198
185
  has_m_coordinate: coder["has_m_coordinate"],
199
186
  srid: coder["srid"],
@@ -201,24 +188,22 @@ module RGeo
201
188
  wkb_generator: symbolize_hash(coder["wkb_generator"]),
202
189
  wkt_parser: symbolize_hash(coder["wkt_parser"]),
203
190
  wkb_parser: symbolize_hash(coder["wkb_parser"]),
204
- uses_lenient_assertions: coder["lenient_assertions"],
205
191
  buffer_resolution: coder["buffer_resolution"],
206
- proj4: proj4,
207
192
  coord_sys: coord_sys
208
193
  )
209
- if (proj_klass = coder["projectorclass"]) && (proj_factory = coder["projection_factory"])
210
- klass_ = RGeo::Geographic.const_get(proj_klass)
211
- if klass_
212
- projector = klass_.allocate
213
- projector.set_factories(self, proj_factory)
214
- @projector = projector
215
- end
216
- end
217
- end
194
+ proj_klass = coder["projectorclass"]
195
+ proj_factory = coder["projection_factory"]
218
196
 
219
- # Returns the srid reported by this factory.
197
+ return unless proj_klass && proj_factory
220
198
 
221
- attr_reader :srid
199
+ klass_ = RGeo::Geographic.const_get(proj_klass)
200
+
201
+ return unless klass_
202
+
203
+ projector = klass_.allocate
204
+ projector.set_factories(self, proj_factory)
205
+ @projector = projector
206
+ end
222
207
 
223
208
  # Returns true if this factory supports a projection.
224
209
 
@@ -241,9 +226,7 @@ module RGeo
241
226
 
242
227
  def project(geometry)
243
228
  return unless @projector && geometry
244
- unless geometry.factory == self
245
- raise Error::InvalidGeometry, "Wrong geometry type"
246
- end
229
+ raise Error::InvalidGeometry, "Wrong geometry type" unless geometry.factory == self
247
230
  @projector.project(geometry)
248
231
  end
249
232
 
@@ -254,9 +237,11 @@ module RGeo
254
237
 
255
238
  def unproject(geometry)
256
239
  return unless geometry
240
+
257
241
  unless @projector && @projector.projection_factory == geometry.factory
258
242
  raise Error::InvalidGeometry, "You can unproject only features that are in the projected coordinate space."
259
243
  end
244
+
260
245
  @projector.unproject(geometry)
261
246
  end
262
247
 
@@ -277,12 +262,10 @@ module RGeo
277
262
  # projection limits are not known.
278
263
 
279
264
  def projection_limits_window
280
- if @projector
281
- unless defined?(@projection_limits_window)
282
- @projection_limits_window = @projector.limits_window
283
- end
284
- @projection_limits_window
285
- end
265
+ return @projection_limits_window if defined?(@projection_limits_window)
266
+ return unless @projector
267
+
268
+ @projection_limits_window = @projector.limits_window
286
269
  end
287
270
 
288
271
  # See RGeo::Feature::Factory#property
@@ -293,8 +276,6 @@ module RGeo
293
276
  @support_z
294
277
  when :has_m_coordinate
295
278
  @support_m
296
- when :uses_lenient_assertions
297
- @lenient_assertions
298
279
  when :buffer_resolution
299
280
  @buffer_resolution
300
281
  when :is_geographic
@@ -368,14 +349,6 @@ module RGeo
368
349
  @multi_polygon_class.new(self, elems)
369
350
  end
370
351
 
371
- # See RGeo::Feature::Factory#proj4
372
-
373
- attr_reader :proj4
374
-
375
- # See RGeo::Feature::Factory#coord_sys
376
-
377
- attr_reader :coord_sys
378
-
379
352
  def generate_wkt(obj)
380
353
  @wkt_generator.generate(obj)
381
354
  end