rgeo-dschee 0.5.4

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 (176) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +29 -0
  3. data/ext/geos_c_impl/coordinates.c +65 -0
  4. data/ext/geos_c_impl/coordinates.h +2 -0
  5. data/ext/geos_c_impl/extconf.rb +43 -0
  6. data/ext/geos_c_impl/factory.c +995 -0
  7. data/ext/geos_c_impl/factory.h +238 -0
  8. data/ext/geos_c_impl/geometry.c +1093 -0
  9. data/ext/geos_c_impl/geometry.h +23 -0
  10. data/ext/geos_c_impl/geometry_collection.c +757 -0
  11. data/ext/geos_c_impl/geometry_collection.h +46 -0
  12. data/ext/geos_c_impl/line_string.c +675 -0
  13. data/ext/geos_c_impl/line_string.h +32 -0
  14. data/ext/geos_c_impl/main.c +40 -0
  15. data/ext/geos_c_impl/point.c +236 -0
  16. data/ext/geos_c_impl/point.h +30 -0
  17. data/ext/geos_c_impl/polygon.c +359 -0
  18. data/ext/geos_c_impl/polygon.h +43 -0
  19. data/ext/geos_c_impl/preface.h +38 -0
  20. data/ext/proj4_c_impl/extconf.rb +62 -0
  21. data/ext/proj4_c_impl/main.c +315 -0
  22. data/lib/rgeo.rb +89 -0
  23. data/lib/rgeo/cartesian.rb +25 -0
  24. data/lib/rgeo/cartesian/analysis.rb +77 -0
  25. data/lib/rgeo/cartesian/bounding_box.rb +398 -0
  26. data/lib/rgeo/cartesian/calculations.rb +113 -0
  27. data/lib/rgeo/cartesian/factory.rb +347 -0
  28. data/lib/rgeo/cartesian/feature_classes.rb +100 -0
  29. data/lib/rgeo/cartesian/feature_methods.rb +88 -0
  30. data/lib/rgeo/cartesian/interface.rb +135 -0
  31. data/lib/rgeo/coord_sys.rb +43 -0
  32. data/lib/rgeo/coord_sys/cs/entities.rb +1315 -0
  33. data/lib/rgeo/coord_sys/cs/factories.rb +148 -0
  34. data/lib/rgeo/coord_sys/cs/wkt_parser.rb +272 -0
  35. data/lib/rgeo/coord_sys/proj4.rb +293 -0
  36. data/lib/rgeo/coord_sys/srs_database/interface.rb +115 -0
  37. data/lib/rgeo/coord_sys/srs_database/proj4_data.rb +140 -0
  38. data/lib/rgeo/coord_sys/srs_database/sr_org.rb +62 -0
  39. data/lib/rgeo/coord_sys/srs_database/url_reader.rb +63 -0
  40. data/lib/rgeo/error.rb +27 -0
  41. data/lib/rgeo/feature.rb +54 -0
  42. data/lib/rgeo/feature/curve.rb +111 -0
  43. data/lib/rgeo/feature/factory.rb +278 -0
  44. data/lib/rgeo/feature/factory_generator.rb +96 -0
  45. data/lib/rgeo/feature/geometry.rb +624 -0
  46. data/lib/rgeo/feature/geometry_collection.rb +95 -0
  47. data/lib/rgeo/feature/line.rb +26 -0
  48. data/lib/rgeo/feature/line_string.rb +60 -0
  49. data/lib/rgeo/feature/linear_ring.rb +26 -0
  50. data/lib/rgeo/feature/mixins.rb +143 -0
  51. data/lib/rgeo/feature/multi_curve.rb +71 -0
  52. data/lib/rgeo/feature/multi_line_string.rb +26 -0
  53. data/lib/rgeo/feature/multi_point.rb +33 -0
  54. data/lib/rgeo/feature/multi_polygon.rb +57 -0
  55. data/lib/rgeo/feature/multi_surface.rb +73 -0
  56. data/lib/rgeo/feature/point.rb +84 -0
  57. data/lib/rgeo/feature/polygon.rb +97 -0
  58. data/lib/rgeo/feature/surface.rb +79 -0
  59. data/lib/rgeo/feature/types.rb +284 -0
  60. data/lib/rgeo/geographic.rb +40 -0
  61. data/lib/rgeo/geographic/factory.rb +450 -0
  62. data/lib/rgeo/geographic/interface.rb +489 -0
  63. data/lib/rgeo/geographic/proj4_projector.rb +58 -0
  64. data/lib/rgeo/geographic/projected_feature_classes.rb +107 -0
  65. data/lib/rgeo/geographic/projected_feature_methods.rb +212 -0
  66. data/lib/rgeo/geographic/projected_window.rb +383 -0
  67. data/lib/rgeo/geographic/simple_mercator_projector.rb +110 -0
  68. data/lib/rgeo/geographic/spherical_feature_classes.rb +100 -0
  69. data/lib/rgeo/geographic/spherical_feature_methods.rb +134 -0
  70. data/lib/rgeo/geographic/spherical_math.rb +188 -0
  71. data/lib/rgeo/geos.rb +89 -0
  72. data/lib/rgeo/geos/capi_factory.rb +470 -0
  73. data/lib/rgeo/geos/capi_feature_classes.rb +129 -0
  74. data/lib/rgeo/geos/ffi_factory.rb +592 -0
  75. data/lib/rgeo/geos/ffi_feature_classes.rb +83 -0
  76. data/lib/rgeo/geos/ffi_feature_methods.rb +574 -0
  77. data/lib/rgeo/geos/interface.rb +202 -0
  78. data/lib/rgeo/geos/utils.rb +74 -0
  79. data/lib/rgeo/geos/zm_factory.rb +405 -0
  80. data/lib/rgeo/geos/zm_feature_classes.rb +80 -0
  81. data/lib/rgeo/geos/zm_feature_methods.rb +344 -0
  82. data/lib/rgeo/impl_helper.rb +19 -0
  83. data/lib/rgeo/impl_helper/basic_geometry_collection_methods.rb +185 -0
  84. data/lib/rgeo/impl_helper/basic_geometry_methods.rb +61 -0
  85. data/lib/rgeo/impl_helper/basic_line_string_methods.rb +146 -0
  86. data/lib/rgeo/impl_helper/basic_point_methods.rb +104 -0
  87. data/lib/rgeo/impl_helper/basic_polygon_methods.rb +87 -0
  88. data/lib/rgeo/impl_helper/math.rb +14 -0
  89. data/lib/rgeo/impl_helper/utils.rb +29 -0
  90. data/lib/rgeo/version.rb +3 -0
  91. data/lib/rgeo/wkrep.rb +37 -0
  92. data/lib/rgeo/wkrep/wkb_generator.rb +201 -0
  93. data/lib/rgeo/wkrep/wkb_parser.rb +251 -0
  94. data/lib/rgeo/wkrep/wkt_generator.rb +207 -0
  95. data/lib/rgeo/wkrep/wkt_parser.rb +415 -0
  96. data/lib/rgeo/yaml.rb +23 -0
  97. data/test/cartesian_analysis_test.rb +65 -0
  98. data/test/cartesian_bbox_test.rb +123 -0
  99. data/test/common/factory_tests.rb +78 -0
  100. data/test/common/geometry_collection_tests.rb +237 -0
  101. data/test/common/line_string_tests.rb +330 -0
  102. data/test/common/multi_line_string_tests.rb +182 -0
  103. data/test/common/multi_point_tests.rb +200 -0
  104. data/test/common/multi_polygon_tests.rb +191 -0
  105. data/test/common/point_tests.rb +370 -0
  106. data/test/common/polygon_tests.rb +261 -0
  107. data/test/coord_sys/ogc_cs_test.rb +342 -0
  108. data/test/coord_sys/proj4_srs_data_test.rb +41 -0
  109. data/test/coord_sys/proj4_test.rb +150 -0
  110. data/test/coord_sys/sr_org_test.rb +32 -0
  111. data/test/coord_sys/url_reader_test.rb +42 -0
  112. data/test/geos_capi/factory_test.rb +31 -0
  113. data/test/geos_capi/geometry_collection_test.rb +24 -0
  114. data/test/geos_capi/line_string_test.rb +24 -0
  115. data/test/geos_capi/misc_test.rb +116 -0
  116. data/test/geos_capi/multi_line_string_test.rb +24 -0
  117. data/test/geos_capi/multi_point_test.rb +24 -0
  118. data/test/geos_capi/multi_polygon_test.rb +39 -0
  119. data/test/geos_capi/parsing_unparsing_test.rb +40 -0
  120. data/test/geos_capi/point_test.rb +72 -0
  121. data/test/geos_capi/polygon_test.rb +154 -0
  122. data/test/geos_capi/zmfactory_test.rb +57 -0
  123. data/test/geos_ffi/factory_test.rb +31 -0
  124. data/test/geos_ffi/geometry_collection_test.rb +24 -0
  125. data/test/geos_ffi/line_string_test.rb +24 -0
  126. data/test/geos_ffi/misc_test.rb +63 -0
  127. data/test/geos_ffi/multi_line_string_test.rb +24 -0
  128. data/test/geos_ffi/multi_point_test.rb +24 -0
  129. data/test/geos_ffi/multi_polygon_test.rb +33 -0
  130. data/test/geos_ffi/parsing_unparsing_test.rb +41 -0
  131. data/test/geos_ffi/point_test.rb +77 -0
  132. data/test/geos_ffi/polygon_test.rb +46 -0
  133. data/test/geos_ffi/zmfactory_test.rb +58 -0
  134. data/test/mixins_test.rb +141 -0
  135. data/test/oneoff_test.rb +26 -0
  136. data/test/projected_geographic/factory_test.rb +25 -0
  137. data/test/projected_geographic/geometry_collection_test.rb +24 -0
  138. data/test/projected_geographic/line_string_test.rb +24 -0
  139. data/test/projected_geographic/multi_line_string_test.rb +26 -0
  140. data/test/projected_geographic/multi_point_test.rb +30 -0
  141. data/test/projected_geographic/multi_polygon_test.rb +25 -0
  142. data/test/projected_geographic/point_test.rb +51 -0
  143. data/test/projected_geographic/polygon_test.rb +24 -0
  144. data/test/simple_cartesian/calculations_test.rb +99 -0
  145. data/test/simple_cartesian/factory_test.rb +27 -0
  146. data/test/simple_cartesian/geometry_collection_test.rb +30 -0
  147. data/test/simple_cartesian/line_string_test.rb +31 -0
  148. data/test/simple_cartesian/multi_line_string_test.rb +28 -0
  149. data/test/simple_cartesian/multi_point_test.rb +31 -0
  150. data/test/simple_cartesian/multi_polygon_test.rb +31 -0
  151. data/test/simple_cartesian/point_test.rb +50 -0
  152. data/test/simple_cartesian/polygon_test.rb +28 -0
  153. data/test/simple_mercator/factory_test.rb +25 -0
  154. data/test/simple_mercator/geometry_collection_test.rb +24 -0
  155. data/test/simple_mercator/line_string_test.rb +24 -0
  156. data/test/simple_mercator/multi_line_string_test.rb +26 -0
  157. data/test/simple_mercator/multi_point_test.rb +29 -0
  158. data/test/simple_mercator/multi_polygon_test.rb +25 -0
  159. data/test/simple_mercator/point_test.rb +55 -0
  160. data/test/simple_mercator/polygon_test.rb +24 -0
  161. data/test/simple_mercator/window_test.rb +173 -0
  162. data/test/spherical_geographic/calculations_test.rb +167 -0
  163. data/test/spherical_geographic/factory_test.rb +27 -0
  164. data/test/spherical_geographic/geometry_collection_test.rb +31 -0
  165. data/test/spherical_geographic/line_string_test.rb +31 -0
  166. data/test/spherical_geographic/multi_line_string_test.rb +29 -0
  167. data/test/spherical_geographic/multi_point_test.rb +31 -0
  168. data/test/spherical_geographic/multi_polygon_test.rb +31 -0
  169. data/test/spherical_geographic/point_test.rb +78 -0
  170. data/test/spherical_geographic/polygon_test.rb +28 -0
  171. data/test/types_test.rb +42 -0
  172. data/test/wkrep/wkb_generator_test.rb +185 -0
  173. data/test/wkrep/wkb_parser_test.rb +293 -0
  174. data/test/wkrep/wkt_generator_test.rb +294 -0
  175. data/test/wkrep/wkt_parser_test.rb +412 -0
  176. metadata +386 -0
@@ -0,0 +1,40 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Geographic data for RGeo
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ module RGeo
8
+ # The Geographic implementation actually comprises a suite of
9
+ # implementations with one common feature: they represent geographic
10
+ # latitude/longitude coordinates measured in degrees. The "x"
11
+ # coordinate corresponds to longitude, and the "y" coordinate to
12
+ # latitude. Thus, coordinates are often expressed in reverse
13
+ # (i.e. long-lat) order. e.g.
14
+ #
15
+ # location = geographic_factory.point(long, lat)
16
+ #
17
+ # Some geographic implementations include a secondary factory that
18
+ # represents a projection. For these implementations, you can quickly
19
+ # transform data between lat/long coordinates and the projected
20
+ # coordinate system, and most calculations are done in the projected
21
+ # coordinate system. For implementations that do not include this
22
+ # secondary projection factory, calculations are done on the sphereoid.
23
+ # See the various class methods of Geographic for more information on
24
+ # the behaviors of the factories they generate.
25
+
26
+ module Geographic
27
+ end
28
+ end
29
+
30
+ # Implementation files.
31
+ require "rgeo/geographic/factory"
32
+ require "rgeo/geographic/projected_window"
33
+ require "rgeo/geographic/interface"
34
+ require "rgeo/geographic/spherical_math"
35
+ require "rgeo/geographic/spherical_feature_methods"
36
+ require "rgeo/geographic/spherical_feature_classes"
37
+ require "rgeo/geographic/proj4_projector"
38
+ require "rgeo/geographic/simple_mercator_projector"
39
+ require "rgeo/geographic/projected_feature_methods"
40
+ require "rgeo/geographic/projected_feature_classes"
@@ -0,0 +1,450 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Geographic data factory implementation
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+
7
+ module RGeo
8
+ module Geographic
9
+ # This class implements the various factories for geography features.
10
+ # See methods of the RGeo::Geographic module for the API for creating
11
+ # geography factories.
12
+
13
+ class Factory
14
+ include Feature::Factory::Instance
15
+
16
+ def initialize(impl_prefix_, opts_ = {}) # :nodoc:
17
+ @impl_prefix = impl_prefix_
18
+ @point_class = Geographic.const_get("#{impl_prefix_}PointImpl")
19
+ @line_string_class = Geographic.const_get("#{impl_prefix_}LineStringImpl")
20
+ @linear_ring_class = Geographic.const_get("#{impl_prefix_}LinearRingImpl")
21
+ @line_class = Geographic.const_get("#{impl_prefix_}LineImpl")
22
+ @polygon_class = Geographic.const_get("#{impl_prefix_}PolygonImpl")
23
+ @geometry_collection_class = Geographic.const_get("#{impl_prefix_}GeometryCollectionImpl")
24
+ @multi_point_class = Geographic.const_get("#{impl_prefix_}MultiPointImpl")
25
+ @multi_line_string_class = Geographic.const_get("#{impl_prefix_}MultiLineStringImpl")
26
+ @multi_polygon_class = Geographic.const_get("#{impl_prefix_}MultiPolygonImpl")
27
+ @support_z = opts_[:has_z_coordinate] ? true : false
28
+ @support_m = opts_[:has_m_coordinate] ? true : false
29
+ @srid = (opts_[:srid] || 4326).to_i
30
+ @proj4 = opts_[:proj4]
31
+ if CoordSys::Proj4.supported?
32
+ if @proj4.is_a?(::String) || @proj4.is_a?(::Hash)
33
+ @proj4 = CoordSys::Proj4.create(@proj4)
34
+ end
35
+ else
36
+ @proj4 = nil
37
+ end
38
+ @coord_sys = opts_[:coord_sys]
39
+ if @coord_sys.is_a?(::String)
40
+ @coord_sys = begin
41
+ CoordSys::CS.create_from_wkt(@coord_sys)
42
+ rescue
43
+ nil
44
+ end
45
+ end
46
+ @lenient_assertions = opts_[:uses_lenient_assertions] ? true : false
47
+ @buffer_resolution = opts_[:buffer_resolution].to_i
48
+ @buffer_resolution = 1 if @buffer_resolution < 1
49
+
50
+ wkt_generator_ = opts_[:wkt_generator]
51
+ case wkt_generator_
52
+ when ::Hash
53
+ @wkt_generator = WKRep::WKTGenerator.new(wkt_generator_)
54
+ else
55
+ @wkt_generator = WKRep::WKTGenerator.new(convert_case: :upper)
56
+ end
57
+ wkb_generator_ = opts_[:wkb_generator]
58
+ case wkb_generator_
59
+ when ::Hash
60
+ @wkb_generator = WKRep::WKBGenerator.new(wkb_generator_)
61
+ else
62
+ @wkb_generator = WKRep::WKBGenerator.new
63
+ end
64
+ wkt_parser_ = opts_[:wkt_parser]
65
+ case wkt_parser_
66
+ when ::Hash
67
+ @wkt_parser = WKRep::WKTParser.new(self, wkt_parser_)
68
+ else
69
+ @wkt_parser = WKRep::WKTParser.new(self)
70
+ end
71
+ wkb_parser_ = opts_[:wkb_parser]
72
+ case wkb_parser_
73
+ when ::Hash
74
+ @wkb_parser = WKRep::WKBParser.new(self, wkb_parser_)
75
+ else
76
+ @wkb_parser = WKRep::WKBParser.new(self)
77
+ end
78
+ @projector = nil
79
+ end
80
+
81
+ def _set_projector(projector_) # :nodoc:
82
+ @projector = projector_
83
+ end
84
+
85
+ # Equivalence test.
86
+
87
+ def eql?(rhs_)
88
+ rhs_.is_a?(Geographic::Factory) &&
89
+ @impl_prefix == rhs_.instance_variable_get(:@impl_prefix) &&
90
+ @support_z == rhs_.instance_variable_get(:@support_z) &&
91
+ @support_m == rhs_.instance_variable_get(:@support_m) &&
92
+ @proj4 == rhs_.instance_variable_get(:@proj4)
93
+ end
94
+ alias_method :==, :eql?
95
+
96
+ # Standard hash code
97
+
98
+ def hash
99
+ @hash ||= [@impl_prefix, @support_z, @support_m, @proj4].hash
100
+ end
101
+
102
+ # Marshal support
103
+
104
+ def marshal_dump # :nodoc:
105
+ hash_ = {
106
+ "pref" => @impl_prefix,
107
+ "hasz" => @support_z,
108
+ "hasm" => @support_m,
109
+ "srid" => @srid,
110
+ "wktg" => @wkt_generator._properties,
111
+ "wkbg" => @wkb_generator._properties,
112
+ "wktp" => @wkt_parser._properties,
113
+ "wkbp" => @wkb_parser._properties,
114
+ "lena" => @lenient_assertions,
115
+ "bufr" => @buffer_resolution
116
+ }
117
+ hash_["proj4"] = @proj4.marshal_dump if @proj4
118
+ hash_["cs"] = @coord_sys.to_wkt if @coord_sys
119
+ if @projector
120
+ hash_["prjc"] = @projector.class.name.sub(/.*::/, "")
121
+ hash_["prjf"] = @projector.projection_factory
122
+ end
123
+ hash_
124
+ end
125
+
126
+ def marshal_load(data_) # :nodoc:
127
+ if CoordSys::Proj4.supported? && (proj4_data_ = data_["proj4"])
128
+ proj4_ = CoordSys::Proj4.allocate
129
+ proj4_.marshal_load(proj4_data_)
130
+ else
131
+ proj4_ = nil
132
+ end
133
+ if (coord_sys_data_ = data_["cs"])
134
+ coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_)
135
+ else
136
+ coord_sys_ = nil
137
+ end
138
+ initialize(data_["pref"],
139
+ has_z_coordinate: data_["hasz"],
140
+ has_m_coordinate: data_["hasm"],
141
+ srid: data_["srid"],
142
+ wkt_generator: ImplHelper::Utils.symbolize_hash(data_["wktg"]),
143
+ wkb_generator: ImplHelper::Utils.symbolize_hash(data_["wkbg"]),
144
+ wkt_parser: ImplHelper::Utils.symbolize_hash(data_["wktp"]),
145
+ wkb_parser: ImplHelper::Utils.symbolize_hash(data_["wkbp"]),
146
+ uses_lenient_assertions: data_["lena"],
147
+ buffer_resolution: data_["bufr"],
148
+ proj4: proj4_,
149
+ coord_sys: coord_sys_
150
+ )
151
+ if (projklass_ = data_["prjc"]) && (projfactory_ = data_["prjf"])
152
+ klass_ = begin
153
+ ::RGeo::Geographic.const_get(projklass_)
154
+ rescue
155
+ nil
156
+ end
157
+ if klass_
158
+ projector_ = klass_.allocate
159
+ projector_._set_factories(self, projfactory_)
160
+ _set_projector(projector_)
161
+ end
162
+ end
163
+ end
164
+
165
+ # Psych support
166
+
167
+ def encode_with(coder_) # :nodoc:
168
+ coder_["impl_prefix"] = @impl_prefix
169
+ coder_["has_z_coordinate"] = @support_z
170
+ coder_["has_m_coordinate"] = @support_m
171
+ coder_["srid"] = @srid
172
+ coder_["wkt_generator"] = @wkt_generator._properties
173
+ coder_["wkb_generator"] = @wkb_generator._properties
174
+ coder_["wkt_parser"] = @wkt_parser._properties
175
+ coder_["wkb_parser"] = @wkb_parser._properties
176
+ coder_["lenient_assertions"] = @lenient_assertions
177
+ coder_["buffer_resolution"] = @buffer_resolution
178
+ if @proj4
179
+ str_ = @proj4.original_str || @proj4.canonical_str
180
+ coder_["proj4"] = @proj4.radians? ? { "proj4" => str_, "radians" => true } : str_
181
+ end
182
+ coder_["coord_sys"] = @coord_sys.to_wkt if @coord_sys
183
+ if @projector
184
+ coder_["projector_class"] = @projector.class.name.sub(/.*::/, "")
185
+ coder_["projection_factory"] = @projector.projection_factory
186
+ end
187
+ end
188
+
189
+ def init_with(coder_) # :nodoc:
190
+ if (proj4_data_ = coder_["proj4"])
191
+ if proj4_data_.is_a?(::Hash)
192
+ proj4_ = CoordSys::Proj4.create(proj4_data_["proj4"], radians: proj4_data_["radians"])
193
+ else
194
+ proj4_ = CoordSys::Proj4.create(proj4_data_.to_s)
195
+ end
196
+ else
197
+ proj4_ = nil
198
+ end
199
+ if (coord_sys_data_ = coder_["cs"])
200
+ coord_sys_ = CoordSys::CS.create_from_wkt(coord_sys_data_.to_s)
201
+ else
202
+ coord_sys_ = nil
203
+ end
204
+ initialize(coder_["impl_prefix"],
205
+ has_z_coordinate: coder_["has_z_coordinate"],
206
+ has_m_coordinate: coder_["has_m_coordinate"],
207
+ srid: coder_["srid"],
208
+ wkt_generator: ImplHelper::Utils.symbolize_hash(coder_["wkt_generator"]),
209
+ wkb_generator: ImplHelper::Utils.symbolize_hash(coder_["wkb_generator"]),
210
+ wkt_parser: ImplHelper::Utils.symbolize_hash(coder_["wkt_parser"]),
211
+ wkb_parser: ImplHelper::Utils.symbolize_hash(coder_["wkb_parser"]),
212
+ uses_lenient_assertions: coder_["lenient_assertions"],
213
+ buffer_resolution: coder_["buffer_resolution"],
214
+ proj4: proj4_,
215
+ coord_sys: coord_sys_
216
+ )
217
+ if (projklass_ = coder_["projector_class"]) && (projfactory_ = coder_["projection_factory"])
218
+ klass_ = begin
219
+ ::RGeo::Geographic.const_get(projklass_)
220
+ rescue
221
+ nil
222
+ end
223
+ if klass_
224
+ projector_ = klass_.allocate
225
+ projector_._set_factories(self, projfactory_)
226
+ _set_projector(projector_)
227
+ end
228
+ end
229
+ end
230
+
231
+ # Returns the srid reported by this factory.
232
+
233
+ attr_reader :srid
234
+
235
+ # Returns true if this factory supports a projection.
236
+
237
+ def has_projection?
238
+ !@projector.nil?
239
+ end
240
+
241
+ # Returns the factory for the projected coordinate space,
242
+ # or nil if this factory does not support a projection.
243
+
244
+ def projection_factory
245
+ @projector ? @projector.projection_factory : nil
246
+ end
247
+
248
+ # Projects the given geometry into the projected coordinate space,
249
+ # and returns the projected geometry.
250
+ # Returns nil if this factory does not support a projection.
251
+ # Raises Error::InvalidGeometry if the given geometry is not of
252
+ # this factory.
253
+
254
+ def project(geometry_)
255
+ return nil unless @projector && geometry_
256
+ unless geometry_.factory == self
257
+ raise Error::InvalidGeometry, "Wrong geometry type"
258
+ end
259
+ @projector.project(geometry_)
260
+ end
261
+
262
+ # Reverse-projects the given geometry from the projected coordinate
263
+ # space into lat-long space.
264
+ # Raises Error::InvalidGeometry if the given geometry is not of
265
+ # the projection defined by this factory.
266
+
267
+ def unproject(geometry_)
268
+ return nil unless geometry_
269
+ unless @projector && @projector.projection_factory == geometry_.factory
270
+ raise Error::InvalidGeometry, "You can unproject only features that are in the projected coordinate space."
271
+ end
272
+ @projector.unproject(geometry_)
273
+ end
274
+
275
+ # Returns true if this factory supports a projection and the
276
+ # projection wraps its x (easting) direction. For example, a
277
+ # Mercator projection wraps, but a local projection that is valid
278
+ # only for a small area does not wrap. Returns nil if this factory
279
+ # does not support or a projection, or if it is not known whether
280
+ # or not it wraps.
281
+
282
+ def projection_wraps?
283
+ @projector ? @projector.wraps? : nil
284
+ end
285
+
286
+ # Returns a ProjectedWindow specifying the limits of the domain of
287
+ # the projection space.
288
+ # Returns nil if this factory does not support a projection, or the
289
+ # projection limits are not known.
290
+
291
+ def projection_limits_window
292
+ if @projector
293
+ unless defined?(@projection_limits_window)
294
+ @projection_limits_window = @projector.limits_window
295
+ end
296
+ @projection_limits_window
297
+ end
298
+ end
299
+
300
+ # See ::RGeo::Feature::Factory#property
301
+
302
+ def property(name_)
303
+ case name_
304
+ when :has_z_coordinate
305
+ @support_z
306
+ when :has_m_coordinate
307
+ @support_m
308
+ when :uses_lenient_assertions
309
+ @lenient_assertions
310
+ when :buffer_resolution
311
+ @buffer_resolution
312
+ when :is_geographic
313
+ true
314
+ end
315
+ end
316
+
317
+ # See ::RGeo::Feature::Factory#parse_wkt
318
+
319
+ def parse_wkt(str_)
320
+ @wkt_parser.parse(str_)
321
+ end
322
+
323
+ # See ::RGeo::Feature::Factory#parse_wkb
324
+
325
+ def parse_wkb(str_)
326
+ @wkb_parser.parse(str_)
327
+ end
328
+
329
+ # See ::RGeo::Feature::Factory#point
330
+
331
+ def point(x_, y_, *extra_)
332
+ @point_class.new(self, x_, y_, *extra_)
333
+ rescue
334
+ nil
335
+ end
336
+
337
+ # See ::RGeo::Feature::Factory#line_string
338
+
339
+ def line_string(points_)
340
+ @line_string_class.new(self, points_)
341
+ rescue
342
+ nil
343
+ end
344
+
345
+ # See ::RGeo::Feature::Factory#line
346
+
347
+ def line(start_, end_)
348
+ @line_class.new(self, start_, end_)
349
+ rescue
350
+ nil
351
+ end
352
+
353
+ # See ::RGeo::Feature::Factory#linear_ring
354
+
355
+ def linear_ring(points_)
356
+ @linear_ring_class.new(self, points_)
357
+ rescue
358
+ nil
359
+ end
360
+
361
+ # See ::RGeo::Feature::Factory#polygon
362
+
363
+ def polygon(outer_ring_, inner_rings_ = nil)
364
+ @polygon_class.new(self, outer_ring_, inner_rings_)
365
+ rescue
366
+ nil
367
+ end
368
+
369
+ # See ::RGeo::Feature::Factory#collection
370
+
371
+ def collection(elems_)
372
+ @geometry_collection_class.new(self, elems_)
373
+ rescue
374
+ nil
375
+ end
376
+
377
+ # See ::RGeo::Feature::Factory#multi_point
378
+
379
+ def multi_point(elems_)
380
+ @multi_point_class.new(self, elems_)
381
+ rescue
382
+ nil
383
+ end
384
+
385
+ # See ::RGeo::Feature::Factory#multi_line_string
386
+
387
+ def multi_line_string(elems_)
388
+ @multi_line_string_class.new(self, elems_)
389
+ rescue
390
+ nil
391
+ end
392
+
393
+ # See ::RGeo::Feature::Factory#multi_polygon
394
+
395
+ def multi_polygon(elems_)
396
+ @multi_polygon_class.new(self, elems_)
397
+ rescue
398
+ nil
399
+ end
400
+
401
+ # See ::RGeo::Feature::Factory#proj4
402
+
403
+ attr_reader :proj4
404
+
405
+ # See ::RGeo::Feature::Factory#coord_sys
406
+
407
+ attr_reader :coord_sys
408
+
409
+ def _generate_wkt(obj_) # :nodoc:
410
+ @wkt_generator.generate(obj_)
411
+ end
412
+
413
+ def _generate_wkb(obj_) # :nodoc:
414
+ @wkb_generator.generate(obj_)
415
+ end
416
+
417
+ def _marshal_wkb_generator # :nodoc:
418
+ unless defined?(@marshal_wkb_generator)
419
+ @marshal_wkb_generator = ::RGeo::WKRep::WKBGenerator.new(
420
+ type_format: :wkb12)
421
+ end
422
+ @marshal_wkb_generator
423
+ end
424
+
425
+ def _marshal_wkb_parser # :nodoc:
426
+ unless defined?(@marshal_wkb_parser)
427
+ @marshal_wkb_parser = ::RGeo::WKRep::WKBParser.new(self,
428
+ support_wkb12: true)
429
+ end
430
+ @marshal_wkb_parser
431
+ end
432
+
433
+ def _psych_wkt_generator # :nodoc:
434
+ unless defined?(@psych_wkt_generator)
435
+ @psych_wkt_generator = ::RGeo::WKRep::WKTGenerator.new(
436
+ tag_format: :wkt12)
437
+ end
438
+ @psych_wkt_generator
439
+ end
440
+
441
+ def _psych_wkt_parser # :nodoc:
442
+ unless defined?(@psych_wkt_parser)
443
+ @psych_wkt_parser = ::RGeo::WKRep::WKTParser.new(self,
444
+ support_wkt12: true, support_ewkt: true)
445
+ end
446
+ @psych_wkt_parser
447
+ end
448
+ end
449
+ end
450
+ end